var menuListener = null;		// Global Variable - Menu Event Listener..
var cTimeout = null;				// Global Variable - Menu Timeout..
var iTimeoutMS = 500;				// Milliseconds to Hide Menu..
var iMenuItemHeight = 18;		// Height of Each Layer..
var hItemSpace = 0;					// Spacer from Each Level (Horizontal Space)
var fstLevelHeight = 12;
var sndLevelHeight = 4;

var oLyChild;
var tmpParentLy;
var oLy;
var aMenu;
var tmpMenu = new Array();
	tmpMenu = [];
var iLoop = new Array();
	iLoop = [];
var oLyTemp = new Array();
	oLyTemp = [];
var iVarLevel = 0;
var canHide = true;

//[xPosition, yPosition, lyWidth];
var oMenu_1;
var oMenu_5;
var oMenu_8;
var xywValues_1 = [0, 22, 180];
var xywValues_5 = [180, 22, 380];
var xywValues_8 = [250, 22, 200];

DynAPI.onLoad = function() {

	menuListener = new EventListener(DynAPI.document)
		menuListener.onmouseout=function(e) {
			var eLy = e.getSource();
				eLy.setBgColor("#FFFFFF");
				for(i=0; i < eLy.children.length; i++)
					eLy.children[i].setVisible(false);
				cTimeout = setTimeout('hideTopMenu()', iTimeoutMS);
					canHide = true;
		}
		menuListener.onmouseover=function(e) {
			clearTimeout(cTimeout);
				canHide = false;
			var eLy = e.getSource();
				eLy.setBgColor("#E2EDF4");
				for(i=0; i < eLy.children.length; i++) {
					eLy.children[i].setVisible(true);
				}
		}
		menuListener.onmousemove=function(e) {
				canHide = false;
			var eLy = e.getSource();
				for(i=0; i < eLy.children.length; i++) {
					eLy.children[i].setVisible(true);
				}
		}

// Building Up Layers..		
		buildLayers();
}


