var horizontal = {};
//index courant
horizontal.current = 0;
//contient le nombre de slides
horizontal.num = 0;

/**
   * initialise le slideshow : 
   * place les slides
   *  attache les événements
   */
inithorizontal = function(){
    // on place les éléments de liste
    $(".niveau_horizontal").each(function(i){
        horizontal.num++;
        var _leftPX = (i)*950;
        $(this).css('left',_leftPX+'px');
        $(this).css('top','0px');
        $(this).show();
    });
    //(ajuste le total de slides)
    horizontal.num--;
    //attache les évéments
    $("#prev_niveau_1_1").click(prevBill);
    $("#next_niveau_1_1").click(nextBill);
    
	$("#prev_niveau_1_1").hide();
    $("#next_niveau_1_1").hide();
    if (horizontal.num>=1) {
    	$("#next_niveau_1_1").show();
    }
}
/**
   * affiche la diapo suivante
   */
nextBill = function(){
    //calcul du prochain index (si max, on revient au début)
    var _next = (horizontal.current+1>horizontal.num)? 0 : horizontal.current+1;
    moveBills(_next);
    
    return false;
}
/**
   * affiche la diapo précédente
   */
prevBill = function(){
    //calcul du prochain index (si min, on va à la fin)
    var _next = (horizontal.current-1<0)? horizontal.num : horizontal.current-1;
    moveBills(_next);
    
    return false;
}
/**
   * affiche la diapo dont l'index est passé en paramètre
   */
moveBills = function(index,vitesse)
{
    //replace les li en les animant
    $(".niveau_horizontal").each(function(i){
        var _leftPX = (i-index)*950;
        

        $(this).animate({left:_leftPX+'px'},300);
        

    });
    //réaffecte l'index courant
    horizontal.current = index;
    
    if (horizontal.current==0) {
		$("#prev_niveau_1_1").hide();
	} else {
		$("#prev_niveau_1_1").show();
	}
	
	if (horizontal.current==1) {
		$("#next_niveau_1_1").hide();
	} else {
		$("#next_niveau_1_1").show();
	}
	
	if (horizontal.current==0) {
		javascript:ytplayer.stopVideo();
	}
	
}

//initialise la page après son chargement
$(document).ready(function(){
    inithorizontal();
});

