﻿
var minRange = -1;
var maxRange = -1;
var	current = 0;
var count = 0 ;
var	direction = "backward";
//
var begin = 1;
//mode = 1 : défilement sans empilement
//mode = 2 : effet d'empilement (le deuxieme se superpose au premier, etc)
var mode = 1 ; 

function galleryAnimate2(){
	//alert($('#flash-items li').length*parseInt($('#flash-items li#item_1').css('width').replace(/[^-\d\.]/g, '')));
	//var myLength=$('#flash-items li').length*parseInt($('#flash-items li#item_1').css('width').replace(/[^-\d\.]/g, ''));
	//$('#flash-infos').css(myLength+'px');
	//var myWidth=parseInt($('#flash-items li#item_1').css('width').replace(/[^-\d\.]/g, ''))+parseInt($('#flash-items li#item_1').css('margin-left').replace(/[^-\d\.]/g, ''))+parseInt($('#flash-items li#item_1').css('margin-right').replace(/[^-\d\.]/g, ''));
	$('#flash-items').css('left',400+'px');
	window.setTimeout('galleryAnimateTest();',5000);
}

function galleryAnimate(){

	var size=$('#flash-items li').length;

	if(direction  == "forward"){
		current = parseInt($('#flash-items li').css('width').replace(/[^-\d\.]/g, ''));
		if (mode==2)begin--;
		window.setTimeout(function(){
		for (var i = begin ; i <= size ; i ++){
			$('#flash-items li#item_'+i).css('left',current+'px');//css('left',current+'px');
			$('#flash-items li#item_'+i).attr('data-dbg',direction);
		}},1000);
	//alert('!');
		count=1;
		direction="backward";
		//return;//}
	}else if (direction  == "backward"){
		current = current-parseInt($('#flash-items li').css('width').replace(/[^-\d\.]/g, ''))-parseInt($('#flash-items li').css('margin-left').replace(/[^-\d\.]/g, ''));
		if (mode==2)begin++;
		for (var i = begin ; i <= size ; i ++){
			$('#flash-items li#item_'+i).animate({'left':current+'px'},11500);//css('left',current+'px');
			//$('#flash-items li#item_'+i).attr('data-dbg',direction);
		}
		count++;
		if(count>=size+1){count=1;direction="forward";}
	}
	
}

function galleryAnimateTest(){
	
	var size=$('#flash-items li').length;
	if (size>0){

		if (direction  == "backward"){
			var myCurrent = 400;//parseInt($('#flash-items li#item_1').css('width').replace(/[^-\d\.]/g, ''));
			current= parseInt($('#flash-items').css('left').replace(/[^-\d\.]/g, ''));
			current = -(size+1)*(parseInt($('#flash-items li#item_1').css('width').replace(/[^-\d\.]/g, ''))+parseInt($('#flash-items li#item_1').css('margin-left').replace(/[^-\d\.]/g, '')));
			

				$('#flash-items').animate({'left':current+'px'},8200*size,function(){
					$('#flash-items').css('left',myCurrent+'px');				
					
					galleryAnimateTest();
				});

		}
	}
}
