
var nav_currentMenu = -1; //init to the negative value which indicates no menu is currently shown
var nav_hideEvent = null;

function gf_showMenu(menuIndex, eventObj, leftMenu) {
	gf_cancelHideMenu();
	//if (!(NN && leftMenu)) {
		if (!gfSuppressTopmenu || leftMenu) {
		/* added gfSuppressTopmenu 4-7 to allow a boolean flag on any page to determine whether menus should show
			-- probably will not be used, but I'm leaving the functionality in 
		*/
			if (nav_currentMenu != -1) gf_hideMenu();
			
			var newLeft = 131;
			var newTop = 25;
			var maxWidth, maxHeight;
			
			//set a variable that tells script how with the rightmost menu is (determined thru trial and error)
			var sizeOfRightmostMenu = 164;
			//if (N6) sizeOfRightmostMenu = 300;
			
			//get the maximum available width
			if (NN || N6) {
				var maxWidth = window.innerWidth;
				var maxHeight = window.innerHeight;
			} else {
				var maxWidth = document.body.clientWidth;
				var maxHeight = document.body.clientHeight;
			}
			
			//calculate menu position
			if (leftMenu) {
				//calculate top
				newTop = gf_getEventY(eventObj) - 20;
			} else {
				//calculate left
				newLeft = gf_getEventX(eventObj) - 40;
				if ((newLeft + sizeOfRightmostMenu) > maxWidth) newLeft = maxWidth - sizeOfRightmostMenu;
			}
			
			gf_setLayerLeft(gf_getLayerObj('topNav' + menuIndex), newLeft);
			gf_setLayerTop(gf_getLayerObj('topNav' + menuIndex), newTop);
			gf_setLayerVis(gf_getLayerObj('topNav' + menuIndex));
			
			if (gf_layerExists('gfTopAnim')) {
				gf_setLayerVis(gf_getLayerObj('gfTopAnim'), true);
				gf_setLayerVis(gf_getLayerObj('gfTopNoAnim'), false, 'block');
			}
			
			nav_currentMenu = menuIndex;
		}
	//}
}

function gf_hideMenu() { //works on nav_currentMenu
	if (nav_currentMenu != -1) {
		gf_setLayerVis(gf_getLayerObj('topNav' + nav_currentMenu), true);
		nav_currentMenu = -1;
		
		if (nav_currentMenu == 5) focus(); //sets focus on the window just in case the user clicked in the search box on menu 5
		
		//restore the flash movie
		/*
		removed 4-27... why restore it? it's not on a loop or anything!
		if (gf_layerExists('gfTopAnim')) {
			gf_setLayerVis(gf_getLayerObj('gfTopAnim'), false);
			gf_setLayerVis(gf_getLayerObj('gfTopNoAnim'), true, 'none');
		}
		*/
	}
	gf_cancelHideMenu(); //cancels future calls to this function
}

function gf_hideMenuSoon(theInterval) {
	if (typeof theInterval != 'number') theInterval = 200;
	//if (nav_currentMenu > 5 && NN) theInterval = 1000; //to address left-nav oddities in the undisputed King of Bugs, Netscape Navigator 4
	gf_cancelHideMenu();
	nav_hideEvent = setInterval('gf_hideMenu()', theInterval);
}

function gf_cancelHideMenu() {
	if (nav_hideEvent != null) {
		clearInterval(nav_hideEvent);
		nav_hideEvent = null;
	}
}

function gf_searchWidgetRespond(obj) {
	gf_cancelHideMenu();
	if (obj.value == 'Keyword(s)') {
		if (!NN && !N6) obj.style.color = 'black';
		obj.value = '';
	}
}

function gf_searchWidgetInputBox() {
	if (NN) var theSize = 8;
	else var theSize = 18;
	var theHTML = '<input name="CiRestriction" class="searchInput" type="text" size="' + theSize + '" value="Keyword(s)" onFocus="gf_cancelHideMenu(); gf_searchWidgetRespond(this);" onMouseOut="gf_hideMenuSoon(2500)" onMouseOver="gf_cancelHideMenu()">';
	return theHTML;
}

/* tried this as a tweak -- not good, really
function XXgf_hideMenuIf(eventObj) {
	if (NN) var yCoord = eventObj.y
	else var yCoord = event.y
	
	if (yCoord < 10) gf_hideMenuSoon();
	else gf_hideMenuSoon(1250);
}
*/

function gf_hideMenuIf(eventObj, duration) { 
	//hides the popup menu when a top-nav item is moused out upwards
	//actually, this function never has much effect as it gets overridden by the table-based event calls... oh well...
	if (typeof duration != 'number') duration = 200;
	if (!N6 & !NN) var yCoord = event.y
	else if (NN) var yCoord = eventObj.y
	//no n6 version yet
	
	if (yCoord < 10) gf_hideMenuSoon();
} 