//Carrousel v1

var _etatBt = 0;
var _tI;
var _pI = 0;
var timy;

function co_initialisation(maxtI){
	_tI = maxtI;
	$("#img_0").css({ top: "55px", left: "0px", height:"52px", width:"52px" })
	$("#img_0 > img").css({height:"50px" })
	$("#img_1").css({ top: "30px", left: "84px", height:"102px", width:"102px" })
	$("#img_1 > img").css({height:"100px"})
	$("#img_2").css({ top: "5px", left: "220px", height:"152px", width:"152px" })
	$("#img_2 > img").css({height:"150px"})
	$("#img_3").css({ top: "30px", left: "406px", height:"102px", width:"102px" })
	$("#img_3 > img").css({height:"100px"})
	$("#img_4").css({ top: "55px", left: "540px", height:"52px", width:"52px" })
	$("#img_4 > img").css({height:"50px"})
	//$("#btPrev").click( function() { co_previous() } );
	//$("#btNext").click( function() { co_next() } );
	timy = setTimeout(function(){co_next()}, 5000 ) ;
}

function co_previous(){
	if(_etatBt!=1){
		_etatBt=1;
		
		_nImg0=_pI;
		_nImg1=(_pI>(_tI-2))? (_pI+1)-_tI : _pI+1;
		_nImg2=(_pI>(_tI-3))? (_pI+2)-_tI : _pI+2;
		_nImg3=(_pI>(_tI-4))? (_pI+3)-_tI : _pI+3;
		_nImg4=(_pI>(_tI-5))? (_pI+4)-_tI : _pI+4;
		
		$("#img_"+_nImg0).css({ zIndex:"2" });
		$("#img_"+_nImg1).css({ zIndex:"3" });
		$("#img_"+_nImg2).css({ zIndex:"4" });
		$("#img_"+_nImg3).css({ zIndex:"5" });
		$("#img_"+_nImg4).css({ top: "-13px", left: "880px", height:"110%", zIndex:"6", opacity:100 });
		
		$("#img_"+_nImg0).animate({ height: "50%", top: "62px", left:"-20px", opacity:0 }, 800 , function(){co_endAnimPrev()} );
		$("#img_"+_nImg1).animate({ height: "60%", top: "47px", left:"0px"}, 800 );
		$("#img_"+_nImg2).animate({ height: "70%", top: "35px", left:"40px"}, 800 );
		$("#img_"+_nImg3).animate({ height: "80%", top: "22px", left:"150px"}, 800 );
		$("#img_"+_nImg4).animate({ height: "100%", top:"0px", left:"404px"}, 800 );
		_pI=(_pI==(_tI-1)) ? 0 : _pI+1 ;
	}
}

function co_endAnimPrev(){
	_etatBt = 0;
	clearTimeout(timy);
	timy = setTimeout(function(){co_previous()}, 5000 ) ;
}

function co_next(){
	if(_etatBt!=1){
		_etatBt=1;
		
		_nImg0=(_pI==0) ? _tI-1 : _pI-1;
		_nImg1=_pI;
		_nImg2=(_pI>(_tI-2))? (_pI+1)-_tI : _pI+1;
		_nImg3=(_pI>(_tI-3))? (_pI+2)-_tI : _pI+2;
		_nImg4=(_pI>(_tI-4))? (_pI+3)-_tI : _pI+3;
		_nImg5=(_pI>(_tI-5))? (_pI+4)-_tI : _pI+4;
		
		$("#img_"+_nImg0).css({ height: "52px", width:"52px", top: "55px", left:"-52px", zIndex:"1", opacity:0 });
		$("#img_"+_nImg0+" > img").css({ height: "50px" });
		$("#img_"+_nImg1).css({ zIndex:"2" });
		$("#img_"+_nImg2).css({ zIndex:"3" });
		$("#img_"+_nImg3).css({ zIndex:"6" });
		$("#img_"+_nImg4).css({ zIndex:"5" });
		$("#img_"+_nImg5).css({ zIndex:"4" });
		
		$("#img_"+_nImg0).animate({ left:"0px", opacity:100 }, 800  );
		$("#img_"+_nImg1).animate({ height: "102px", width:"102px", top: "30px", left:"84px"}, 800 );
		$("#img_"+_nImg1+" >img").animate({ height: "100px"}, 800 );
		$("#img_"+_nImg2).animate({ height: "152px", width:"152px", top: "5px", left:"220px"}, 800 );
		$("#img_"+_nImg2+" >img").animate({ height: "150px"}, 800 );
		$("#img_"+_nImg3).animate({ height: "100px", width:"102px", top: "30px", left:"406px"}, 800 );
		$("#img_"+_nImg3+" >img").animate({ height: "100px"}, 800 );
		$("#img_"+_nImg4).animate({ height: "52px", width:"52px", top: "50px", left:"540px"}, 800 );
		$("#img_"+_nImg4+" >img").animate({ height: "50px"}, 800 );
		$("#img_"+_nImg5).animate({ left:"592px"}, 800 , function(){co_endAnimNext()} );
		
	}
}

function co_endAnimNext(){
	_pI=(_pI==0) ? (_tI-1) : _pI-1 ;
	_etatBt = 0;
	clearTimeout(timy);
	timy = setTimeout(function(){co_next()}, 5000 ) ;
}