/* ---------- CARROUSEL ----------- */

var carrousel = {

	nbSlide : 0,
	nbCurrent : 1,
	elemCurrent : null,
	elem : null,
	timer : null,
	
	init : function(elem){
		this.nbSlide = elem.find(".slide").length;
			
		// INITIALISATION DU CARROUSEL
		this.elem=elem;
		elem.find(".slide").hide();
		elem.find(".slide:first").show();
		this.elemCurrent=elem.find(".slide:first");
		
		// CRÉATION TIMER
		carrousel.play();
	},
	
	gotoSlide : function(num){
		if(num == this.nbCurrent)
		{ return false; }
		
		/* ANIMATION FADEIN FADEOUT  */
		
		this.elemCurrent.fadeOut();
		this.elem.find(".slide:eq("+(num-1)+")").fadeIn();
		
		// ANIMATION EN SLIDE 
		/*
		var direction = 1; 
		if(num < this.nbCurrent){direction = -1;}

		var cssDepart = {"left" : direction*this.elem.width()};
		var cssArrivee = {"left" : -direction*this.elem.width()};
		this.elem.find("#slide"+num).show().css(cssDepart);
		
		this.elem.find("#slide"+num).animate({"top":0, "left":0},1000);
		this.elemCurrent.animate(cssArrivee,1000);
		*/
	
		this.nbCurrent=num;
		this.elemCurrent = this.elem.find("#slide"+num);
	},
	
	next : function(){
		var num = this.nbCurrent+1;
		if(num > this.nbSlide){
			num = 1;
		}
		this.gotoSlide(num);
	},
	
	play : function(){
		window.clearInterval(carrousel.timer);
		this.timer = window.setInterval("carrousel.next()",5000);
	}
}

$(function(){
		carrousel.init($("#carrousel"));
	});
