function ClientBrowse() { this.w=0; this.h=0;
if (self.screen) { this.w=screen.width; this.h=screen.height; }
else if (self.java) { var jkit=java.awt.Toolkit.getDefaultToolkit(); var scrsize=jkit.getScreenSize(); this.w=scrsize.width; this.h=scrsize.height; } return this; }
function OpenWin(url,nwin,w,h,s) { p=new ClientBrowse();
if (w) { leftPos=(p.w-w)/2; } else { w=p.w-100; leftPos=(p.w-w)/2; }
if (h) { topPos=(p.h-h)/2; } else { h=p.h-100; topPos=10; }
(s==1)?null:s=0; (nwin)?null:nwin="win"; var property="left="+leftPos+",top="+topPos+",width="+w+",height="+h+",scrollbars="+s;
window.open (url,nwin,property); }



$(document).ready(function(){

   var _timer;
   $("a.preview").click( function() { return false; } ).hover(
      
      function(e) {
         var _img = $( this ).find( 'img:first');
         var _base_w = Math.floor( _img.width() );
         var _base_h = Math.floor( _img.height() );
         var _base_l = Math.floor( _img.position().left );
         var _base_t = Math.floor( _img.position().top );     
         
         clearTimeout( _timer )
         $("#preview").remove();
         $("#loading").remove();
         
         $( this ).append("<img src='/i/loader.gif' id='loading'>" );
         $("#loading").bind('load', function() {
            $( this )
               .css("top", Math.floor( _base_t + ( _base_h - $( this ).height() ) / 2 ) + "px")
               .css("left", Math.floor(_base_l + ( _base_w - $( this ).width() ) / 2 ) + "px")
               .show();
         } );
         
         $( this ).append("<img id='preview' src='" + this.href + "' alt='загрузка...'>");

         $("#preview").bind('load', function() {
            
            var img_w = Math.floor( $( this ).width() * 0.9 );
            var img_h = Math.floor( $( this ).height() * 0.9 );

            $( this )
               .width( _base_w + 'px' )
               .height( _base_h + 'px' )
               .css("top",  _base_t + 'px' )
               .css("left", _base_l + 'px' )           
               .show( 0, 0, function() { setTimeout( function() { $("#loading").remove(); }, 200 ); } )
               .animate( {
                  
                   width: img_w + 'px',
                   height: img_h + 'px',
                   top:  '+=' + Math.floor( ( _base_h - img_h ) / 2  ) + 'px',
                   left: '+=' + Math.floor( ( _base_w - img_w ) / 2  ) + 'px'
                
                  }, 500
               );
               
            //document.title = img_w + ',' + img_h + ',' + _base_h + ',' + _base_w;
            
         } );
         
      }, // End function
      
      function(){
         _timer = setTimeout( function() {$("#preview").remove();$("#loading").remove() }, 50 );
      } // End function
   );	


   
   
});
