

// -= Variables globales =-
//==========================
var Interval = 50;
var SumInt = 0;
var imgOButton = "common/images/menu/OButton.gif";
var imgFButton = "common/images/menu/FButton.gif";

var PosXStart = 0;
var PosYStart = 0;
var intSepar = 20;
var bFader = false;

var strFader = "filter: alpha(opacity=0);";

var arrListMenu = new Array();

// -= Fonctions =-
//=================
function DoNothing() {}

function StartMenu(){
	for( var i = 0; i < arrListMenu.length; i++ )  fctWrite(i);	
}

function InitMenu( StartX, StartY, Separ, Fader ){
	PosXStart = StartX;
	PosYStart = StartY;
	intSepar = Separ;
	bFader = Fader;
}

function getObject( id ){
	for( var Cpt = 0; Cpt < arrListMenu.length; Cpt++ ){
	 	if( id == arrListMenu[Cpt].Name ) return arrListMenu[Cpt];
		for( var Cpt2 = 0; Cpt2 < arrListMenu[Cpt].Option.length; Cpt2++ ){
	 		if( id == arrListMenu[Cpt].Option[Cpt2].Name ) return arrListMenu[Cpt].Option[Cpt2];
		}
	}
}

function fctMove( strObj, intTo, intVitesse ){
	// But:		Bouger le menu de sa position 'Y' actuelle vers la position 'Y' "intTo".
	// Event:	/
	// Param.:	- Index = Numéro du menu. 
	//			- intTo = Position 'Y' finale du menu ou de l'option.
	//			- intVitesse = Vitesse de mouvement.
	
	var Obj = getObject( strObj );
	
	if( parseInt(intTo) != Obj.PosY ){
		if( parseInt(intTo) < Obj.PosY ){
			Obj.PosY -= 5 * intVitesse;
			if( Obj.PosY <= parseInt(intTo) ) Obj.PosY = parseInt(intTo);
		}
		else {
			Obj.PosY += 5 * intVitesse;
			if( Obj.PosY >= parseInt(intTo) ) Obj.PosY = parseInt(intTo);
		}
		document.getElementById( Obj.Name ).style.top = Obj.PosY;
		setTimeout("fctMove('" + Obj.Name + "', " + intTo + ", " + intVitesse + ")", Interval);
	}
}

function fctMoveFix( strObj, intTo, intVitesse ){
	// But:		Amene directement a la position Y
	// Event:	/
	// Param.:	- Index = Numéro du menu. 
	//			- intTo = Position 'Y' finale du menu ou de l'option.
	//			- intVitesse = Vitesse de mouvement.
	
	var Obj = getObject( strObj );
	
	if( parseInt(intTo) != Obj.PosY ){
		if( parseInt(intTo) < Obj.PosY ){
			Obj.PosY -= 5 * intVitesse;
			if( Obj.PosY <= parseInt(intTo) ) Obj.PosY = parseInt(intTo);
		}
		else {
			Obj.PosY += 5 * intVitesse;
			if( Obj.PosY >= parseInt(intTo) ) Obj.PosY = parseInt(intTo);
		}
		document.getElementById( Obj.Name ).style.top = Obj.PosY;
		fctMoveFix(Obj.Name, intTo, intVitesse);
	}
}

