
// FIN INITIALISE


// DISPLAY
function display_ss_menu(menu,controle){

var le_cadre = document.getElementById(menu);
var le_menu = document.getElementById(menu+'_menu');

	for (i=0;i<initialisation.length;i++)
	{
		if (initialisation[i]==menu) 
		{ 
			indice = i;
		} 
	}
if (controle == initialisation_etat[indice] || controle == 4)
	{
		onouvre = 0;
		if (initialisation_etat[indice] == 0 || initialisation_etat[indice] == 2)
			{
			initialisation_etat[indice] = 3;
			onouvre = 1;
			}
		if (initialisation_etat[indice] == 3)	
			{
			onouvre = 1;
			}
		
		if (onouvre == 1)
			{
				move(menu,indice);
			}
	}
}
// FIN DISPLAY

// DEBUT HIDE
function hide_ss_menu(menu,controle){

var le_cadre = document.getElementById(menu);
var le_menu = document.getElementById(menu+'_menu');

	for (i=0;i<initialisation.length;i++)
	{
		if (initialisation[i]==menu) 
		{ 
			indice = i;
		} 
	}
if (controle == initialisation_etat[indice] || controle == 4)
	{
		onferme = 0;
		if (initialisation_etat[indice] == 1 || initialisation_etat[indice] == 3)
			{
			initialisation_etat[indice] = 2;
			onferme = 1;
			}
		if (initialisation_etat[indice] == 2)	
			{
			onferme = 1;
			}
		
		if (onferme == 1)
			{	
				move(menu,indice);
			}
	}
}
// FIN HIDE

// DEBUT DEPLACEMENT
function move(menu,indice){
	if (initialisation_etat[indice]==3)
		{
			pas = 6;
			pas_cadre = 10;
			pos_max_cadre = parseInt(initialisation_h_cadre[indice])+parseInt(initialisation_pos_cadre[indice]);
			pos_max_texte = parseInt(initialisation_h_texte[indice])+parseInt(initialisation_pos_texte[indice]);
		}
	if (initialisation_etat[indice]==2)
		{
			pas = -6;
			pas_cadre = -5;
			pos_max_cadre = parseInt(initialisation_pos_cadre[indice]);
			pos_max_texte = parseInt(initialisation_pos_texte[indice]);						
		}
	element_cadre = document.getElementById(menu);
	element_texte = document.getElementById(menu+'_menu');	

	nouvelleposition_cadre = parseInt(element_cadre.style.top) + pas_cadre;
	nouvelleposition_texte = parseInt(element_texte.style.top) + pas;	

	// on vérifie l'etat du cadre : en position, ou en mouvement. Dans tous les cas, on le bouge en fonction.
	if (nouvelleposition_cadre >pos_max_cadre && initialisation_etat[indice]==3)
		{
			onstoppe_cadre = 1;	
			element_cadre.style.top = pos_max_cadre;
		}
	else if (nouvelleposition_cadre <pos_max_cadre && initialisation_etat[indice]==2)
		{
			onstoppe_cadre = 0;	
			element_cadre.style.top = pos_max_cadre;
		}
	else
		{
			element_cadre.style.top = nouvelleposition_cadre;
			onstoppe_cadre = 3;	
		}

	// on vérifie l'etat du texte : en position, ou en mouvement. Dans tous les cas, on le bouge en fonction.	
	if (nouvelleposition_texte >pos_max_texte && initialisation_etat[indice]==3)
		{
			onstoppe_texte = 1;	
			element_texte.style.top = pos_max_texte;
		}
	else if (nouvelleposition_texte <pos_max_texte && initialisation_etat[indice]==2)
		{
			onstoppe_texte = 0;	
			element_texte.style.top = pos_max_texte;
		}
	else
		{
			element_texte.style.top = nouvelleposition_texte;
			onstoppe_texte = 3;	
		}
	
	// on va voir ce qu'on fait maintenant que les éléments ont bougé.
	if (onstoppe_texte == onstoppe_cadre && onstoppe_texte != 3) // dans ce cas, on arrete le défilement.
		{
			initialisation_etat[indice]= onstoppe_cadre; // l'état est définitif
		}
	else //dans ce cas on relance la fonction
		{
			if (initialisation_etat[indice] == 3)
				{setTimeout("display_ss_menu('"+menu+"',3)", 20);}
			else
				{setTimeout("hide_ss_menu('"+menu+"',2)", 40);}
		}
	
}
// FIN DEPLACEMENT