var base_marge = 0;
var plus = 0;
var width = 0;
var stop = 1;
var sens = "hor";
var time = 50;
var hs = 0;

function strlen(strVar)
{
	return(strVar.length)
}

$(function(){
	
	
	
	i = 0;		
	$("#photosProduits li").each(function(){
		we = parseInt($(this).width());
		if(we <= 0){
			we = 138;
		}
		width = width + we;
		i++;
	});


	$("#scrollContainer").css({
		width: "420px"
	});
	
	width = (parseInt(width) - 420) + 10;
		
	if(width < 0)
	{
		return;
	}

	if(width < 50)
		time = 200;

	$("#photosProduits").css({
		overflow: "hidden",
		whiteSpace: "nowrap",
		width: "auto"
	});

	/*$("#photosProduits a").mouseover(function(){
		stop = 1
	});

	$("#photosProduits a").mouseout(function(){
		stop = 0
	});*/


	initScroll("hor");
		
	$("#flecheg").html("<a id='clickg' href='javascript:void(0)'><img src='/images/fleche_g.jpg' alt='' /></a>");
	$("#fleched").html("<a id='clickd' href='javascript:void(0)'><img src='/images/fleche_d.jpg' alt='' /></a>");

	$("#clickg").mouseover(function(){
		plus = 1;
		stop = 0;
		hs = 1;
		scrollProduits();
	}).mouseout(function(){
		stop = 1;
	});
	
	$("#clickd").mouseover(function(){
		plus = 1;
		stop = 0;
		hs = 2;
		scrollProduits();
	}).mouseout(function(){
		stop = 1;
	});	
			

});

function initScroll(ty)
{
	sens = ty;
	stop = 1;
}


function scrollProduits()
{
	
	if(sens == "hor") {
		marge = "-"+ base_marge + "px";
		//alert(marge);
		$("#photosProduits").css("margin-left",marge);
	}else{
		$("#photosProduits").css("margin-top","-"+ base_marge + "px");
	}
	
	
	if ((base_marge >= 0) && stop == 0 && hs == 1) {
		base_marge = base_marge - 5;
		plus = 1;
	}
	
	
	if ((base_marge <= width) && stop == 0 && hs == 2) {
		base_marge = base_marge + 5;
		plus = 0;
	}
	//$("#infobox").html(base_marge+"<br />"+width+"<br />"+stop+"<br />"+hs);
		
	if (stop == 0) {
		setTimeout("scrollProduits()", time);
	}
		
}

