// JavaScript Document
jQuery.noConflict();

jQuery(document).ready(function() {
	var nb_li = jQuery('#produits-selection > #wrapper > ul > li').size();
	var width_li = jQuery('#produits-selection > #wrapper > ul > li:first').outerWidth(true);
	var nb_visible = Math.floor(jQuery('#produits-selection').outerWidth(true) / width_li);
	var width_ul = width_li * nb_li;
	jQuery('#produits-selection #wrapper > ul').css('width', width_ul+'px');
	var max_scroll = jQuery('#produits-selection > #wrapper')[0].scrollWidth - (Math.ceil(jQuery('#produits-selection').outerWidth(true)));
	
	var go_to_next = function() {
		var left = parseInt(jQuery('#produits-selection > #wrapper')[0].scrollLeft)+(nb_visible*width_li);
		
		if (left > 0) { jQuery('#arrow-left').fadeIn(800); } else { jQuery('#arrow-left').fadeOut(800); };
		if (left > max_scroll) { jQuery('#arrow-right').fadeOut(800); } else { jQuery('#arrow-right').fadeIn(800); };

		jQuery('#produits-selection #wrapper').animate({
			scrollLeft: left
		}, 800);
	}

	var go_to_previous = function() {
		var left = parseInt(jQuery('#produits-selection > #wrapper')[0].scrollLeft)-(nb_visible*width_li);
		left = (left < 0) ? 0 : left;
		
		if (left == 0) { jQuery('#arrow-left').fadeOut(800); } else { jQuery('#arrow-left').fadeIn(800); };
		if (left <= max_scroll) { jQuery('#arrow-right').fadeIn(800); } else { jQuery('#arrow-right').fadeOut(800); };
		
		jQuery('#produits-selection #wrapper').animate({
			scrollLeft: left
		}, 800);
	}

	jQuery('#arrow-left').click(function() {
		go_to_previous();
		return false;									  
	});

	jQuery('#arrow-right').click(function() {
		go_to_next();
		return false;									  
	});

	jQuery('#arrow-left').fadeOut(800);
	if (max_scroll <= 0) { jQuery('#arrow-right').fadeOut(800); }
});

