/* Carrousel JavaScript */

var carrousel = {
	
	nbSlide : 0,
	nbCurrent : 1,
	elemCurrent : null,
	elem : null,
	timer : null,
	
	
	init : function(elem) {
		this.nbSlide = elem.find(".slide").length;
	
		// Créer la pagination
		$("#pagination").append('<div class="nav_slide"></div>');
		for(var i=1;i <= this.nbSlide; i++) {
			$("#pagination").find(".nav_slide").append('<span>'+i+'</span>');
		}
		
		$("#pagination").find(".nav_slide span").click(function(){ carrousel.gotoSlide($(this).text()); });

		$("#slidePrev").click(function(){carrousel.prev();});
		$("#slideNext").click(function(){carrousel.next();});
				
		// Initialisation du carrousel
		this.elem = elem;
		elem.find(".slide").hide();
		elem.find(".slide:first").show();
		this.elemCurrent = elem.find(".slide:first");
		$("#pagination").find(".nav_slide span:first").addClass("active");
		
		// On ajoute le timer
		carrousel.timer = window.setInterval("carrousel.next()",4000);
	
	},
	
	gotoSlide : function(num) {
		if(num == this.nbCurrent) { return false; }
		
		this.elemCurrent.fadeOut();
		this.elem.find("#slide"+num).show();
		this.elem.find("#slide"+num).hide().fadeIn();
		
		var titleHeight=this.elemCurrent.find(".title").height();
		this.elemCurrent.find(".title").animate({"bottom":-titleHeight},700);
		this.elem.find("#slide"+num+" .title").css("bottom",-titleHeight).animate({"bottom":0},700);
			
		
		$("#pagination").find(".nav_slide span").removeClass("active");
		$("#pagination").find(".nav_slide span:eq("+(num-1)+")").addClass("active");
		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);
	},
	
	prev : function() {
		var num = this.nbCurrent-1;
		if(num < 1) {
			num = this.nbSlide;
		}
		this.gotoSlide(num);
	}
		
}

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

function actif_rech(a){if(a.value=="Rechercher"){a.value=""}}
function des_rech(a){if(a.value==""){a.value="Rechercher"}}

function show(id)
{
if(id==1) {
	$("#2").fadeOut().hide();
	$(".btn_2").css("background", "url('/wp-content/themes/PatrickBeaudouin/images/agenda_grey_back.png') repeat-x");
	$("#3").fadeOut().hide();
	$(".btn_3").css("background", "url('/wp-content/themes/PatrickBeaudouin/images/agenda_grey_back.png') repeat-x");
	$("#4").fadeOut().hide();
	$(".btn_4").css("background", "url('/wp-content/themes/PatrickBeaudouin/images/agenda_grey_back.png') repeat-x");
	$("#1").hide().fadeIn();
	$(".btn_1").css("background", "url('/wp-content/themes/PatrickBeaudouin/images/agenda_blue_back_t1.png') no-repeat");
	}
if(id==2) {
	$("#1").fadeOut().hide();
	$(".btn_1").css("background", "url('/wp-content/themes/PatrickBeaudouin/images/agenda_grey_back.png') repeat-x");
	$("#3").fadeOut().hide();
	$(".btn_3").css("background", "url('/wp-content/themes/PatrickBeaudouin/images/agenda_grey_back.png') repeat-x");
	$("#4").fadeOut().hide();
	$(".btn_4").css("background", "url('/wp-content/themes/PatrickBeaudouin/images/agenda_grey_back.png') repeat-x");
	$("#2").hide().fadeIn();
	$(".btn_2").css("background", "url('/wp-content/themes/PatrickBeaudouin/images/agenda_blue_back_t1.png') no-repeat");
	}
if(id==3) {
	$("#1").fadeOut().hide();
	$(".btn_1").css("background", "url('/wp-content/themes/PatrickBeaudouin/images/agenda_grey_back.png') repeat-x");
	$("#2").fadeOut().hide();
	$(".btn_2").css("background", "url('/wp-content/themes/PatrickBeaudouin/images/agenda_grey_back.png') repeat-x");
	$("#4").fadeOut().hide();
	$(".btn_4").css("background", "url('/wp-content/themes/PatrickBeaudouin/images/agenda_grey_back.png') repeat-x");
	$("#3").hide().fadeIn();
	$(".btn_3").css("background", "url('/wp-content/themes/PatrickBeaudouin/images/agenda_blue_back_t2.png') no-repeat");
	}
if(id==4) {
	$("#1").fadeOut().hide();
	$(".btn_1").css("background", "url('/wp-content/themes/PatrickBeaudouin/images/agenda_grey_back.png') repeat-x");
	$("#2").fadeOut().hide();
	$(".btn_2").css("background", "url('/wp-content/themes/PatrickBeaudouin/images/agenda_grey_back.png') repeat-x");
	$("#3").fadeOut().hide();
	$(".btn_3").css("background", "url('/wp-content/themes/PatrickBeaudouin/images/agenda_grey_back.png') repeat-x");
	$("#4").hide().fadeIn();
	$(".btn_4").css("background", "url('/wp-content/themes/PatrickBeaudouin/images/agenda_blue_back_t2.png') no-repeat");
	}
}
