var menuTop = 45;		//top edge of dropdown menu
var menuLeft = 400;		//left edge of dropdown menu (to be reassigned later)

var domSMenu = null;		//menu DOM
var oldDomSMenu = null; 	//DOM for last menu opened
var t = 0;			//a flag for whether the menu is waiting to be closed (1) or opened (2)
var lDelay = 4;			//records how long a window should wait before opening
var lCount = 0;			//keeps track of how long the window has been been open
				//when lCount = lDelay, the window closes
var pause = 100;			

/* This function closes any other menus that are open, then
calculates the left and bottom edge of the menu header, placing 
appropriate dropdown menu in that position and making it visible */

function popMenu(menuNum){
	if (isDHTML) {
///// Sets the previous menu's visibility to hidden
		t = 2;
		if (oldDomSMenu) {
			oldDomSMenu.visibility = 'hidden'; 
			oldDomSMenu.zIndex = '0'; 
			t = 2; 
			lCount = 0;
		}

///// Defines the DOMs	of the menu objects
		var idMenu = 'menuHead';
		var domMenu = findDOM(idMenu,0);

		var idMenuOpt = 'menuHead' + menuNum;
		var domMenuOpt = findDOM(idMenuOpt,0);		

		var idSMenu = 'menu' + menuNum;
		var domSMenu = findDOM(idSMenu,1);

///// Defines the positions of the sub-menus
	if (isID || isAll) { 	
				var menuLeft = (domMenu.offsetLeft) + (domMenuOpt.offsetLeft) + 0;
				var menuTop = (domMenu.offsetTop) + (domMenu.offsetHeight) + 116;
			}
		if (isLayers) {
				var menuLeft = document.layers[idMenu].layers[idMenuOpt].pageX - 5;
				var menuTop = domMenu.pageY + domMenu.clip.height - 5;
		}

///// Positions and shows the menu
		if (oldDomSMenu != domSMenu) {	
			domSMenu.left = menuLeft; 
			domSMenu.top = menuTop;
			domSMenu.visibility = 'visible';
			domSMenu.zIndex = '100';
			oldDomSMenu = domSMenu;
		}

///// Resets oldDom if it is the same as the current DOM
		else { oldDomSMenu = null; }
	}

////// Returns a 'null' value for non-DHTML Browsers 
	else { return null; }
}

function delayHide() {
///// Checks to see if there is a menu showing and whether 
///// the global variable 't' has been set to 0
    if ((oldDomSMenu) && (t == 0)) {

///// Hides the old menu, resets menu conditions, 
///// and stops the function running
        oldDomSMenu.visibility = 'hidden'; 
        oldDomSMenu.zIndex = '0';
        oldDomSMenu = null;
        lCount = 0; 
        return false;
    }

///// Interupts the function if another menu is opened
    if (t == 2) { lCount = 0; return false; }

///// Repeats the function adding 1 to lCount each time until 
///// lCount is equal to lDelay and then sets 't' to 0 so that 
///// the menu will hide when it runs again
    if (t == 1) { 
        lCount = lCount + 1;
        if (lDelay <= lCount) { t = 0; }
        if (lDelay >= lCount) { setTimeout('delayHide(' + t + ')',pause); }
    }
}
