// 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.largeurCache = this.div.width();
	this.largeur = 0;	
	this.div.find('a').each(function(){
	self.largeur+=$(this).width();
	self.largeur+=parseInt($(this).css("padding-left"));
	self.largeur+=parseInt($(this).css("padding-right"));
	self.largeur+=parseInt($(this).css("margin-left"));
	self.largeur+=parseInt($(this).css("margin-right"));
	});
	this.last = this.div.find(".last");
	this.next = this.div.find(".next");
	this.saut = 498;
	this.nbEtapes = 6; 
	this.courant=0;
	$('.last').hide();
	$("#debord_gauche").hide();
	
	this.next.click(function(){
		if(self.courant<=self.nbEtapes) {
			$('.last').fadeIn('slow', function() {});
			$('#debord_gauche').fadeIn('slow', function() {});
			$('#legende').fadeOut('slow', function() {});
			$('#legende').fadeIn('slow', function() {});			
			self.courant++;
			self.slider.animate({
				left:-self.courant*self.saut
			},1000);
		} else {
			self.courant=0;
			self.slider.animate({
				left:-self.courant*self.saut
			},1000);
			$('.last').fadeOut('slow', function() {});
			$('#debord_gauche').fadeOut('slow', function() {});
			$('#legende').fadeOut(750);
			$('#legende').fadeIn(750);			

		}

	});
	
	this.last.click(function(){
		if(self.courant>0) {
			$('#legende').fadeOut('slow', function() {});
			$('#legende').fadeIn('slow', function() {});
			self.courant--;
			self.slider.animate({
				left:-self.courant*self.saut
			},1000);
		}
		
		if(self.courant==0) {
			$('.last').fadeOut('slow', function() {});
			$('#debord_gauche').fadeOut('slow', function() {});
		}
	});
}
	
