var sliderProduits = (function()
{
	return{
		slider:		{
						id:			"slider",
						idMask:		"slider_mask",
						widthMask:	0
					},
		fleche:		{
						gch:		"fleche_gch",
						drt:		"fleche_drt",
						o_class:	"fleche"
					},
		prod:		{
						o_class:		"produit",
						current:		"current",
						prefix:		"prod_",
						enlarge:	false,
						infos:		{
										bool:	false,
										o_class:	"infos"
									},
						curInit:	2,
						width:		325,
						length:		0,
						lenMax:		3,
						type:		"produits"
					},
		x:			0,
		bandeau_drt:{
						id:			"bandeau_drt",
						infos:		"span"
					},
		init:		function()
					{
						searchLength();
						fleche();
					}
	}
	
	function searchLength()
	{
		var o = sliderProduits;
		o.prod.length = $("#"+o.slider.idMask).find("."+o.prod.o_class).length;
		o.slider.widthMask = Math.round(o.prod.width*o.prod.length);
		$("#"+o.slider.idMask).css("width" ,o.slider.widthMask+"px");
	}
	function fleche()
	{
		var o = sliderProduits;
		current($("#"+o.prod.prefix+o.prod.curInit));
		if(o.prod.length > o.prod.lenMax)
		{
			$("#"+ o.fleche.drt).click(function(e)
			{
				e.preventDefault();
				/*if(o.prod.type == "ambassadeurs")
				{
					var limit = -(o.prod.width*(o.prod.length-(o.prod.lenMax)));
				}
				else
				{
					var limit = -(o.prod.width*(o.prod.length-(o.prod.lenMax-1)));
				}*/
				var limit = -(o.prod.width*(o.prod.length-(o.prod.lenMax+1)));
				if( o.x > limit )
				{
					o.x = o.x-o.prod.width;
					$("#"+o.slider.id).find("#"+o.slider.idMask).stop();
					$("#"+o.slider.id).find("#"+o.slider.idMask).animate({left: o.x});
					o.prod.curInit++;
					$("."+o.prod.o_class).removeClass(o.prod.current);
					current($("#"+o.prod.prefix+o.prod.curInit));
				}
			});
			$("#"+ o.fleche.gch).click(function(e)
			{
				e.preventDefault();
				var limit = -100;
				if( o.x < limit )
				{
					o.x = o.x+o.prod.width;
					$("#"+o.slider.id).find("#"+o.slider.idMask).stop();
					$("#"+o.slider.id).find("#"+o.slider.idMask).animate({left: o.x});
					o.prod.curInit--;
					$("."+o.prod.o_class).removeClass(o.prod.current);
					current($("#"+o.prod.prefix+o.prod.curInit));
				}
			});
		}
		else
		{
			$("#"+o.slider.id).find("."+o.fleche.o_class).css("display", "none");
		}
	}
	function current(pEl)
	{
		var o = sliderProduits;
		pEl.addClass(o.prod.current);
		if(o.prod.infos.bool != false)
		{
			var html = $(pEl).find("."+o.prod.infos.o_class).html();
			$("#"+o.bandeau_drt.id).find(o.bandeau_drt.infos).html(html);
		}
		
	}
})();

