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

var carrousel = {

	nbSlide : 0,
	nbCurrent : 1,
	elemCurrent : null,
	elemCurrentTxt : null,
	elem : null,
	timer : null,
	
	init : function(elem){
		this.nbSlide = elem.find(".slide").length;
		
		this.nbSlideTxt = elem.find(".slide_txt").length;
		
		// Création de la pagination
		/*
			elem.append('<div class="navigation"></div>');
			for(var i=1; i<=this.nbSlide;i++)
			{
				elem.find(".navigation").append("<span>"+i+"</span>");
			}
		*/
		elem.find(".navigation span").click(function(){ carrousel.gotoSlide(this.id); })
		/*elem.find(".navigation span").hover(function(){ carrousel.gotoSlide(this.id); })*/
		
		// Initialisation du carrousel
		this.elem=elem;
		elem.find(".slide").fadeOut(1000);
		elem.find(".slide:first").fadeIn(1000);
		
		elem.find(".slide_txt").hide();
		elem.find(".slide_txt:first").show();
		
		this.elemCurrent=elem.find(".slide:first");
		this.elemCurrentTxt=elem.find(".slide_txt:first");
		
		
		$(".crs_page:first").addClass("active");
		
		// CRÉATION TIMER
		carrousel.play();
		
		// STOP WHEN HOVER
		//elem.mouseover(carrousel.stop);
		// PLAY WHEN OUT
		//elem.mouseout(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 normale ******************
		
			this.elemCurrent.fadeOut(1000);
			this.elemCurrentTxt.hide();
			
			this.elem.find(".slide:eq("+(num-1)+")").fadeIn(1000);
			this.elem.find(".slide_txt:eq("+(num-1)+")").show();
		
		
		//this.elem.find("#slide"+num).fadeIn();
		
		
		// ANIMATION EN SLIDE MONTANT
			/*
			var direction = 1; 
			if(num < this.nbCurrent){direction = 0;}
			
			var cssArrivee = {"top" : -direction*this.elem.height()};
			this.elem.find("#slide"+num).animate({"top":0, "left":0},0);
			
			this.elemCurrent.animate(cssArrivee,500);
			*/
		
		/* 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},500);
		this.elemCurrent.animate(cssArrivee,500);
		*/
		
		/* ANIMATION AVEC TITRE QUI MONTE 
		this.elemCurrent.find(".visu").fadeOut();
		this.elem.find("#slide"+num).show();
		this.elem.find("#slide"+num+" .visu").hide().fadeIn();
		
		var titreHeight = this.elemCurrent.find(" .crs_titre").height();
		
		this.elemCurrent.find(".visu .crs_titre").animate({"bottom": - titreHeight},500);
		this.elem.find("#slide"+num+" .crs_titre").css("bottom",- titreHeight).animate({"bottom": 0},500);
		*/
		this.elem.find(".navigation span").removeClass("active");
		this.elem.find(".navigation span:eq("+(num-1)+")").addClass("active");
		this.nbCurrent=num;
		this.elemCurrent = this.elem.find("#slide"+num);
		this.elemCurrentTxt = this.elem.find("#slide_txt"+num);
	},
	
	next : function(){
		var num = this.nbCurrent+1;
		if(num > this.nbSlide){
			num = 1;
		}
		this.gotoSlide(num);
	},
	
	prev : function(){
		this.num = this.nbCurrent-1;
		if(tnum < 1){
			num = this.nbSlide;
		}
		this.gotoSlide(num);
	},
	
	stop : function(){
		window.clearInterval(carrousel.timer);
	},
	
	play : function(){
		window.clearInterval(carrousel.timer);
		this.timer = window.setInterval("carrousel.next()",5000);
	}

}

$(function(){
		carrousel.init($("#carrousel"));
	});
/*$(function(){
		carrousel.init($("#carrousel_meteo"));
	});*/
	
/* ---------- CARROUSEL OFFRES ACTU EVENEMENTS ----------- */

var carrouselbloc = {

	nbSlide : 0,
	nbCurrent : 1,
	elemCurrent : null,
	elemCurrentTxt : null,
	elem : null,
	timer : null,
	
	init : function(elem){
		this.nbSlide = elem.find(".slidebloc").length;
		
		this.nbSlideTxt = elem.find(".slidebloc_txt").length;
		
		// Initialisation du carrouselbloc
		this.elem=elem;
		elem.find(".slidebloc").fadeOut(1000);
		elem.find(".slidebloc:first").fadeIn(1000);
		
		elem.find(".slidebloc_txt").hide();
		elem.find(".slidebloc_txt:first").show();
		
		this.elemCurrent=elem.find(".slidebloc:first");
		this.elemCurrentTxt=elem.find(".slidebloc_txt:first");
		
		// CRÉATION TIMER
		carrouselbloc.play();
		
		// STOP WHEN HOVER
		//elem.mouseover(carrouselbloc.stop);
		// PLAY WHEN OUT
		//elem.mouseout(carrouselbloc.play);
	},
	
	gotoSlide : function(num){
		if(num == this.nbCurrent)
		{ return false; }
		
		/* ANIMATION FADEIN FADEOUT  */
		
		/*
		this.elemCurrent.fadeOut(2000);
		this.elem.find(".slidebloc:eq("+(num-1)+")").fadeIn(2000);
		*/
		
		// ANIMATION EN SLIDE 
		var direction = 1; 
		if(num < this.nbCurrent){direction = -1;}

		var cssDepart = {"top" : direction*this.elem.height()};
		var cssArrivee = {"top" : -direction*this.elem.height()};
		this.elem.find("#slidebloc"+num).show().css(cssDepart);
		
		this.elem.find("#slidebloc"+num).animate({"top":0, "left":0},1000);
		this.elemCurrent.animate(cssArrivee,1000);
		
	
		this.nbCurrent=num;
		this.elemCurrent = this.elem.find("#slidebloc"+num);
	},
	
	next : function(){
		var num = this.nbCurrent+1;
		if(num > this.nbSlide){
			num = 1;
		}
		this.gotoSlide(num);
	},
	
	prev : function(){
		this.num = this.nbCurrent-1;
		if(tnum < 1){
			num = this.nbSlide;
		}
		this.gotoSlide(num);
	},
	
	stop : function(){
		window.clearInterval(carrouselbloc.timer);
	},
	
	play : function(){
		window.clearInterval(carrouselbloc.timer);
		this.timer = window.setInterval("carrouselbloc.next()",5000);
	}
}
$(function(){
		carrouselbloc.init($("#carrouselbloc"));
	});
	
