// JavaScript Document
$(document).ready(function(){
	s = new slider("#galerie");
});

var slider = function(id){
var	self=this;
	this.div = $(id);
	this.slider=this.div.find(".slider");

	this.carrer=this.div.find(".carrer");
	
	this.hauteurCache = this.div.height();
	this.hauteur=0;
		
	this.div.find('a').each(function(){
		self.hauteur+=$(this).height();					  
		self.hauteur+=parseInt($(this).css("padding-top"));
		self.hauteur+=parseInt($(this).css("padding-bottom"));
		self.hauteur+=parseInt($(this).css("margin-top"));
		self.hauteur+=parseInt($(this).css("margin-bottom"));
	});
	
	this.prec = this.div.find(".prec");
	this.suiv = this.div.find(".suiv");
	this.saut = (this.hauteurCache/3);
	
	this.sautCarrer = 170.4;
		
	this.nbEtapes = Math.ceil(this.hauteur/this.saut - this.hauteurCache/this.saut)-1;
	this.courant=0;
	
	this.suiv.click(function(){
		if(self.courant<=self.nbEtapes){
			self.courant++;
			self.slider.animate({
				top:-self.courant*self.saut
			},1000);
			self.carrer.animate({
				top:+self.courant*self.sautCarrer
			},1000);
		}
	});
	
	this.prec.click(function(){
		if(self.courant>0){
			self.courant--;
			self.slider.animate({
				top:-self.courant*self.saut
			},1000);
			self.carrer.animate({
				top:+self.courant*self.sautCarrer
			},1000);
		}
	});
}

