
/* #product-scroll 

 

#scrolling-content

.row

#product-scroll-nav .left-button 
#product-scroll-nav .right-button

*/

function productScrollNext($element) {
    var curPos = $element.data('currentposition');
    var $rows = $element.find('.carousel-rows');
    var scrollitems = $element.find('.carousel-row').length;
    var contWidth = ($rows.width() / scrollitems);
    
    if (curPos <= 0) curPos = 1;
    
    if (curPos < scrollitems) {	
        $element.find('.prev').removeClass('disabled');	
        var scrollWidth = (curPos * contWidth);
        
        $rows.animate({ 
            'margin-left' : '-'+scrollWidth 
        }, 500);
	
        curPos++;
        
        if (curPos == scrollitems){
            $element.find('.next').addClass('disabled');
        }
        
        $element.data('currentposition', curPos);
    } 
}

function productScrollPrev($element) {
    var curPos = $element.data('currentposition');
    var $rows = $element.find('.carousel-rows');
    var scrollitems = $element.find('.carousel-row').length;
    var contWidth = ($rows.width() / scrollitems);
    
    if (curPos > 0) {
        $element.find('.next').removeClass('disabled');
        
        curPos--;
        var scrollWidth = (curPos * contWidth) - contWidth;

        $rows.animate({
            'margin-left' : '-'+scrollWidth
        }, 500);
        
        if (curPos == 1) {
            $element.find('.prev').addClass('disabled');
        }	
        
        $element.data('currentposition', curPos);
    }
}

function productAutoScroll($element) {
    if ($element.find('.next').hasClass('disabled')) {
        // move back
        $element.data('currentposition', 2);
        productScrollPrev($element);
    }
    else {
        productScrollNext($element);
    }
}

function productAutoScrollTimer($element) {
    var timer = window.setInterval(function() {
        productAutoScroll($element);
    }, 10000);
    $element.data('timer', timer); 
}

function productScroll($element, contWidth, delay) {	
    
    $element.data('currentposition', 1);
    var scrollitems = $element.find('.carousel-row').length;
    var scrollWidth = scrollitems * contWidth;
    $element.find('.carousel-rows').css('width', scrollWidth);
    
    window.setTimeout(function() {
        productAutoScrollTimer($element);
    }, delay);

    $element.find('.next').click(function(){	
        var carousel = $(this).closest('.carousel');
        productScrollNext(carousel);
        
        var timer = carousel.data('timer');
        window.clearInterval(timer);
    });
	
    $element.find('.prev').click(function(){	
        var carousel = $(this).closest('.carousel');
        productScrollPrev(carousel);
        
        var timer = carousel.data('timer');
        window.clearInterval(timer);
    });
        
    $element.find('.prev').addClass('disabled');
}
	
function productScrollMini() {	
	contWidth = 300 + 20;
	scrollWidth = contWidth;
	curPos = 0;	
	scrollitems = $('#carousel-just-in').find('.carousel-row').length;	
	scrollWidth = scrollitems * contWidth;
	
	$('#carousel-just-in').find('.carousel-rows').css('width', scrollWidth);

	$('#carousel-just-in').find('.next').click(function(){		
		if (curPos == 0 ) {curPos = 1;}
		if (curPos < scrollitems) {	
			$('#carousel-just-in').find('.prev').removeClass('disabled');	
			scrollWidth = (curPos * contWidth);
			$('#carousel-just-in').find('.carousel-rows').animate({ 
				'top' : '-'+scrollWidth 
			}, 500);			
			curPos++;
			if (curPos == scrollitems){
				$('#carousel-just-in').find('.next').addClass('disabled');
			}
		} 
	});
	
	$('#carousel-just-in').find('.prev').click(function(){						 
			curPos--;
		if (curPos > 0) {
			$('#carousel-just-in').find('.next').removeClass('disabled');
			scrollWidth = (scrollWidth - contWidth);
			$('#carousel-just-in').find('.carousel-rows').animate({
				'top' : '-'+scrollWidth
			}, 500);			
			if (curPos == 1) {
				$('#carousel-just-in').find('.prev').addClass('disabled');
			}	
		} 		
	});

	/* OVERLAY */
	
	if((navigator.userAgent.match(/iPhone/i)) || (navigator.userAgent.match(/iPod/i)) || (navigator.userAgent.match(/iPad/i))) {
	} else {
		
		$(".item .photo").mouseenter(function(){									
			if ($(this).parent().find('.item-overlay').length > 0) {													
				overlayHTML = $(this).parent().find('.item-overlay').html();
				
				lastClass = '';
				
				if ($(this).parent().find('.item-overlay').hasClass('last')) {
					lastClass = 'last';
				}
				
				
				$('body div:last').after('<div class="item-overlay-global '+lastClass+'">'+overlayHTML+'</div>');
				$('.item-overlay-global').fadeIn('fast');
				
				$(".item .photo").mousemove(function(e){
					
					px = e.pageX;
					py = e.pageY;
					
					if (lastClass == 'last') {
						px = px -450;
					}											   
															   
					$('.item-overlay-global').css({
						'left' : px+'px',
						'top' : py+'px'
					});											   
				});
			};
		}).delay(500);	
		
		$(".item .photo").mouseleave(function(){	
										
			$(".item-overlay-global").hide().remove();
		});	
	
	}

}




