$(document).ready(function(){
	s = new slider("#conteneur_slider");
});

var slider = function(id){
	var self = this;
	var el = new Array();
			var tags = document.getElementsByTagName('div');
			var tcl = " bloc_slider ";
			for(i=0,j=0; i<tags.length; i++) { 
				var test = " " + tags[i].className + " ";
				if (test.indexOf(tcl) != -1) 
					el[j++] = tags[i];
			} 
	this.div = $(id);
	this.largeurCache = this.div.width();
	this.largeur=-10000;
	this.compte=0;
	this.div.find("div").each(function(){
		self.largeur+=$(this).width();
		self.largeur+=30;
		self.compte++;
	});
	this.compte=this.compte-3;
	this.compte=this.compte/2;
	this.largeur=this.largeur-this.compte*195;
	this.largeur=this.largeur-this.compte*30;
	this.largeur-=64;
	this.largeur-=120;
	this.slider = this.div.find(".slider");
	this.prec = this.div.find(".prec");
	this.suiv = this.div.find(".suiv");
	
	this.saut = this.largeurCache-30;
	this.nombre_saut = Math.ceil(this.largeur/this.saut-this.largeurCache/this.saut)-1;
	this.courant=0;
	
	this.suiv.click(function(){
		if(self.courant<=self.nombre_saut)
		{
			self.courant++;
			self.div.animate({
				height:el[self.courant].offsetHeight
			},1000);
			self.slider.animate({
				left:30-(self.courant*self.saut)
			},1000);
		}
	});
	
	this.prec.click(function(){
		if(self.courant>0)
		{
			self.courant--;
			self.div.animate({
				height:el[self.courant].offsetHeight
			},1000);
			self.slider.animate({
				left:30-(self.courant*self.saut)
			},1000);
		}
	});
}
