/***********************************************************
*	Gestion du menu (haut de page)
***********************************************************/
function menu() {
	this.items				=	new Array();
	this.itemCount			=	0;
	this.divName			=	"menu";
	this.drawAfterUpdate	=	true;

	this.addItem			=	addItem;
	this.addItemCmd			=	addItemCmd;
	this.draw				=	drawMenu;
	this.disableMenu		=	disableMenu
	this.enableMenu			=	enableMenu;
	this.changeItemState	=	changeItemState;
	this.getItemState		=	getItemState;
	this.updateMenu			=	updateMenu;
	this.addItemList		=	addItemList;
	this.addItemListCmd		=	addItemListCmd;
	this.addSeparator		=	addSeparator;
	this.hide				=	hide;
	this.show				=	show;
	this.setDrawAfterUpdate	=	setDrawAfterUpdate;
	this.base				=	"./";
	this.scroll				=	scroll;
	this.top				=	0;
	this.showEditoLogo		=	true;
	
	function scroll(){
		//alert(document.body.scrollTop);
		//alert(this.divName);
		//alert(document.getElementById("menu").style.top);
		document.getElementById(this.divName).style.top		=	document.body.scrollTop + this.top + "px";
		return false;
	}
	
	function hide() {
		document.getElementById(this.divName).style.display = "none";
	}
	
	function show() {
		document.getElementById(this.divName).style.display = "";
	}
	
	// E-dito 1.1 : ajout de commandName pour pouvoir selectionner les elements en cours sur la selection 
	function addItemCmd(name, imageOn, imageOff, methode, desc,state,commandName) {
		this.items[this.itemCount] = new menuItem(name,imageOn, imageOff, methode, desc, state,this,commandName);
		this.itemCount++;
	}

	// E-dito 1.1 : ajout de commandName pour pouvoir selectionner les elements en cours sur la selection 
	function addItemListCmd(name, methode, desc,state, width, items,commandName) {
		this.items[this.itemCount] = new menuItemList(name, methode, desc, state, width, items,this,commandName);
		this.itemCount++;	
	}
	
	function addItem(name, imageOn, imageOff, methode, desc,state) {
		this.addItemCmd(name, imageOn, imageOff, methode, desc,state,"");
	}

	function addItemList(name, methode, desc,state, width, items) {
		this.addItemListCmd(name, methode, desc,state, width, items,"");
	}

	function addSeparator() {
		this.items[this.itemCount] = "separator";
		this.itemCount++;
	}
	
	function disableMenu() {
		for (i = 0; i < this.itemCount; i++) {
			if (this.items[i] == "separator") {
			} else if (this.items[i].type == "item"){
				document.images[this.items[i].name].style.cursor="default";
				document.images[this.items[i].name].filters.alpha.opacity=25;
				document.images[this.items[i].name].onmouseover="";
				document.images[this.items[i].name].onmouseout="";
				document.images[this.items[i].name].className="topMenu";
				this.items[i].active=false;
				document.images[this.items[i].name].active="false";
			} else {
				document.getElementById(this.items[i].name).disabled = true;
				this.items[i].active=false;
			}
		}
	}

	function enableMenu() {
		for (i = 0; i < this.itemCount; i++) {
			if (this.items[i] == "separator") {
			} else if (this.items[i].type == "item"){
				document.images[this.items[i].name].style.cursor="hand";
				document.images[this.items[i].name].filters.alpha.opacity=100;
				document.images[this.items[i].name].onmouseover=function anonymous() {this.className="topMenuOver"};
				document.images[this.items[i].name].onmouseout=function anonymous() {this.className="topMenu"};
				this.items[i].active=true;
				document.images[this.items[i].name].active="true";
			} else {
				document.getElementById(this.items[i].name).disabled = false;
				this.items[i].active=true;
				//alert("document.getElementByID(this.items[i].name).onChange=	" + this.items[i].action + "(this.value)");
				//eval("document.getElementByID(this.items[i].name).onChange=	" + this.items[i].action + "(this.value);");
				//document.getElementById(this.items[i].name).options[0].selected=true;
			}
		}
	}

	// e-dito 1.1.3 - 15/06/2006 - forcer l'alignement a gauche dans le menu
	function drawMenu() {
		content			=	"<TABLE BORDER='0' CELLSPACING='0' CELLPADDING='0' WIDTH='100%' HEIGHT='25px'><TR HEIGHT='25px'>";
		content			+=	"<TD CLASS='topMenuBg' WIDTH='13px'><SPAN class='separator' BORDER=0 CELLSPACING=0 CELLPADDING=0>&nbsp;</SPAN></TD>";
		content			+=	"<TD CLASS='topMenuBg' VALIGN='center' style='text-align:left;'>";
		for (i = 0; i < this.itemCount; i++) {
			// Image Item else List Item
			if (this.items[i] == "separator")
				content	+=	"<SPAN class='separator' BORDER=0 CELLSPACING=0 CELLPADDING=0>&nbsp;</SPAN>";
			else {
				if (this.items[i].type == "item"){
					content	+=     "<IMG SRC='" + this.items[i].image_on.src + "' CLASS='topMenu' HSPACE='0' TITLE='" + this.items[i].description + "' NAME='" + this.items[i].name + "' HEIGHT='21px' WIDTH='21px' onMouseOver='this.className=\"topMenuOver\"' onMouseOut='this.className=\"topMenu\"' active='true' onMouseDown='if (this.className != \"topMenu\") " + this.items[i].action + ";' STYLE='cursor:hand;cursor: pointer;filter:alpha(opacity=100)' ALIGN='absmiddle'/>";
				} else {
					content	+=	"</TD><TD VALIGN='center' CLASS='topMenuBg' WIDTH='" + this.items[i].width + "px' style='text-align:left;'><SELECT NAME='" + this.items[i].name + "' ID='" + this.items[i].name + "' TITLE='" + this.items[i].description + "' CLASS='topMenuList' STYLE='width:" + this.items[i].width + ";' onChange='" + this.items[i].action + "(this.value);this.options[0].selected=true;'>" + this.items[i].items + "</SELECT></TD><TD VALIGN='center' CLASS='topMenuBg' style='text-align:left;'>";
				}
			}
		}
		content			+=	"</TD>";
		if (this.showEditoLogo)
				content		+=	"<TD VALIGN='center' CLASS='topMenuBg' STYLE='text-align:right;'><A HREF='http://www.e-dito.net' TARGET='_blank'><IMG SRC='" + this.base + "images/E.gif' BORDER='0' ALT='E-dito : création de sites Internet dynamiques' HEIGHT='21px' WIDTH='73px' STYLE='margin:0px;border:0px;margin-right:20px;'></A></TD>";
		content			+=	"</TR></TABLE>";
		document.getElementById(this.divName).innerHTML	=	content;
		
	}

	function updateMenu() {
		for (i = 0; i < this.itemCount; i++) {
			if (this.items[i] == "separator") {
			} else if (this.items[i].type == "item"){
				if (this.items[i].active) {
					document.images[this.items[i].name].style.cursor="hand";
					document.images[this.items[i].name].filters.alpha.opacity=100;
					document.images[this.items[i].name].onmouseover=function anonymous() {this.className="topMenuOver"};
					document.images[this.items[i].name].onmouseout=function anonymous() {this.className="topMenu"};
					document.images[this.items[i].name].active="true";
				} else {
					document.images[this.items[i].name].style.cursor="default";
					document.images[this.items[i].name].filters.alpha.opacity=25;
					document.images[this.items[i].name].onmouseover="";
					document.images[this.items[i].name].onmouseout="";
					document.images[this.items[i].name].className="topMenu";
					document.images[this.items[i].name].active="false";
				}
			} else {
				if (this.items[i].active) {
					document.getElementById(this.items[i].name).disabled = false;
				} else {
					document.getElementById(this.items[i].name).disabled = true;
				}
			}
		}
	}
	
	function changeItemState(nom, state) {
		for (i = 0; i < this.itemCount; i++) {
			if (this.items[i].name == nom) {
				this.items[i].active	= state;

				/*if (this.items[i].type != "separator") {
					if (state) {
						document.images[this.items[i].name].active="true";
					} else {
						document.images[this.items[i].name].active="false";
					}
				}*/
			}
		}
		if (this.drawAfterUpdate)
			this.updateMenu();
	}

	function getItemState(nom) {
		for (i = 0; i < this.itemCount; i++) {
			if (this.items[i].name == nom)
				return this.items[i].active;
		}
	}
	
	function setDrawAfterUpdate(v) {
		this.drawAfterUpdate	= v;
	}
}

// Chaque Item du menu
function menuItem(n,io,iof,m,d,s,tm,cmd) {
	this.name			=	n;
	this.image_on		=	new Image(); 
	this.image_on.src	=	tm.base + "images/" + io;
	this.image_off		=	new Image();
	this.image_off.src	=	tm.base + "images/"+ iof;
	this.action			=	m;
	this.description	=	d;
	this.active			=	s;
	this.type			=	"item";
	this.commandName	=	cmd;

	if (this.action.indexOf("(") < 0)
		this.action	+=	"()";
	
	if (this.action.indexOf(";'") == 0) {
		this.action	=	this.action.substring(16);
	}
}

// Chaque Item de format liste du menu
function menuItemList(n,m,d,s,w,i,parent,cmd) {
	this.name			=	n;
	this.action			=	m;				// onChange
	this.description	=	d;
	this.active			=	s;
	this.width			=	w;
	this.items			=	i;
	this.type			=	"list";
	this.commandName	=	cmd;
}


	

