

function animate(sens){
	_loopAnimateSens = sens;
	switchLoopAnimate(0);
	if(_gardefou == 1) return;
	_gardefou = 1;
	setTimeout(function(){_gardefou = 0;},500);
	setTimeout(function(){switchLoopAnimate(1);},500);
	prod = $('#products ul li');
	nprod = $('#products ul li').length;
	boucle = 0;

	if(cur < 0){
		cur = (nprod) + cur;
	}

	if(lastSens === -1){
		lastSens = sens;
	}
	if(sens == 0){

		if(lastSens != sens){
			ncur = cur - total;
			if(ncur < 0){
				cur = ncur + nprod;
			}else{
				cur = ncur;
			}
		}
		tcur = cur;
		while(boucle <= total){
			if(cur >= nprod) cur = 0;
			n = boucle;
			k = makeK(cur-1);
			if($(prod[k]).css('display') === "none"){
				$(prod[k]).css('marginLeft',hid[1]);
				$(prod[k]).css('marginTop',hid[0]);
			}
			if(boucle < total){
				$(prod[k]).animate({
					marginLeft: m[n][1] + "px",
					marginTop: m[n][0] + "px"
				});
				if($(prod[k]).css('display') === "none"){
					$(prod[k]).fadeIn();
				}
			}else{
				$(prod[makeK(k)]).fadeOut();
			}
			boucle++;
			cur++;
		}
		cur = tcur - 1;
		sensD = 1;
	}else{
		boucle = total;
		if(sensD === 0)
			cur = total;
		if(cur > nprod) cur = 1;

		if(lastSens != sens){
			ncur = cur + total;
			if(ncur > (nprod - 1)){
				cur = ncur - nprod;
			}else{
				cur = ncur;
			}
		}
		tcur = cur;
		while(boucle >= 0){

			if(cur < 0)
				k = (nprod-2) - (cur);
			else
				k = makeK(cur);
			n = makeK(boucle - 1);

			if(k >= nprod){
				c = (nprod-1) - k;
				k = (nprod-1) + c;
			}

			if($(prod[k]).css('display') === "none"){
				$(prod[k]).css('marginLeft',hid2[1]);
				$(prod[k]).css('marginTop',hid2[0]);
			}
			if(boucle > 0){
				$(prod[k]).animate({
					marginLeft: m[n][1] + "px",
					marginTop: m[n][0] + "px"
				});
			if ($(prod[k]).css('display') === "none") {
				$(prod[k]).fadeIn(100);
			}
			}else{
				$(prod[makeK(k)]).fadeOut();
			}
			boucle--;
			cur--;
		}
		cur = tcur + 1;
		sensD = 1;
	}
	lastSens = sens;
}

function makeK(k){
	if(k < 0){
		return nprod - 1;
	}else{
		if(k >= nprod)
			return 0;
		else
			return k;
	}
	return k;
}



function switchLoopAnimate(sw){
	_loopAnimate = sw;
}

function autoAnimate(){
	if(_loopAnimate == 1){
		animate(_loopAnimateSens);
		_timeout = setTimeout('autoAnimate()',2000);
	}else{
		_timeout = setTimeout('autoAnimate()',2500);
	}
}