function createMenu(iCode, sIndex, startX, startY, parentLy, masterLayer) {

	hideTopMenu();
	clearTimeout(cTimeout);

		aMenu = eval('aMenu_' + iCode + sIndex);
	
		oLy = new DynLayer();
		oLy.setVisible(false);
		oLy.moveTo(startX, startY);
		oLy.setWidth(aMenu[(aMenu.length -1)]);
		
// Menu Header
			oLyChild = new DynLayer();
			if (masterLayer != null)
				oLyChild.setHTML('<table width="' + aMenu[(aMenu.length -1)] +'" cellpadding="0" cellspacing="0" border="0"><tr><td width="18"><img src="../img/menu_sup_esq.gif" width="18" height="12"></td><td backGround="../img/menu_sup_esq_fundo.gif"><img src="../img/transp.gif" width="1" height="12"></td><td width="22"><img src="../img/menu_sup_dir.gif" width="22" height="12"></td></tr></table>');
			else
				oLyChild.setHTML('<table width="' + aMenu[(aMenu.length -1)] +'" cellpadding="0" cellspacing="0" border="0"><tr><td width="11"><img src="../img/menu2_sup_esq.gif" width="11" height="4"></td><td backGround="../img/menu2_sup_esq_fundo.gif"><img src="../img/transp.gif" width="1" height="4"></td><td width="11"><img src="../img/menu2_sup_dir.gif" width="11" height="4"></td></tr></table>');
			oLyChild.moveTo(0, 0);
			oLy.addChild(oLyChild);
			
		for (i=0; i < (aMenu.length - 1); i++) {
			oLyChild = new DynLayer();
			oLyChild.setBgColor("#FFFFFF");
			oLyChild.setHeight(iMenuItemHeight);
			oLyChild.moveTo(0, ((masterLayer != null) ? fstLevelHeight : sndLevelHeight) + (iMenuItemHeight * i));

			if ( (aMenu[i][1] != null) && (aMenu[i][2] != null)) // Link And SubLevel..
				oLyChild.setHTML('<table width="' + aMenu[(aMenu.length -1)] +'" cellpadding="0" cellspacing="0" border="0"><tr><td width="18"><img name="menuEstrela" src="../img/menu_estrela_preta.gif" width="18" height="18"></td><td width="*" valign="middle" height="' + iMenuItemHeight + '" class="dynaMenu" nowrap><a href="frameInterno.asp?URL=' + aMenu[i][1] + '" target="_top" class="dynaMenuLink">' + aMenu[i][0] + '</a></td><td width="22"><img name="menuSeta" src="../img/menu_seta_lado.gif" width="22" height="18"></td></tr></table>');
			if ( (aMenu[i][1] != null) && (aMenu[i][2] == null)) // Link And Not SubLevel..
				oLyChild.setHTML('<table width="' + aMenu[(aMenu.length -1)] +'" cellpadding="0" cellspacing="0" border="0"><tr><td width="18"><img name="menuEstrela" src="../img/menu_estrela_preta.gif" width="18" height="18"></td><td width="*" valign="middle" height="' + iMenuItemHeight + '" class="dynaMenu" nowrap><a href="frameInterno.asp?URL=' + aMenu[i][1] + '" target="_top" class="dynaMenuLink">' + aMenu[i][0] + '</a></td><td width="22"><img name="menuSeta" src="../img/menu_seta_lado_empty.gif" width="22" height="18"></td></tr></table>');
			if ( (aMenu[i][1] == null) && (aMenu[i][2] != null)) // Not Link And SubLevel..
				oLyChild.setHTML('<table width="' + aMenu[(aMenu.length -1)] +'" cellpadding="0" cellspacing="0" border="0"><tr><td width="18"><img name="menuEstrela" src="../img/menu_estrela_preta.gif" width="18" height="18"></td><td width="*" valign="middle" height="' + iMenuItemHeight + '" class="dynaMenu" nowrap><a href="javascript:void(0);" class="dynaMenuLink">' + aMenu[i][0] + '</a></td><td width="22"><img name="menuSeta" src="../img/menu_seta_lado.gif" width="22" height="18"></td></tr></table>');
			if ( (aMenu[i][1] == null) && (aMenu[i][2] == null)) // Not Link And Not SubLevel..
				oLyChild.setHTML('<table width="' + aMenu[(aMenu.length -1)] +'" cellpadding="0" cellspacing="0" border="0"><tr><td width="18"><img name="menuEstrela" src="../img/menu_estrela_preta.gif" width="18" height="18"></td><td width="*" valign="middle" height="' + iMenuItemHeight + '" class="dynaMenu" nowrap><a href="javascript:void(0);" class="dynaMenuLink">' + aMenu[i][0] + '</a></td><td width="22"><img name="menuSeta" src="../img/menu_seta_lado_empty.gif" width="22" height="18"></td></tr></table>');
				
			oLyChild.addEventListener(menuListener);
			oLy.addChild(oLyChild);
			
			if(aMenu[i][2] != null) {
				iVarLevel++; oLyTemp[iVarLevel] = oLy;  tmpMenu[iVarLevel] = aMenu;  iLoop[iVarLevel] = i;
					createMenu(iCode, (sIndex + '[' + i +'][2]'), (oLyChild.getX() + hItemSpace + aMenu[(aMenu.length - 1)]), 0, oLyChild, null);
				aMenu = tmpMenu[iVarLevel]; i = iLoop[iVarLevel]; oLy = oLyTemp[iVarLevel]; iVarLevel--;
			}
			
			oLyChild = null;
		}
// Menu Footer
			oLyChild = new DynLayer();
			if (masterLayer != null)
				oLyChild.setHTML('<table width="' + aMenu[(aMenu.length -1)] +'" cellpadding="0" cellspacing="0" border="0"><tr><td width="18"><img src="../img/menu_inf_esq.gif" width="18" height="9"></td><td backGround="../img/menu_inf_esq_fundo.gif"><img src="../img/transp.gif" width="1" height="9"></td><td width="22"><img src="../img/menu_inf_dir.gif" width="22" height="9"></td></tr></table>');
			else
				oLyChild.setHTML('<table width="' + aMenu[(aMenu.length -1)] +'" cellpadding="0" cellspacing="0" border="0"><tr><td width="11"><img src="../img/menu2_inf_esq.gif" width="11" height="4"></td><td backGround="../img/menu2_inf_esq_fundo.gif"><img src="../img/transp.gif" width="1" height="4"></td><td width="11"><img src="../img/menu2_inf_dir.gif" width="11" height="4"></td></tr></table>');

			oLyChild.moveTo(0, ((masterLayer != null) ? fstLevelHeight : sndLevelHeight) + (iMenuItemHeight * (aMenu.length - 1)));
			oLy.addChild(oLyChild);
			oLy.removeAllEventListeners();
		
		if (masterLayer != null) {
			oLy.setWidth(masterLayer);
		}
			
		parentLy.addChild(oLy);

		return oLy;
}

function timeoutMenu() {
	cTimeout = setTimeout('hideTopMenu()', iTimeoutMS);
}

function hideTopMenu() {
 if (canHide)
	for (i=0; i < DynAPI.document.children.length; i++)
		DynAPI.document.children[i].setVisible(false);

}

function showMenu(oLayer) {
	clearTimeout(cTimeout);
		canHide = true;
	hideTopMenu();
		oLayer.setVisible(true);
}
