////////111111////////////////////////////////////////////////////////////////////////
//                                                                            //
//  Menus JavaScript Document Object Model Library                            //
//                                                                            //
////////////////////////////////////////////////////////////////////////////////

//options
var MENU_NAME_SEPARATOR="_";

//objects
var M="";
var T;

//hiding the menu
function hM(i){

	//counter & name of the menu found
	var n;

	//clearing the timeout
	clearTimeout(T);

	//checking for the input
	if(!i){T=setTimeout("hM('"+MENU_NAME_SEPARATOR+"')",111);return(false);}

	//check for a parent
	var p=(i&&i.lastIndexOf(MENU_NAME_SEPARATOR)>0)?i.substring(0,i.lastIndexOf(MENU_NAME_SEPARATOR)):"";

	//looking up for a menu
	while(M&&M.lastIndexOf(MENU_NAME_SEPARATOR)>0){

		//getting the name & object
		n=M;

		//item already opened
		if(i==n){return(true);}

		//parent already opened
		if(p==n){return(false);}

		//fetching the object
		o=gO(MENU_NAME_SEPARATOR+n);

		//found?
		if(o){

			//closing
			hO(o);

		}

		//cleanup
		M=(M&&M.lastIndexOf(MENU_NAME_SEPARATOR)>0)?M.substring(0,M.lastIndexOf(MENU_NAME_SEPARATOR)):"";

	}

	//all menus closed - return true - continue to show menus
	return(false);

}

//display the menu - link from main
function sM(o,u,x,y,p){

	//getting objects - menu and popup - no need to pass the document
	var m=gO(MENU_NAME_SEPARATOR+o.id);

	//hide all open menus except current
	if(hM(o.id)){return(false);}

	//check if both objects found
	if(m){

		//show the menu
		sO(m);
		mT(m,x?x:gPX(o)+5,y?y:u?(gPY(o)-gH(m)+5):(gPY(o)+gH(o)-5));
		mA(m);

		//store the link to the menu id
		if(!p){M=o.id;}

	}

	//go back
	return(false);

}

//display the menu - link from main
function sMN(n,x,y,p){

	//getting objects - menu and popup - no need to pass the document
	var m=gO(MENU_NAME_SEPARATOR+n);

	//check if both objects found
	if(m){

		//show the menu
		sO(m);
		mT(m,x?x:(screen.width-gW(m))/2,y?y:(screen.height-gH(m))/2);
		mA(m);

		//store the link to the menu id
		if(!p){M=n;}

	}

	//go back
	return(false);

}

//display the submenu - link from item
function sP(o,x,y,p){

	//getting objects - menu and popup - no need to pass the document
	var m=gO(MENU_NAME_SEPARATOR+o.id);

	//hide all open menus except current
	if(hM(o.id)){return(false);}

	//check if both objects found
	if(m){

		//show the popup
		sO(m);
		mT(m,x?x:(gPX(o)+gW(o)-5),y?y:(gPY(o)+5));
		mA(m);

		//store the link to the menu id
		if(!p){M=o.id;}

	}

	//go back
	return(false);

}

//display the submenu - link from item
function sPN(n,x,y,p){

	//getting objects - menu and popup - no need to pass the document
	var m=gO(MENU_NAME_SEPARATOR+n);

	//check if both objects found
	if(m){

		//show the popup
		sO(m);
		mT(m,x?x:(screen.width-gW(m))/2,y?y:(screen.height-gH(m))/2-111);
		mA(m);

		//store the link to the menu id
		if(!p){M=n;}

	}

	//go back
	return(false);

}

//updating the item color & cursor
function mC(i,c,e){

	//updating the background color of the item
	i.style.backgroundColor=c;

	//updating the cursor of the item
	//i.style.cursor="hand";

	//go back
	return(false);

}