___GS_MENUS 		= new Array();
___GsMnEdit_Hover 	= new Array();
var ___GsMnEdit_Current, ___GsMnEdit_Popup, ___GsMnEdit_PopupTimeout;

function GsMenu(id) {
	this.id 			= id;
	this.levels 		= new Array();
	this.level 			= 0;
	this.type 			= '';
	this.caption 		= '';
	this.urlImgCap 		= '';
	this.urlImgCapFb 	= '';
	this.urlImgCapDa 	= '';
	this.urlImgEx 		= new Array();
	this.urlGlyph 		= '';
	this.absoluteHref 	= '';
	this.Items 			= new Array();
	this.enabled 		= false;
	this.hasChildren 	= false;
	this.lastItem;
	this.sequences		= new Array();
	this.sequence		= '';
	this.lL				= 0;
	this.uL				= null;
	this.handler 		= null;
	this.hdlObjId 		= null;
	this.parent 		= null;
	this.__obj			= null;
	
	// Instance ----------------------
	this.open 			= false;
	this.sequences['']	= this;
	}

GsMenu.prototype.handleWith = function (hdl, objId, lL, uL) {
	if (lL) minL = lL; else minL = this.level;
	if (uL) maxL = uL; else maxL = this.levels.length;
	for (i=minL; i<maxL; i++) {
		for (j=0; j<this.levels[i].length; j++) {
			this.levels[i][j].handler = hdl;
			this.levels[i][j].hdlObjId = objId;
			}
		}
	}
	
GsMenu.prototype.newItem = function (caption, href, glyph, img, imgFb, imgDisabled, enabled) {
	nI = new GsMenu();
	nI.levels			= this.levels;
	nI.urlImgEx			= this.urlImgEx;
	nI.sequences		= this.sequences;
	nI.handler			= this.handler;
	nI.hdlObjId			= this.hdlObjId;
	nI.level 			= this.level + 1;
	nI.caption 			= caption;
	nI.absoluteHref 	= href;
	nI.urlGlyph 		= glyph;
	nI.urlImgCap 		= img;
	nI.urlImgCapFb 		= imgFb;
	nI.urlImgCapDa 		= imgDisabled;
	nI.parent			= this;
	if (enabled) nI.enabled = enabled; else nI.enabled = true;
	if (this.sequence != '') nI.sequence = this.sequence + '-';
	nI.sequence += this.Items.length;
	this.Items.push(nI);
	this.hasChildren	= true;
	this.lastItem 		= this.Items[this.Items.length - 1];
	this.sequences[nI.sequence] = this.lastItem;
	if (!this.levels[this.level]) this.levels[this.level] = new Array();
	this.levels[this.level].push(this.Items[this.Items.length - 1]);
	return this.lastItem;
	}

GsMenu.prototype.newSeparator = function () {
	nI = new GsMenu();
	nI.sequences		= this.sequences;
	nI.level 			= this.level + 1;
	nI.type				= 'SEP';
	nI.enabled			= true;
	if (this.sequence != '') nI.sequence = this.sequence + '-';
	nI.sequence += this.Items.length;
	this.Items.push(nI);
	this.hasChildren 	= true;
	this.lastItem 		= this.Items[this.Items.length - 1];
	this.sequences[nI.sequence] = this.lastItem;
	return this.lastItem;
	}

var GsMnPnl, GsMnHv, GsMnFHdl, GsMnTo;

function GsMenu_Blur() {
	if (GsMnPnl) {
		var gsmpp = GsMnPnl.parentNode;
		gsmpp.removeChild(GsMnPnl);
		GsMnPnl = null;
		}
	}
function GsMenu_ClosePopup () {
	if (___GsMnEdit_Popup && !___GsMnEdit_Popup.hover) {
		___GsMnEdit_Popup.parentNode.removeChild(___GsMnEdit_Popup);
		}
	if (___GsMnEdit_PopupTimeout) clearTimeout(___GsMnEdit_PopupTimeout);
	}
