(function($){
    
Drupal.rotator = Drupal.rotator || {}
    
Drupal.behaviors.rotator = {
    attach : function(context){
        Drupal.rotator.slides = $('.gallery .slide').length;
        Drupal.rotator.index = 1;
        Drupal.rotator.slide;
        Drupal.rotator.slideTimerID = 0;
        
        Drupal.rotator.fadeSlides();
    }
}

Drupal.rotator.fadeSlides = function(){
    if(Drupal.rotator.slide){
        Drupal.rotator.slide.fadeOut();
    }
    Drupal.rotator.slide = $('#slide'+Drupal.rotator.index);
    Drupal.rotator.slide.fadeIn();
    Drupal.rotator.index++;
    if(Drupal.rotator.index>Drupal.rotator.slides) Drupal.rotator.index = 1;
    if(Drupal.rotator.slides > 1) Drupal.rotator.slideTimerID = setTimeout(Drupal.rotator.fadeSlides, 5000);
}

})(jQuery);;
(function($){
    
Drupal.zoomer = Drupal.zoomer || {}

Drupal.behaviors.zoomer = {
    attach : function(context){
        
        $('#product .image .sens').width($('#product .image .thumbnail').width());
        $('#product .image .sens').height($('#product .image .thumbnail').height());
        
        $('#product .image .thumbnail').load(function(){
            $('#product .image .sens').width($('#product .image .thumbnail').width());
            $('#product .image .sens').height($('#product .image .thumbnail').height());
        });
        
        $('#product .image .sens', context).mousemove(function(event){
            var zoom = $('#product .zoom');
            var full = $('#product .zoom .full');
            var image = $('#product .image img.thumbnail');
            
            var left = event.pageX-$(this).offset().left;
            var top = event.pageY-$(this).offset().top;

            var w = full.width()/$(this).width();
            var h = full.height()/$(this).height();
            
            
            var x = -w*left+zoom.width()/2;
            if(x > 0) x = 0;
            if(x < -full.width()+zoom.width()) x = -full.width()+zoom.width();
            
            var y = -h*top+zoom.height()/2;
            if(y > 0) y = 0;
            if(y < -full.height()+zoom.height()) y = -full.height()+zoom.height();
            
            full.css('left', x);
            full.css('top', y);
            
            $('#product .magnifier').css({'left': left-15, 'top': top-15});
        });
        
        $('#product .image .sens', context).mouseenter(function(event){
            $('#product .image').css('cursor', 'none');
        });
        
        $('#product .image .sens', context).mouseleave(function(){
            $('#product .image').css('cursor', 'default');
            var left = $('#product .sens').width()-$('#product .magnifier').width()-5;
            var top = $('#product .sens').height()-$('#product .magnifier').height()-5;
            $('#product .magnifier').animate({'left': left, 'top': top}, 200);
        });
        
    }
}

})(jQuery);

