﻿/*$(document).ready(function(){	
	s=new slider("#galerie1");
	//s=new slider("#galerie2");
});*/

var slider=function(id){
	var toto=this;
	this.div=$(id);
	//alert(this.div.width());
	hauteurCache=this.div.width();
	this.slider=this.div.find(".slider");
	this.hauteurCache=this.div.height()-20; //20 represente le margin haut bas /2 voir si padding h b /2 a prendre en compte
	this.hauteur=0;
	this.nbinside=0;
	this.div.find('.inside_txt').each(function(){
		toto.nbinside++;
	//this.div.find('a').each(function(){	
		toto.hauteur+=$(this).height();
		//alert(toto.hauteur);
		toto.hauteur+=parseInt($(this).css("padding-top"));
		//alert(toto.hauteur);
		toto.hauteur+=parseInt($(this).css("padding-bottom"));
		//alert(toto.hauteur);
		toto.hauteur+=parseInt($(this).css("margin-top"));
		//alert(toto.hauteur);
		toto.hauteur+=parseInt($(this).css("margin-bottom"));	
		//alert(toto.hauteur);
	});
	this.nbinside-=1;

	this.prec=this.div.find(".prec");
	this.suiv=this.div.find(".suiv");
	this.nbEtapes=Math.ceil(this.hauteur/this.saut);
	this.courant=0;
	if(toto.nbinside==0){
		toto.suiv.hide();
	};

	
	this.suiv.click(function(){
		if(toto.courant<toto.nbinside){
			toto.courant++;			
			toto.slider.animate({
			top:-toto.courant*540//toto.hauteurCache
			},1000);
		};
		if(toto.courant>0){
			toto.prec.show();
		}
		if(toto.courant==toto.nbinside){
			toto.suiv.hide();
		};
	});

	this.prec.click(function(){
		if(toto.courant>0){
			toto.courant--;
			toto.slider.animate({
			top:-toto.courant*540//toto.hauteurCache
			},1000);
		};
		if(toto.courant==0){
			toto.prec.hide();
		};
		if(toto.courant!=toto.nbinside){
			toto.suiv.show();
		};
	});

}

