﻿var imgDrag = false;
var mouse = new Object();


     function degradeScroll() {
        if (Math.abs(mouse.SpeedX)  <= .5 && Math.abs(mouse.SpeedY) <= .5) 
            return;
            
        mouse.SpeedX = mouse.SpeedX * .9;
        mouse.SpeedY = mouse.SpeedY * .9;
        
           $('#zoomWindow div').scrollLeft($('#zoomWindow div').scrollLeft() + mouse.SpeedX);
           $('#zoomWindow div').scrollTop($('#zoomWindow div').scrollTop() + mouse.SpeedY);
        
        setTimeout("degradeScroll()", 30);
     }
     
     
function BindPreview() {
     
     $('#zoomWindow').dblclick(function() {
        var o = $('#zoomWindow');
        var img = o.find('img');
        o.css('background-image','url(/s/i/zoomshad-wide.png)').css('width','470px').css('height', '352px');
        
        o.find('div').css('width','470px').css('height', '352px');

        var altUrl = img.attr('alturl');
        //alert(altUrl);
        if (altUrl.length > 0) {
            var newObj = '';
            if (altUrl.toLowerCase().indexOf('youtube.com') > 0)
                newObj = ('<object width="440" height="320"><param name="movie" value="' + altUrl + '"></param><param name="wmode" value="transparent"></param><embed src="' + altUrl + '" type="application/x-shockwave-flash" wmode="transparent" width="440" height="320"></embed></object>');
            $('#zoomWindow #zoomBody').html(newObj);
        }
        else
            img.attr('src', img.attr('src').toLowerCase().replace('size=m', 'size=hl').replace('size=l', 'size=hl'));
            
        return false;
     });
     
     
     $('#zoomWindow').click(function() {
        return false;
     });
     
     $('#zoomWindow').mousedown(function(e) {
        imgDrag = true;
        mouse.X = e.clientX;
        mouse.Y = e.clientY;
        mouse.SpeedX = 0;
        mouse.SpeedY = 0;
        
        return false;     
        
     });
     $('#zoomWindow').mouseup(function() {
        imgDrag = false;
        
        mouse.SpeedX *= 2;
        mouse.SpeedY *= 2;
        degradeScroll();
        
        return false;
     });
     
     $('#zoomWindow').mousemove(function(e) {
        if (imgDrag) {
            var diffX = mouse.X - e.clientX;
            var diffY = mouse.Y - e.clientY;
           // $(this).parent().scroll(4,4);
           
           $('#zoomWindow div').scrollLeft($('#zoomWindow div').scrollLeft() + diffX);
           $('#zoomWindow div').scrollTop($('#zoomWindow div ').scrollTop() + diffY);
            //alert('scrollBy');
            mouse.SpeedX = (mouse.SpeedX+diffX)/2;
            mouse.SpeedY = (mouse.SpeedY+diffY)/2;
            
            mouse.X = e.clientX;
            mouse.Y = e.clientY; 
        }
        return false;
     });     
     
     	    
	    var hoverIntentConfig = {    
             sensitivity: 3, // number = sensitivity threshold (must be 1 or higher)    
             interval: 400, // number = milliseconds for onMouseOver polling interval    
             over: hoverIn, // function = onMouseOver callback (REQUIRED)    
             timeout: 1000, // number = milliseconds delay before onMouseOut    
             out: hoverOut // function = onMouseOut callback (REQUIRED)    
        };
                     	    
    //$('img.thumbZoom').hoverIntent(hoverIntentConfig);//
    
    function hoverIn() {
        imgDrag = false;
        //$(this).attr('src', $(this).attr('src').replace('size=S', 'size=H'))
        var o = $('#zoomWindow');
        
        o.find('#zoomBody').html('<img src="/s/i/b.gif" />');
        o.css('width','220px').css('height', '180px').find('div').css('width','220px').css('height', '180px');
        o.css('background-image','url(/s/i/zoomshad.png)');
        
        var zo = $(this);
        var img = o.find('img');
       // img.attr('src', '/s/i/logotmp.gif');
        //o.css('position','absolute').show();
        //alert(zo.offset().top);
        
        var st = (zo.offset().top.toString().replace('px', '') - 35) + 'px';
        var sl = (zo.offset().left.toString().replace('px', '') - 30) + 'px';
        o.fadeIn('slow').css('position','absolute').css('left', sl).css('top', st);
        img.attr('src', $(this).attr('src').toLowerCase().replace('size=s', 'size=l').replace('size=m', 'size=l'));
        img.attr('alturl', $(this).attr('alturl'));
        //$.scrollTo('#zoomWindow', 0);//zo.scrollTo(0,0);
        
        $('body').click(function() {
            $(this).unbind('hover');
            $(this).unbind('click');
            $('#zoomWindow').fadeOut('slow', function() {
            $(this).css('background-image','url(/s/i/zoomshad.png)').css('width','220px').find('div').css('width','220px');
            });
            return false;
        });

        return false;
    }
    function hoverOut() {
        imgDrag = false;
        // $('#zoomWindow').hide();
        //$(this).attr('src', $(this).attr('src').replace('size=H', 'size=S'))
    }
    
   
    $('#zoomWindow ').hover(function() {}, function() {
        imgDrag = false;  
        degradeScroll();      
    });
}     
     
$(document).ready(function() {
BindPreview();
    
    
});