function fctAnim( Index ){
	// But:		Animation du menu
	// Event:	Qd on clique sur l'en-tête du menu.
	// Param.:	- Index = Numéro du menu.
	
	var Menu = arrListMenu[Index];
	
	var To = 0;
	var intCpt = 0;
	var http;
	
	if( !Menu.isShowed ){
		document.getElementById( "img_" + Menu.Name ).src = "common/images/menu/FButton.gif";
		if( bFader ) fctSetOpacity(Index, "+");
		else document.getElementById( Menu.OptionName ).style.display = "";
		if (Menu.opened == false){
			for( intCpt = 0; intCpt < Menu.Option.length; intCpt++){
				fctMove(Menu.Option[intCpt].Name, 0, intCpt);
				To += 20;
			}
			for( intCpt = Menu.Index + 1; intCpt < arrListMenu.length; intCpt++ ){
				fctMove(arrListMenu[intCpt].Name, To + arrListMenu[intCpt].PosY, Menu.Option.length + 1 );
			}
		}else{
			for( intCpt = 0; intCpt < Menu.Option.length; intCpt++){
				fctMoveFix(Menu.Option[intCpt].Name, 0, intCpt);
				To += 20;
			}
			for( intCpt = Menu.Index + 1; intCpt < arrListMenu.length; intCpt++ ){
				fctMoveFix(arrListMenu[intCpt].Name, To + arrListMenu[intCpt].PosY, Menu.Option.length + 1 );
			}
		}
		
		// MAJ de la variable de session
		url = "common/ajax/req_menu.asp?menu=" + Menu.Name + "&etat=1";
		http = createRequestObject();
		http.open('get', url, true);
		http.send(null);
		
		Menu.opened = true;
		Menu.isShowed = true;
	}
	else {
		document.getElementById( "img_" + Menu.Name ).src = "common/images/menu/OButton.gif";
		if( bFader ) fctSetOpacity(Index, "-");
		for( intCpt = 0; intCpt < Menu.Option.length; intCpt++){
			fctMove(Menu.Option[intCpt].Name,-30*(intCpt), intCpt + 1);
			To += 20;
			SumInt += Interval/2;
		}
		for( intCpt = Index + 1; intCpt < arrListMenu.length; intCpt++ ){
			fctMove(arrListMenu[intCpt].Name, arrListMenu[intCpt].PosY - To, Menu.Option.length + 1 );
			SumInt += Interval/2;
		}
		
		// MAJ de la variable de session
		url = "common/ajax/req_menu.asp?menu=" + Menu.Name + "&etat=0";
		http = createRequestObject();
		http.open('get', url, true);
		http.send(null);
		
		
		Menu.opened = false;
		Menu.isShowed = false;
		if( !bFader ) setTimeout("document.getElementById('" + Menu.OptionName + "').style.display = 'none'", SumInt);
		SumInt = 0;
	}
}

function fctSetOpacity( Index, strOp ){
	// But:		Initialisé l'opacité du menu.
	// Event:	/
	// Param.:	- Index = Numéro du menu.
	//			- strOp = Opération à effectuer sur l'opcaté du menu
	
	var Menu = arrListMenu[Index];
	
	if( Menu.Opac <= 101 && Menu.Opac >= -1 ){
		if( strOp == "+" ){
			Menu.Opac = Menu.Opac + 20;	
		}
		else {
			Menu.Opac = Menu.Opac - 20;
		}
		for( var i = 0; i < Menu.Option.length; i++ ) document.getElementById( Menu.Option[i].Name).filters.alpha.opacity = Menu.Opac;
		document.getElementById( Menu.OptionName).style.display = "";
		setTimeout("fctSetOpacity(" + Index + ", '" + strOp + "')", Interval);
	}
	else {


		if( strOp == "+" ){
			Menu.Opac = 100;	
		}
		else {
			Menu.Opac = 0;
			document.getElementById( Menu.OptionName).style.display = "none";
		}
		for( var i = 0; i < Menu.Option.length; i++ ) document.getElementById( Menu.Option[i].Name ).filters.alpha.opacity = Menu.Opac;
	}
}

