$(document).ready(function() {

	$("#open").click(function(){
		$("div#panel").slideDown("slow");	
	});	
	
	$("#close").click(function(){
		$("div#panel").slideUp("slow");	
	});		
	
	$("#toggle a").click(function () {
		$("#toggle a").toggle();
	});		
		

	s = new slider("#gallery");
});


var slider = function(id){
	var self = this;
	this.div = $(id);
	this.slider = this.div.find(".slider");
	this.largeurCache = this.div.width();
	this.largeur = 0;
	this.div.find('a').each(function(){
		self.largeur += $(this).width();
		self.largeur += parseInt($(this).css("margin-left"));
		self.largeur += parseInt($(this).css("margin-right"));
	 });
	this.prec = this.div.find(".prec");
	this.suiv = this.div.find(".suiv");
	
	this.saut = this.largeurCache;
	this.nbEtapes = Math.ceil(this.largeur/this.saut);
	this.courant=0;
	
	this.suiv.click(function(){
		if(self.courant <= (self.nbEtapes-2)) {
		self.courant++;
		self.slider.animate({
			left:-self.courant*self.saut
			},1000);
		}
	});
	
	this.prec.click(function(){
		if(self.courant > 0) {				 
		self.courant--;
		self.slider.animate({
			left:-self.courant*self.saut
			},1000);
		}
	});
		
	
		
}

