/*
    carrouselh JS
*/



var carrouselh = {
    
    nbSlide: 0,
    nbCurrent: 1,
    elemCurrent : null,
    elem : null,
	
    
    init : function(elem){
        this.nbSlide = elem.find(".hslide").length;
        
		// Créer la pagination
      
      	elem.find(".nexth").click(function(){carrouselh.gotoNextImage(carrouselh.nbCurrent+1);});
		elem.find(".prevh").click(function(){carrouselh.gotoPreviousImage(carrouselh.nbCurrent-1);});
        
        // Initialisation du carrousel
        this.elem=elem;
        elem.find(".hslide").hide();
        elem.find(".hslide:first").show();
        this.elemCurrent = elem.find(".hslide:first");
		
        

    },
    
    gotoSlide : function(num){
        if(num==this.nbCurrent){ return false; }
        

		this.elemCurrent.find(".visuh").fadeOut();
        this.elem.find("#slideh"+num).show();
        this.elem.find("#slideh"+num+" .visuh").hide().fadeIn();
        var prixHeight = this.elemCurrent.find(".prixh").height();
        this.elemCurrent.find(".prixh").animate({"bottom": -prixHeight},500);
        this.elem.find("#slideh"+num+" .prixh").css("bottom",-prixHeight).animate({"bottom": 0},500);
    
        
        
        
        this.nbCurrent = num;
        this.elemCurrent = this.elem.find("#slideh"+num);
    },
    
	gotoNextImage : function (num){
	if(num<=this.nbSlide) // on vérifie que l'on ne soit pas à la fin des images
	{
	this.elemCurrent.fadeOut(); // quand on click, cache l'image en cours
	this.elem.find("#slideh"+ num).fadeIn(); // on va ensuite chopper l'image en fonction de son indice
	this.nbCurrent = num; // on met à jour l'indice de l'élement en cours
	this.elemCurrent = this.elem.find("#slideh"+num); // on met à jour l'elem en cours
	}
	else // sinon on retourne à l'image 1
	{
	num=1;
	this.elemCurrent.fadeOut();
	this.elem.find("#slideh"+ num).fadeIn(); // on va ensuite chopper l'elem en fonction de son indice
	this.nbCurrent = num; // on met à jour l'indice de l'élement en cours
	this.elemCurrent = this.elem.find("#slideh"+num); // on met à jour l'elem en cours
	}
	},

//Precedent
	gotoPreviousImage : function (num){
	if(num<1) // si on veut aller, en dessous de 0, on retourne à la derniere image
	{
	num=this.nbSlide;
	this.elemCurrent.fadeOut(); // quand on click, cache l'image en cours
	this.elem.find("#slideh"+ num).fadeIn(); // on va ensuite chopper l'elem en fonction de son indice
	this.nbCurrent = num; // on met à jour l'indice de l'élement en cours
	this.elemCurrent = this.elem.find("#slideh"+num); // on met à jour l'elem en cours
	}
	else
	{
	this.elemCurrent.fadeOut();
	this.elem.find("#slideh"+ num).fadeIn(); // on va ensuite chopper l'elem en fonction de son indice
	this.nbCurrent = num; // on met à jour l'indice de l'élement en cours
	this.elemCurrent = this.elem.find("#slideh"+num); // on met à jour l'elem en cours
	}
	}

}


$(function(){
    carrouselh.init($("#carrouselh"));
});
	
