var total = 0;
var duree = 7000;
var largeur = 400;
var droite = 0;
var global_pas = 0;
var mouvement_pas = 0;
var mouvement_en_cours = 0;
var bloque_permanent = 0;



function panneau_lance() {
	x_panneau_cont(panneau_lance2);
}

function panneau_lance2(r) {
	document.getElementById('panneau_contenu').innerHTML = r;
	total = parseInt(document.getElementById('panneau_cont_nb').value);
	setTimeout('tourne_permanent()', 5000);
}


  function move_gauche() {
    if (mouvement_en_cours == 1) {
	  setTimeout("move_gauche()", 50);
    } else {
      mouvement_pas = 0;

	  if (global_pas == 0) {
	    global_pas = total;
	    droite = total * largeur;
		document.getElementById('scroll_clipper').scrollLeft = droite;
	  }

	  if (global_pas > 0) {
 		mouvement_en_cours = 1;
		bloque_permanent = 1;
		move_gauche_action();
		global_pas = global_pas - 1;
	  }
	}
  }

  function move_gauche_manu() {
   if(total) {
    move_gauche();
	bloque_permanent = 1;
   }
  }

  function move_gauche_action() {
    if ((mouvement_pas==0) || (mouvement_pas==16)) {
	  droite = droite - 1;
    }
    if ((mouvement_pas==1) || (mouvement_pas==15)) {
	  droite = droite - 4;
    }
    if ((mouvement_pas==2) || (mouvement_pas==14)) {
	  droite = droite - 9;
    }
    if ((mouvement_pas==3) || (mouvement_pas==13)) {
	  droite = droite - 16;
    }
    if ((mouvement_pas==4) || (mouvement_pas==12)) {
	  droite = droite - 25;
    }
    if ((mouvement_pas==5) || (mouvement_pas==11)) {
	  droite = droite - 36;
    }
    if ((mouvement_pas==6) || (mouvement_pas==10)) {
	  droite = droite - 40;
    }
    if ((mouvement_pas>=7) && (mouvement_pas<=9)) {
	  droite = droite - 46;
    }
    document.getElementById('scroll_clipper').scrollLeft = droite;
	mouvement_pas = mouvement_pas + 1;
	if (mouvement_pas <= 16) {
		window.setTimeout("move_gauche_action()", 20);
	} else {
		mouvement_en_cours = 0;
	}
  }


  function move_droite() {
    if (mouvement_en_cours == 1) {
	  setTimeout("move_droite()", 50);
    } else {
      mouvement_pas = 0;

	  if (global_pas == (total - 1)) {
	    global_pas = 0;
	    droite = 0;
		document.getElementById('scroll_clipper').scrollLeft = 0;
	  }

	  if (global_pas < (total - 1))	{
		mouvement_en_cours = 1;
		move_droite_action();
		global_pas = global_pas + 1;
	  }
	}
  }

  function move_droite_manu() {
   if(total) {
    move_droite();
	bloque_permanent = 1;
   }
  }

  function move_droite_action() {
    if ((mouvement_pas==0) || (mouvement_pas==16)) {
	  droite = droite + 1;
    }
    if ((mouvement_pas==1) || (mouvement_pas==15)) {
	  droite = droite + 4;
    }
    if ((mouvement_pas==2) || (mouvement_pas==14)) {
	  droite = droite + 9;
    }
    if ((mouvement_pas==3) || (mouvement_pas==13)) {
	  droite = droite + 16;
    }
    if ((mouvement_pas==4) || (mouvement_pas==12)) {
	  droite = droite + 25;
    }
    if ((mouvement_pas==5) || (mouvement_pas==11)) {
	  droite = droite + 36;
    }
    if ((mouvement_pas==6) || (mouvement_pas==10)) {
	  droite = droite + 40;
    }
    if ((mouvement_pas>=7) && (mouvement_pas<=9)) {
	  droite = droite + 46;
    }
    document.getElementById('scroll_clipper').scrollLeft = droite;
	mouvement_pas = mouvement_pas + 1;
	if (mouvement_pas <= 16) {
		window.setTimeout("move_droite_action()", 20);
	} else {
		mouvement_en_cours = 0;
	}
  }

  function tourne_permanent() {
	if (bloque_permanent) {
	  bloque_permanent = bloque_permanent - 1;
	} else {
	  move_droite();
	}
	setTimeout("tourne_permanent()", duree);
  }
