$.fn.wait = function(time, type) {
        time = time || 1000;
        type = type || "fx";
        return this.queue(type, function() {
            var self = this;
            setTimeout(function() {
                $(self).dequeue();
            }, time);
        });
    };

$(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;
	self.largeur=0;
	this.div.find('a').each(function(){
	 self.largeur += $(this).width();
	 self.largeur += 14;
	});
	this.largeurReal = this.largeur - $(id).width();
	this.largeur=self.largeur;
	
	this.slider.css({'width':this.largeur});
	
	
	this.prec = this.div.find(".prec");
	this.suiv = this.div.find(".suiv");
	this.saut = this.largeurCache/2;
	this.nbEtapes = Math.ceil(this.largeur/this.saut - this.largeurCache / this.saut);
	this.courant=0;
	this.suiv.click(function(){
		if(self.courant <= (self.nbEtapes - 1))
		{
			self.courant++;
		  self.slider.animate({
			left: -self.courant * self.saut
			},1000)
		}
		return false;
	});
	
	this.prec.click(function(){
		if(self.courant > 0)
		{
			self.courant--;
		  self.slider.animate({
			"left": -self.courant * self.saut
			},1000)
		}
		if(self.courant <= 0)
		{
			self.slider.animate({
			"left": 74
			},1000)
		}
		return false;
	});
	
	$(".imgThumb").click(function(){
		var id=$(this).attr('url');
		var titre = $(this).attr('title');
		$("#titre").text("");
		$("#big_pict").stop().fadeOut(200).attr('src',id).fadeIn(500);
		$("#titre").text(titre);
		return false;
		});
		
}

function afficheBig(lien)
{
	$("#big_pict").fadeOut(500).attr('src',lien).fadeIn(500);
	
}

function diaporama(){
	var i = 0;
	$(".slider").find("a").each(function(){
		 	var lien = $(this).attr('url');
		 	var titre = $(this).attr('title');
		 	$("#titre").text("");
		  $("#big_pict").fadeOut(500);
		  $("#big_pict").attr('src',lien);
		  $("#big_pict").fadeIn(500);
		  $("#big_pict").delay(2000);
		  $("#titre").text(titre);
		  i++;
		});
		
		
		
}

function autoAffiche(ident){
	//var lien = ident.attr('url');
	var titre = $(this).attr('title');
	//$("#big_pict").fadeOut(500).attr('src',lien).fadeIn(500);
	$("#titre").text(titre);
}

function autoRun(){
			premier = $(".imgThumb").first();
			dernier = $(".imgThumb").last();
			//var titre = premier.attr('title');
			//alert(titre);
			courant = premier;
			while(courant != dernier)
			{
				window.setInterval("autoAffiche("+courant+")",2000);
				courant = courant.next().delay(1000);
			}
			
			
		}