/* ---------- CARROUSEL METEO ----------- */

var carrousel_meteo = {

	nbSlide : 0,
	nbCurrent : 1,
	elemCurrent : null,
	elemCurrentTxt : null,
	elem : null,
	timer : null,
	
	init : function(elem){
		this.nbSlide = elem.find(".slide_meteo").length;
		
		this.nbSlideTxt = elem.find(".slide_txt_meteo").length;
		
		// Création de la pagination
		/*
			elem.append('<div class="navigation"></div>');
			for(var i=1; i<=this.nbSlide;i++)
			{
				elem.find(".navigation").append("<span>"+i+"</span>");
			}
		*/
		elem.find(".navigation_meteo span").click(function(){ carrousel_meteo.gotoSlide(this.id); })
		/*elem.find(".navigation span").hover(function(){ carrousel_meteo.gotoSlide(this.id); })*/
		
		// Initialisation du carrousel_meteo
		this.elem=elem;
		elem.find(".slide_meteo").fadeOut(1000);
		elem.find(".slide_meteo:first").fadeIn(1000);
		
		elem.find(".slide_txt_meteo").hide();
		elem.find(".slide_txt_meteo:first").show();
		
		this.elemCurrent=elem.find(".slide_meteo:first");
		this.elemCurrentTxt=elem.find(".slide_txt_meteo:first");
		
		
		$(".crs_page:first").addClass("active");
		
		// CRÉATION TIMER
		carrousel_meteo.play();
		
		// STOP WHEN HOVER
		//elem.mouseover(carrousel_meteo.stop);
		// PLAY WHEN OUT
		//elem.mouseout(carrousel_meteo.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 normale ******************
		
			this.elemCurrent.hide(1000);
			this.elemCurrentTxt.hide();
			
			this.elem.find(".slide_meteo:eq("+(num-1)+")").show();
			this.elem.find(".slide_txt_meteo:eq("+(num-1)+")").show();
		
		
		//this.elem.find("#slide"+num).fadeIn();
		
		
		// ANIMATION EN SLIDE MONTANT
			/*
			var direction = 1; 
			if(num < this.nbCurrent){direction = 0;}
			
			var cssArrivee = {"top" : -direction*this.elem.height()};
			this.elem.find("#slide"+num).animate({"top":0, "left":0},0);
			
			this.elemCurrent.animate(cssArrivee,500);
			*/
		
		/* 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},500);
		this.elemCurrent.animate(cssArrivee,500);
		*/
		
		/* ANIMATION AVEC TITRE QUI MONTE 
		this.elemCurrent.find(".visu").fadeOut();
		this.elem.find("#slide"+num).show();
		this.elem.find("#slide"+num+" .visu").hide().fadeIn();
		
		var titreHeight = this.elemCurrent.find(" .crs_titre").height();
		
		this.elemCurrent.find(".visu .crs_titre").animate({"bottom": - titreHeight},500);
		this.elem.find("#slide"+num+" .crs_titre").css("bottom",- titreHeight).animate({"bottom": 0},500);
		*/
		this.elem.find(".navigation_meteo span").removeClass("active");
		this.elem.find(".navigation_meteo span:eq("+(num-1)+")").addClass("active");
		this.nbCurrent=num;
		this.elemCurrent = this.elem.find("#slide_meteo"+num);
		this.elemCurrentTxt = this.elem.find("#slide_txt_meteo"+num);
	},
	
	next : function(){
		var num = this.nbCurrent+1;
		if(num > this.nbSlide){
			num = 1;
		}
		this.gotoSlide(num);
	},
	
	prev : function(){
		this.num = this.nbCurrent-1;
		if(tnum < 1){
			num = this.nbSlide;
		}
		this.gotoSlide(num);
	},
	
	stop : function(){
		window.clearInterval(carrousel_meteo.timer);
	},
	
	play : function(){
		window.clearInterval(carrousel_meteo.timer);
		this.timer = window.setInterval("carrousel_meteo.next()",5000);
	}

}

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