function fctWrite( Index ){
	// But:		Ecriture du menu dans le browser.
	// Event:	/
	var strRBorder = "solid";
	var strLBorder = "solid";
	var strBBorder = "none";
	var strReturn = "";
	
	var Menu = arrListMenu[Index];
	
strReturn += "<table border='0' width='193px' summary='' cellpadding = '0' cellspacing = '0' style='Position:absolute;top:" + Menu.PosY + ";left:" + Menu.PosX + ";' id = '" + Menu.Name + "'>"
strReturn += "<tr style='z-index:1;'><td><table border='0' summary='' cellpadding = '0' cellspacing = '0'><tr onClick = \"fctAnim(" + Index + ")\" class='menu_head_tr'>";
strReturn += "<td height = '25' width = '5'><img src='common/images/menu/LBorder.gif' border='0' width='5' height='25' alt=''></td>";
//strReturn += "<td><img src='scripts/" + Menu.Image + "' border='0' width='52' height='52' align='right'></td>";
strReturn += "<td height = '25' width = '161' class='menu_head'>" + Menu.Caption + "</td>";
strReturn += "<td><img id='img_" + Menu.Name + "' src='common/images/menu/OButton.gif' border='0' width='22' height='25'></td>";
strReturn += "<td height = '25' width = '5'><img src='common/images/menu/RBorder.gif' border='0' width='5' height='25'></td>";
strReturn += "</tr></table></td></tr><tr><td>";
strReturn += "<table border='0' width='100%' cellpadding='0' cellspacing='0'  id='" + Menu.OptionName + "' style=';z-index:0;display: none'>";

for( var intCpt = 0; intCpt < Menu.Option.length; intCpt++ ){
	if( Menu.Option.length-1 == intCpt ){
		strBBorder = "solid";
	}
	strReturn += "<tr id='" + Menu.Option[intCpt].Name + "' style='position: relative; top:" + Menu.Option[intCpt].PosY + "; left:" + Menu.Option[intCpt].PosX + ";z-index: 0;" + ((bFader)? strFader : "")  + "'>";
	strReturn += "<td height = '16' width = '1%' style = 'border-style: none none " + strBBorder + " " + strLBorder + "; border-color: #666666; border-width: 1; color: #666666; background: #FFFFFF;'>&nbsp;</td>";
	strReturn += "<td height = '16' width = '1%' style = 'border-style: none none " + strBBorder + " none; border-color: #666666; border-width: 1; color: #666666; background: #FFFFFF;'><img src='" + Menu.Option[intCpt].Image + "' border='0' width='16' height='16' align='left'></td>";
	strReturn += "<td height = '16' class='ss_menu_link' style = 'border-style: none none " + strBBorder + " none;'><a href = '" + Menu.Option[intCpt].Links + Menu.Option[intCpt].Param + "' > " + Menu.Option[intCpt].Caption + " </a></td>";
	strReturn += "<td height = '16' width = '1%' style = 'border-style: none " + strRBorder + " " + strBBorder + " none; border-color: #666666; border-width: 1; color: #E6F6F2; background: #FFFFFF;'>&nbsp;</td>";
}
strReturn += "</tr></Table></td></tr></table>";
document.write( strReturn );
}

function fctCreateOption( strName, strTitre, strHref, strParam, strTarget, strImage){
	this.Option[this.Option.length] = new OptionObject(strName, strTitre, strHref, strParam, strTarget, strImage, 0, -30*(this.Option.length));
}


// -= Objet "Menu" =-
//====================
function MenuObject( strMenuName, /*strImage, strImageName,*/ strTitre, intPosX, intPosY ){
	this.Name = strMenuName;
	//this.Image = strImage;
	//this.ImageName = strImageName;
	this.Caption = "<font face=Tahoma color=#666666><b><span style='font-size: 8pt'>" + strTitre + "</span></b></font>";
	this.PosX = PosXStart;
	this.PosY = PosYStart + arrListMenu.length * (35 + intSepar);
	this.OptionName = strMenuName + "Option";
	
	this.Opac = 0;
	this.Index = arrListMenu.length;
	arrListMenu[arrListMenu.length] = this;
	this.Option = new Array();
	this.isShowed = false;
	this.opened = false;
	this.CreateOption = fctCreateOption;
	this.ShowMenu = fctShowMenu;
	
}

function fctShowMenu(){
	this.opened = true;
	fctAnim(this.Index);	
}

// -= Objet "Option " =-
//======================
function OptionObject( strName, strTitre, strHref, strParam, strTarget, strImage, intPosX, intPosY){
	this.PosX = intPosX;
	this.PosY = intPosY;
	this.Name = strName;
	this.Image = strImage;
	this.Caption = "<font face=tahoma color=#666666><span style='font-size: 8pt'>" + strTitre + "</span></font>";
	this.Param = strParam;
	this.Target = strTarget;
	this.Links = strHref;
}