$(document).ready(function() {
  
  	$('#banner_bg').empty();
	
  
    //Calcul du nombre de diapos
    NbrDiapo = news.length;
    //Initialisation du compteur
    Cpt = 0;
    //Définition de la vitesse du Timer
    TSpeed = 8000;
    //Clic enregistré
    clicked = false;
    //Mouseover enregistré
    hover = false;
	//LImg description
	LImg = 694;
	//HImg description
	HImg = 187;
    
    //Ciblage de la bande de diapositive
    $("#banner_bg")
        .wrap('<div id="carrousel_container"></div>')
        .css("width",(LImg * NbrDiapo)+"px")
        .css("height",HImg+"px");
    
    //Définition de la taille des diapos
    $("#banner_bg")
        .css("margin-left","0px");
    
    //Définition de la taille des diapos
    $("#banner_bg li")
        .css("width",LImg+"px")
        .css("height",HImg+"px");
    
    //Ciblage de la zone de visualisation
    $("#carrousel_container")
        .css("z-index","5")
        .css("position","absolute")
        .css("overflow","hidden")
        .css("width",LImg+"px")
        .css("height",HImg+"px")
        .css("margin-left","240px")
		
	//Fonctions de défilement	
    nextSlide = function(param){
        if(param){
            Cpt=param;
            clicked = true;
        }
        else {
            Cpt++;
        };
        if(param==0){
            Cpt=0;
            $("#banner_bg").animate({
                marginLeft : - (LImg * Cpt)
            });
        }
        else if(Cpt > (NbrDiapo-1)){
            Cpt=0;
            $("#banner_bg").animate({
                marginLeft : - (LImg * Cpt)
            });
        }
        else{
            $("#banner_bg").animate({
                marginLeft : - (LImg * Cpt)
            });
        };
        reWrite();
    };
    previousSlide = function(){
        Cpt--;
        if(Cpt < 0){
            Cpt=(NbrDiapo-1);
            $("#banner_bg").animate({
                marginLeft : - (LImg * Cpt)
            });
        }
        else{
            $("#banner_bg").animate({
                marginLeft : - (LImg * Cpt)
            });
        };
        reWrite();
    };
    
    //Déclenchement du timer
    $.timer(TSpeed, function (timer) {
        if(clicked){
            clicked = false;
            $.timer2(TSpeed, function (timer) {
                timer.reset(TSpeed);
            });
        }
        /*if(hover){
            $.timer3(TSpeed, function (timer) {
                timer.reset(TSpeed);
            });
        }*/
        else{
            nextSlide();
        };
    });
    
    for(i=0;i<NbrDiapo;i++){
        $("#banner_bg").append('<div style="float:left; position:relative; display:block; width:'+(LImg-0)+'px; height:'+(HImg-0)+'px"><img style="display:block; position:absolute; z-index:auto;" src="uploads/pics/'+news[i].image+'" /></div>');
    };
        
    $("#banner_bg div.bodytitlebg")
        .css("position","absolute")
        .css("z-index","30")
        .css("padding","15px")
        .css("margin","190px 0px 0px 50px")
        .css("overflow","auto")
        .css("color","#000")
        .css("font-size","18px")
        .css("width","370px")
        .css("height","100px")
        .css("text-transform","uppercase")
        .css("font-weight"),("bold")
        
    $("#banner_bg div.bodytext")
        .css("position","absolute")
        .css("z-index","40")
        .css("padding","15px")
        .css("margin","225px 0px 0px 50px")
        .css("width","370px")
        .css("height","100px")
        .css("overflow","auto")
        .css("font-style","italic")
        .css("color","#000")
        .css("line-height","16px")
        
    $("#banner_bg div.bodytextbg")
        .css("position","absolute")
        .css("z-index","20")
        .css("padding","15px")
        .css("margin","190px 0px 0px 50px")
        .css("width","370px")
        .css("height","100px")
        .css("opacity","0.7")
        .css("overflow","auto")
        .css("-webkit-box-shadow","2px 2px 5px #000")
        .css("background","#FFF")
        .css("font-style","italic")
        .css("color","#000");
	
	//Repositionnement de la <div> gérant les langues
	$('#banner_language')
		.css('z-index','10')
		.children('div').children('a').css('background-color','white');
});
