var pc_serialScrollNbImagesDisplayed;
var pc_serialScrollNbImages;

function pc_serialScrollFixLock(event, targeted, scrolled, items, position){
	var id = items.parent().parent().attr('id').replace('productscategory_list', '');
	pc_serialScrollNbImages = items.length;
	
	$('.nav_prec'+id).css('cursor', position == 0 ? 'default' : 'pointer').fadeTo(500, position == 0 ? 0.2 : 1);
	$('.nav_suiv'+id)
		.css('cursor', position + pc_serialScrollNbImagesDisplayed >= pc_serialScrollNbImages ? 'default' : 'pointer')
		.fadeTo(500, position + pc_serialScrollNbImagesDisplayed >= pc_serialScrollNbImages ? 0.2 : 1);
	
	if(position + pc_serialScrollNbImagesDisplayed >= pc_serialScrollNbImages + 1)
	{
		$('.crossSelling #productscategory_list'+id).trigger( 'goto', 0 );
		return false;
	}
	else
	{
		return true;
	}
}

$(document).ready(function(){
	//init the serialScroll for thumbs
	pc_serialScrollNbImagesDisplayed = 3;
	
	$('.crossSelling .slideshow').each(function(){
		var id = $(this).attr('id').replace('productscategory_list', '');
		
		$('.nav_prec'+id).css('cursor', 'pointer').fadeTo(500, 0.2);
		
		$(this).serialScroll({
			items: 'li',
			prev: 'a.nav_prec'+id,
			next: 'a.nav_suiv'+id,
			axis: 'x',
			stop: true,
			onBefore: pc_serialScrollFixLock,
			duration: 500,
			step: 1,
			lock: false,
			force: true,
			cycle: false,
			interval: 4000,
			constant: false
		});
	});
	$('.crossSelling .slideshow').trigger( 'goto', 0 );
});

