/* #####################################
FLMenu v.01
by Nuno Albuquerque

javascript revision by P.Sousa
######################################*/

/* :::::::::::::::::::::::::::::::::::::
Global Variables
::::::::::::::::::::::::::::::::::::::*/
var s1 = String.fromCharCode(2);
var s2 = String.fromCharCode(3);
var MenuObj = "";
var isIE = document.all?true:false;

//All Possible Menu Items
var MenuItems = new Array();
MenuItems[0] = ["@seperator@","",""];

/* :::::::::::::::::::::::::::::::::::::
init Function
::::::::::::::::::::::::::::::::::::::*/
window.onload = menuInit;
function menuInit(){
	MenuObj = document.getElementById("menuLayer");
	MenuObj.data = "";
}//func \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\

/* :::::::::::::::::::::::::::::::::::::
Menu Function
::::::::::::::::::::::::::::::::::::::*/	
//Get the XY Cord of the Mouse event
function getMouseXY(e){
	var rtn = new Object();
	//Get the Cords depending on the browser, and incase of negatives reset to zero.
	if(isIE){//IE
		rtn.x = Math.max(event.clientX + document.body.scrollLeft,0);
		rtn.y = Math.max(event.clientY + document.body.scrollTop,0);
	}else{//Mozilla+Safari
		rtn.x = Math.max(e.pageX,0);
		rtn.y = Math.max(e.pageY,0);
	}//if
	return rtn;
}//func \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\

//Resize the Menu Layer
function setLayerSize(h,w){
	MenuObj.style.height=h;
	MenuObj.style.width=w;
}//func \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\

//Display Menu
function showMenu(e,ary,arg){
	// Clear TimeOut if it's active
	stopDelayMenu();
	
	//Prepare for display Menu
	m = getMouseXY(e);
	menuStr = MkMenuString(ary,arg);
	
	//Set the Menu Layer Properties		
	MenuObj.style.display = "";
	MenuObj.style.left = m.x-5;
	MenuObj.style.top = m.y-5;
	
	//Rewrite the FlashStuff
	if(isIE){//IE
		MenuObj.innerHTML = '<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,0,0" width="100%" height="100%" id="menu" align="middle"><param name="allowScriptAccess" value="sameDomain"/><param name="movie" value="/global/media/menu.swf"/><param name="menu" value="false"/><param name="quality" value="high"/><param name="scale" value="noscale"/><param name="salign" value="lt"/><param name="wmode" value="transparent"/><param name="bgcolor" value="#990000"/><param name="flashVars" value="menu=' + menuStr + '"/></object>';
	}else{//Mozilla+Safari
		MenuObj.innerHTML = '<embed src="/global/media/menu.swf" width="100%" height="100%" align="middle" menu="false" quality="high" scale="noscale" salign="lt" wmode="transparent" bgcolor="#990000" name="menu" allowScriptAccess="sameDomain" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" flashVars="menu=' + menuStr + '"/>';
	}//if
	return false;
}//func \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\

//Construct how the Menu is ment to be displayed
function MkMenuString(ary,arg){
	var rtn = "";
	
	//Compile the String
	for(x in ary){
		if(rtn != "") rtn += s2;
		rtn += MenuItems[ary[x]][0] + s1 + MenuItems[ary[x]][1] + s1 + MenuItems[ary[x]][2];
	}//for
	
	//Replace all the Variable PlaceHolders
	if(arg != ""){
		for(y in arg){
			do{//Keep replace all placeholders
				rtn = rtn.replace("#" + y + "#",arg[y]);
			}while(rtn.indexOf("#" + y + "#") > -1);
		}//for
	}//if				
	return rtn;
}//func \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
		
//hide layer
function hideMenu(){
	MenuObj.data = setTimeout("hideMenuDelay()", 500);
	//MenuObj.style.display = "none";
	//return false;
}//func \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\

//hide layer delay
function hideMenuDelay(){
	MenuObj.style.display = "none";
	stopDelayMenu();
	return false;
}//func \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\

function stopDelayMenu(){
	clearTimeout(MenuObj.data);
}//func