function ShowCenter(Elt)
    {
        Elt=$(Elt);
        Elt.css('top','5000px');
        Elt.show();
        //return;
        var w=Elt.outerWidth();
        var h=Elt.outerHeight();
        
        Elt.hide();
        //alert($(document).scrollTop());
        var l=$(document).scrollLeft()-w/2+$(window).width()/2;
        var t=$(document).scrollTop()-h/2+$(window).height()/2;
        
        //alert(w+' '+h+' '+$(window).width()+' '+$(window).height());
        Elt.css('top',t.toString()+'px');
        Elt.css('left',l.toString()+'px');
        //Elt.show('normal');
        Elt.slideDown('normal');
    }
    function CPopupController(Args)
    {
        var me=this;
        var frameClass=Args.frameClass==undefined?'popup_window':Args.frameClass;
        var popupUrl=Args.popupUrl==undefined?'popup_video.html':Args.popupUrl;
        var closeButtonClass=Args.closeButtonClass==undefined?'close':Args.closeButtonClass;
        var loadingHtml=Args.loadingHtml==undefined?'Загрузка ... ':Args.loadingHtml;
        var frame;
        var load;
        var Link='';
        CPopupController.prototype.Load=function(Params)
        {
            
            Link=popupUrl+'?';
            if(Params!=undefined)
                for(var i in Params) Link+=i+'='+Params[i]+'&';
            
            //alert(encodeURI(Link));
            
            $(frame).hide('normal',me.LoadStart);
            
        }
        CPopupController.prototype.LoadStart=function()
        {
            ShowCenter(load);
            //alert('load start');
            $.ajax({type: "get",dataType:'html',url: encodeURI(Link),complete:me.ShowStart,scriptCharset:'utf-8'});
            //$(frame).load(encodeURI(Link),me.ShowStart);
        }
        CPopupController.prototype.ShowStart=function(html,state)
        {
            
            
            //for(var i in html) alert(i);
            //alert(state);
            //alert(html.responseText+' XXX');
            //alert(state);
            
            if(state != 'parsererror')
            {
                $(frame).css('top','5000px');
                $(frame).html(html.responseText);
                
            }
            $(me).oneTime(1000,me.Show);
            
            //alert('end');
        }
        CPopupController.prototype.Show=function()
        {
            //alert('Show');
            $(load).hide('normal');
            ShowCenter(frame);
            $(frame).find('.'+closeButtonClass).click(me.Close);
        }
        CPopupController.prototype.Close=function()
        {
            $(frame).hide('normal',function(){this.innerHTML='';});
        }
        CPopupController.prototype.Init=function()
        {
            frame=document.createElement('DIV');
            frame.style.position='absolute';
            frame.style.display='none';
            frame.className=frameClass;
            document.body.appendChild(frame);            
            
            load=document.createElement('DIV');
            load.style.position='absolute';
            load.style.display='none';
            load.className=frameClass+'_load';
            load.innerHTML=loadingHtml;
            document.body.appendChild(load);            
        }
        me.Init();
    }

    var pcShow;
    function ImageOver()
    {
        if(this.is_over==true) return;
        this.is_over=true;
        var img=$(this);
        var mag=1.5;
        var pos=img.position();
        var w=img.width();
        var h=img.height();
        var div=$(document.createElement('DIV'));
        
        div.css('width',(w).toString()+'px'); 
        div.css('height',(h).toString()+'px');       
        //alert(w+' '+h);
        img.attr('oldWidth',w);        
        img.attr('oldHeight',h);        
        
        
        img.css('width',(w*mag).toString()+'px');        
        img.css('height',(h*mag).toString()+'px');
        img.css('top',(pos.top-(h*mag-h)/2).toString()+'px');
        img.css('left',(pos.left-(w*mag-w)/2).toString()+'px');
        //img.css('top',(-(h*mag-h)/2).toString()+'px');
        //img.css('left',(-(w*mag-w)/2).toString()+'px');
        img.after(div);
        img.css('position','absolute');
        //img.css('position','relative')
        this.onresize();
        
    }
    function ImageOut()
    {
        if(this.is_over==false) return;
        this.is_over=false;
        var img=$(this);
        //var mag=2;
        //alert(img.attr('oldWidth')+' '+img.attr('oldHeight'));        
        var div=img.next();
        
        //img.css('width',(div.width()).toString()+'px');        
        //img.css('height',(div.height()).toString()+'px');
        img.css('width',(img.attr('oldWidth')).toString()+'px');        
        img.css('height',(img.attr('oldHeight')).toString()+'px');
        
        img.css('position','static');
        div.remove();
        this.onresize();
    }
          
    function ShowVideo(Img)
    {
        pcShow.Load({video:$(Img).attr('video')});
    }
