$(document).ready(function(){
s = new slider("#masqueGalerie",3);
s2 = new flowbook("#flowGrands",6,".flowSlider",".flowPrec2",".flowSuiv2",128);
s3 = new flowbook("#flowLaby",6,".flowSlider",".flowPrec2",".flowSuiv2",128);
s4 = new flowbook("#flowJaune",6,".flowSlider",".flowPrec2",".flowSuiv2",128);
s5 = new flowbook("#flowMsk",6,".flowSlider",".flowPrec2",".flowSuiv2",128);

s6 = new flowbook("#flowSalons",6,".homeUneSlider",".homeBlocBtnLeft",".homeBlocBtnRight",280);
s7 = new flowbook("#flowRevuePresse",6,".homeUneSlider",".homeBlocBtnLeft",".homeBlocBtnRight",280);
s8 = new flowbook("#flowBreves",6,".homeUneSlider",".homeBlocBtnLeft",".homeBlocBtnRight",280);

s9 = new flowbook("#flowPresse",6,".flowSlider2",".flowPrec3",".flowSuiv3",190);
s10 = new flowbook("#flowPresseRencontre",6,".flowSlider2",".flowPrec3",".flowSuiv3",190);


});

var slider = function(id,etapes) {
	var self=this;
	// this.varEtapes = $(etapes);
	this.div = $(id);
	this.slider=this.div.find(".galSlider")
	this.largeurCache = this.div.width();
	// this.largeur=3000;
	this.galPrec = this.div.find(".galPrec");
	this.galSuiv = this.div.find(".galSuiv");
	this.saut = this.largeurCache;
	// this.nbEtapes = Math.ceil(this.largeur/this.saut - this.largeurCache/this.saut);
	this.nbEtapes = etapes;
	
	// alert(this.nbEtapes);
	this.courant=0;
	this.intervale=5000;

		window.setInterval(function() {
			if(self.courant<self.nbEtapes){
				self.courant++;
				self.slider.animate({
					left:-self.courant*self.saut
				},500);
			}
			else{
				self.courant=0;
				self.slider.animate({
					left:-self.courant*self.saut
				},500);
			}
		}, self.intervale);
	
	this.galSuiv.click(function(){
		if(self.courant<self.nbEtapes){
			self.courant++;
			self.slider.animate({
				left:-self.courant*self.saut
			},500);
		}
		else{
			self.courant=0;
			self.slider.animate({
				left:-self.courant*self.saut
			},500);
		}
	});

	this.galPrec.click(function(){
		if(self.courant>0){
			self.courant--;
			self.slider.animate({
				left:-self.courant*self.saut
			},500);
		}
		else{
			self.courant=self.nbEtapes;
			self.slider.animate({
				left:-self.courant*self.saut
			},500);
		}
	});	
	
}


/* Books Sliders */


var flowbook = function(id,etapes,findSlider,findPrec,findSuiv,findCache) {
	var flow=this;
	// this.varEtapes = $(etapes);
	this.div = $(id);
	this.slider=this.div.find(findSlider);
	// this.largeurCache = this.div.width();
	this.largeurCache=findCache;
	this.galPrec = this.div.find(findPrec);
	this.galSuiv = this.div.find(findSuiv);
	this.saut = this.largeurCache;
	// this.nbEtapes = Math.ceil(this.largeur/this.saut - this.largeurCache/this.saut);
	this.nbEtapes = etapes;
	
	// alert(this.nbEtapes);
	this.courant=0;


	this.galSuiv.click(function(){
		if(flow.courant<flow.nbEtapes){
			flow.courant++;
			flow.slider.animate({
				left:-flow.courant*flow.saut
			},500);
		}
		else{
			flow.courant=0;
			flow.slider.animate({
				left:-flow.courant*flow.saut
			},500);
		}
	});

	this.galPrec.click(function(){
		if(flow.courant>0){
			flow.courant--;
			flow.slider.animate({
				left:-flow.courant*flow.saut
			},500);
		}
		else{
			flow.courant=flow.nbEtapes;
			flow.slider.animate({
				left:-flow.courant*flow.saut
			},500);
		}
	});	
	
}