function GsMenu_EditHover(obj, seq, gsmObj) {
	var gsBrowser = parent.document.getElementById("CMSBrowser");
	if (gsBrowser) {
		if (___GsMnEdit_Current) {
			GsMenu_EditDeleteLink(___GsMnEdit_Current);
			GsMenu_ClosePopup ();
			}
		objPos = Blacksmith.objPos(obj);
		dd 	= document.createElement("div");
		dd.id 				= 'GsMnAdm_Link_' + seq;
		dd.className 		= 'GsMnAdm_EditLink';
		dd.style.position	= 'absolute';
		dd.style.left		= objPos[0] + obj.offsetWidth + 'px';
		dd.style.top		= objPos[1] + 'px';
		dd.style.height		= obj.offsetHeight + 'px';
		dd.style.zIndex		= 1050;
		dd.onclick = function() {
			GsMenu_ClosePopup();
			icoPos = Blacksmith.objPos(this);
			gsmPopup = document.createElement("div");
			gsmPopup.className 		= 'GsMnAdm_Popup';
			gsmPopup.style.position	= 'absolute';
			gsmPopup.style.left		= Blacksmith.mouseX + 'px';
			gsmPopup.style.top  	= Blacksmith.mouseY + 'px';
			gsmPopup.style.zIndex 	= 1051;
			document.body.appendChild(gsmPopup);
			___GsMnEdit_Popup = gsmPopup;
			___GsMnEdit_Popup.hover = false;
			ulObj = document.createElement("ul");
			gsmPopup.appendChild(ulObj);
			liObj = new Array(); aObj = new Array();
			for (i=0; i<3; i++) {
				liObj[i] = document.createElement("li");
				liObj[i].id = 'icon'+(i+1);
				ulObj.appendChild(liObj[i]);
				liObj[i].onmouseover = function() {
					___GsMnEdit_Popup.hover = true;
					}
				liObj[i].onmouseout = function() {
					___GsMnEdit_Popup.hover = false;
					___GsMnEdit_PopupTimeout = setTimeout("GsMenu_ClosePopup();", 2000);
					}
				}
			liObj[0].innerHTML = ____Menu_TR['linkEdit'];
			liObj[1].innerHTML = ____Menu_TR['linkNewBefore'];
			liObj[2].innerHTML = ____Menu_TR['linkNewAfter'];
			liObj[0].onclick = function() {
				Blacksmith.openControl('Menu', 'edit', '&action=edit&id=' + gsmObj.id + '&seq=' + obj.name, null, 700, 500);
				}
			liObj[1].onclick = function() {
				Blacksmith.openControl('Menu', 'edit', '&action=before&id=' + gsmObj.id + '&seq=' + obj.name, null, 700, 500);
				}
			liObj[2].onclick = function() {
				Blacksmith.openControl('Menu', 'edit', '&action=after&id=' + gsmObj.id + '&seq=' + obj.name, null, 700, 500);
				}
			}
		___GsMnEdit_Hover[seq] = false;
		dd.onmouseover = function () {
			___GsMnEdit_Hover[seq] = true;
			}
		dd.onmouseout = function () {
			___GsMnEdit_Hover[seq] = false;
			}
		___GsMnEdit_Current = seq;
		document.body.appendChild(dd);
		___GsMnEdit_PopupTimeout = setTimeout("GsMenu_ClosePopup();", 2000);
		}
	}
function GsMenu_EditDeleteLink(seq) {
	//alert('del : ' + seq);
	var gsm_editL = document.getElementById('GsMnAdm_Link_' + seq);
	if (gsm_editL) {
		if (!___GsMnEdit_Hover[seq]) gsm_editL.parentNode.removeChild(gsm_editL);
		else setTimeout("GsMenu_EditDeleteLink('"+seq+"')", 1000);
		}
	}
	
function GsMenu_EditHoverOut(obj, seq, mnName) {
	var gsBrowser = parent.document.getElementById("CMSBrowser");
	if (gsBrowser) {
		setTimeout("GsMenu_EditDeleteLink('"+seq+"')", 1000);
		//___GsMnEditItems[seq] = 
		/*var gsm_editL = document.getElementById('GsMnAdm_Link_' + seq);
		if (gsm_editL) {
			gsm_editL.parentNode.removeChild(gsm_editL);
			}*/
		}
	//setTimeout(GsMenu_EditDeleteLink(obj, seq), 10000);
	}
	
function GsMenu_Edit(ctobj, sInfStr) {
	var gsBrowser = parent.document.getElementById("CMSBrowser");
	if (gsBrowser) {
		/*GsMenu_Blur();
		if (!GsMnHv) {
			for (i=0; i<ctobj.childNodes.length; i++) if (ctobj.childNodes[i].tagName=='DIV') obj=ctobj.childNodes[i];
			mnPos 				= Blacksmith.objPos(obj);
			mnlk 				= document.createElement("div");
			mnlk.style.position = 'absolute';
			mnlk.style.left 	= mnPos[0]+'px';
			mnlk.style.top 		= mnPos[1]+'px';
			mnlk.style.width 	= obj.offsetWidth+'px';
			mnlk.style.height 	= obj.offsetHeight+'px';
			mnlk.style.zIndex 	= 990;
			mnlk.className		= 'GsMnAdm_MnLayer';
			mnlk.innerHTML		= '<div style="margin-top:7px;" align="center"><b>Cliquer pour éditer ou patienter 2 secondes pour naviguer</b></div>';
			document.body.appendChild(mnlk);
			
			mnlk.oncontextmenu = function () {
				}
				
			mnlk.onclick = function () {
				mnlk.style.cursor = 'wait';
				var top = (screen.height-600)/2;
				var left = (screen.width-900)/2;
				window.open(GS_PATH['COMPONENTS']['URL']+'/Menu/controls/edit.control.php?source=gsmenu',"MenuEdition","top="+top+",left="+left+",width="+900+",height="+600+", toolbar=no, status=yes, scrollbars=no, resizable=yes, directories=no, menubar=no, location=no");
				}
			
			GsMnPnl = mnlk;
			GsMnHv	= true;
			
			if (!GsMnFHdl) GsMnFHdl = new Array();
			if (!GsMnFHdl[obj.id]) GsMnFHdl[obj.id] = Blacksmith.onMouseOver(function (params) {
				obj 	= params[0];
				mnPos 	= params[1];
				if (Blacksmith.mouseX < mnPos[0] 
					|| Blacksmith.mouseX > (mnPos[0]+parseInt(obj.offsetWidth))
					|| Blacksmith.mouseY < mnPos[1]
					|| Blacksmith.mouseY > (mnPos[1]+parseInt(obj.offsetHeight))) {
						Blacksmith.disableMouseOver(GsMnFHdl[obj.id]);
						clearTimeout(GsMnTo);
						GsMenu_Blur();
						GsMnHv=false;
						}
				}, [obj, mnPos]);
			else Blacksmith.enableMouseOver(GsMnFHdl[obj.id]);
			GsMnTo = setTimeout("GsMenu_Blur();", 1500);
			}*/
		}
	}
	
//GsMenu = new GsMenu();
