// ** Sniff for the two major browser types **
	var ie  = (document.all)? true:false
	var moz = ((document.getElementById)&&(!ie))? true:false

// ** Sniff for browser version (used for IE 5 only) **
	var agent = navigator.userAgent.toLowerCase();
	var intAppVersion = parseInt(navigator.appVersion);
	var ie5_0 = (ie && (intAppVersion == 4) && (agent.indexOf("msie 5.0")!=-1) );
	var ie5_5 = (ie && (intAppVersion == 4) && (agent.indexOf("msie 5.5") !=-1));

// ** Sniff for Mac (used for IE Mac browsers) **
	var mac = (agent.indexOf("mac") > -1)? true:false

// ** Global variables **
	var layerNavMenu, layerNavSecMenu, layerMenuDiv, layerMenuSecDiv;
	var currentMenu, currentSecMenu, currentMenuWidth, currentSecMenuWidth;
	var memCurrentMenu = "";
	var memLayerMenuDiv = "";
	var memCurrentSecMenu = "";
	var memLayerMenuSecDiv = "";
	var isOutsideMenus = true;
	var isOutsideSecMenus = true;
	var constFullPageWidth = 766;
	var constTopNavWidth = 753;
	var PageLoaded = false;

// ** If these are set to 0 the code will automatically calculate and populate the values based on the widest menu entry. **
// ** Setting values here will bypass the calculations. **
// ***** WARNING!!!:  
// SETTING ANY OF THESE VALUES TO 0 (zero) 
// WILL BREAK THE DROP-DOWN NAV IN IE 7 !!!
	var navMenuWidth = new Array();
	navMenuWidth["Tickets"] = 175;
	navMenuWidth["FOLPassGroup"] = 230;
	navMenuWidth["Inside"] = 154;
	navMenuWidth["Dining"] = 190;
	navMenuWidth["Shopping"] = 260;
	navMenuWidth["Nightspots"] = 250;
	navMenuWidth["VisitorInfo"] = 200;
	navMenuWidth["Experiences"] = 200;
	navMenuWidth["DiningCasual"] = 340;
	navMenuWidth["DiningQuick"] = 240;
	navMenuWidth["DiningSnacks"] = 170;
	navMenuWidth["ShoppingApparel"] = 260;
	navMenuWidth["ShoppingCollectibles"] = 215;
	navMenuWidth["ShoppingFood"] = 175;
	navMenuWidth["FoL"] = 0;
	navMenuWidth["JobDescrips"] = 124; 	// see "ENTERTAINMENT JOBS" minisite 
										// ("http://preview.unistudios.com//entjobs/")
										// - this is the dropdown menu under "Job Descriptions"

// ** Returns a DHTML reference to a layer.  It makes sure that if a layer doesn't exist **
// ** the function will return null instead of a JavaScript error. **
	function getLayerRef(layerName) {
		var layerRef;
		if (ie) {
			if (document.all[layerName]) {
				layerRef = document.all[layerName];
				HideText = "hidden";
			} else {
				layerRef = null;
			}
		} else {
		    // default to NS6+/Firefox
			if (document.getElementById(layerName)) {
				layerRef = document.getElementById(layerName);
				HideText = "hidden";
			} else {
				layerRef = null;
			}
		}

		return layerRef;
	}


// ** Functions to determine the browser window width and height **
	function getInsideWindowWidth() {
		if (ie) {
			return document.body.scrollWidth
		} else {
			return document.width
		}
	}

	function getInsideWindowHeight() {
		if (ie) {
			return document.body.scrollHeight
		} else {
			return document.height
		}
	}


// ** Calculate the position of the rolled over item from the mouse event. **
	function getEventXOffset(evt) {
		if (ie5_0 || ie5_5) {
			return document.body.scrollLeft - document.body.clientLeft + evt.clientX - evt.offsetX;
		} else if (ie) {
			return document.documentElement.scrollLeft - document.documentElement.clientLeft + evt.clientX - evt.offsetX;
		} else {
			return evt.pageX - evt.layerX
		}
	}

	function getEventYOffset(evt) {
		if (ie5_0 || ie5_5) {
			return document.body.scrollTop - document.body.clientTop + evt.clientY - evt.offsetY;
		} else	if (ie) {
			return document.documentElement.scrollTop - document.documentElement.clientTop + evt.clientY - evt.offsetY;
		} else {
			return evt.pageY - evt.layerY
		}
	}

// ** returns the width of a layer **
	function getLayerWidth(layer) {
		if (ie) {
			return layer.scrollWidth;
		} else {
			return layer.offsetWidth;
		}
	}



// ** Initialize the top nav layers and sets PageLoaded to true. **
	function initMenus() {
		layerNavMenu = getLayerRef("navMenuContainer");
		layerNavSecMenu = getLayerRef("navSecMenuContainer");
		PageLoaded = true;
	}


//**********************************
//** Top Nav DHTML Menu Functions **
//**********************************

// ** Calculates max width of layer (if not already set), and sets the outer div to that size. **
	function calcAndSetWidth(menuName, isSecondary) {
		var i, menuToCalc;
		menuToCalc = isSecondary ? layerNavSecMenu : layerNavMenu;
		if (navMenuWidth[menuName] <= 0) {
		// ** Calculate max width of inner DIVs **
			for (i=0; i<menuToCalc.childNodes.length; i++) {
				if (menuToCalc.childNodes[i].offsetWidth > navMenuWidth[menuName]) {
					navMenuWidth[menuName] = menuToCalc.childNodes[i].offsetWidth;
				}
			}
		}
		
		if (isSecondary) {
			currentSecMenuWidth  = navMenuWidth[menuName];
		} else {
			currentMenuWidth = navMenuWidth[menuName];
		}

		menuToCalc.style.width = navMenuWidth[menuName] + "px";
	}


// ** Menu item rollover functions **
	function menuItemRollOver(layer, isSecondary) {
		if (PageLoaded) {
			layer.style.background = "url('/images/top_nav/no_line_bullet_bg_hl.gif')";
			layer.style.backgroundColor = "#CD8B0C";			
			showDropDownMenu(isSecondary);
		}
	}

	function menuItemRollOff(layer, isSecondary) {
		if (PageLoaded) {
			layer.style.background = "url('/images/top_nav/no_line_bullet_bg.gif')";
			layer.style.backgroundColor = "#DACDC6";
			first = layer.href.lastIndexOf('/') + 1;
			last = layer.href.lastIndexOf('.');
			imgName = layer.href.substring(first, last);
			if (isSecondary) {
				hideSecDropDownMenu(true);
			} else {
				hideDropDownMenu(true);
			}
		}
	}


// ** Top Nav Dropdown functions **
// ** Check PageLoaded on these just in case to avoid javascript errors **
	function showDropDownMenu(isSecondary) {
		var menuToShow;
		if (PageLoaded) {
			menuToShow = isSecondary ? layerNavSecMenu : layerNavMenu;
			if (isSecondary) {
				isOutsideSecMenus = false;
				isOutsideMenus = false;
			} else {
				isOutsideMenus = false;
			}
			menuToShow.style.visibility = "inherit";
			if (!isSecondary) {
				layerMenuDiv.childNodes[0].style.visibility = "inherit";
			}
		}
	}

	function hideDropDownMenu(FirstTry) {
		if (PageLoaded) {
			if (FirstTry) {
				isOutsideMenus = true;
				memLayerMenuDiv = layerMenuDiv;
				memCurrentMenu = currentMenu;
				setTimeout("hideDropDownMenu(false)", 50);
			} else if (isOutsideMenus) {
				layerNavMenu.style.visibility = "hidden";
				//** Must split these two if statement, because the second one will fail if the first is true. **
				if (memLayerMenuDiv) {
					if (memLayerMenuDiv != "") {
						memLayerMenuDiv.childNodes[0].style.visibility = "hidden";
					}
				}
				memLayerMenuDiv = "";
				memCurrentMenu = "";
			}
		}
	}

	function hideSecDropDownMenu(FirstTry) {
		if (PageLoaded) {
			if (FirstTry) {
				isOutsideSecMenus = true;
				isOutsideMenus = true;
				memLayerMenuSecDiv = layerMenuSecDiv;
				memCurrentSecMenu = currentSecMenu;
				setTimeout("hideSecDropDownMenu(false)", 50);
				setTimeout("hideDropDownMenu(false)", 150);
			} else if (isOutsideSecMenus) {
				layerNavSecMenu.style.visibility = "hidden";
				memLayerMenuSecDiv = "";
				memCurrentSecMenu = "";
			}
		}
	}

	function openDropDownMenu(menuName, topDiv, evt, isSecondary) {
		var MenuEdge, menuXPosition, menuYPosition, thisMenu;
		
		
				
		if (!evt) evt = event;
		
		if (PageLoaded) {
			thisMenu = isSecondary ? layerNavSecMenu : layerNavMenu;

		// ** Hide menu and move it off the page.  This resolves menu flicker. **
			if (isSecondary) {
				isOutsideSecMenus = true;
				hideSecDropDownMenu(false);
			} else {
				isOutsideMenus = true;
				hideDropDownMenu(false);
			}
			
			thisMenu.style.left = -500;
			thisMenu.style.top = -500;

			//alert(getLayerRef('nav' + menuName).innerHTML);
		// ** Copy the contents of the current menu div at the bottom into the menu container div **
			thisMenu.innerHTML = getLayerRef('nav' + menuName).innerHTML;

			if (ie) {
				thisMenu.style.width = "10px";
			} else {
				thisMenu.style.width = "auto";
			}

			calcAndSetWidth(menuName, isSecondary);

	// ** Calculate right edge of menu.  If it's past the edge of the top nav, align it so it is not past it. **
	// ** For secondary menus, move the menu to the left of the primary menu when this happens **

			menuXPosition = getEventXOffset(evt);
			menuYPosition = getEventYOffset(evt);

			LeftPageStart = (getInsideWindowWidth()-constFullPageWidth)/2;
			MenuEdge = menuXPosition + getLayerWidth(thisMenu) - LeftPageStart;

			if (MenuEdge > constTopNavWidth) {
	// ** The right edge of the menu is beyond the designed-for constTopNavWidth.  Adjust menuXPosition appropriately.
				if (isSecondary) {
					menuXPosition -= currentSecMenuWidth;
					menuXPosition -= currentMenuWidth;
					menuXPosition += 5;
					if (ie) {
						menuXPosition -= 3;
					}
				} else {
					menuXPosition -= (MenuEdge-constTopNavWidth) - 3;
				}

				if (moz) {
					menuXPosition -= 3;
				} else if (ie && mac)  {
					menuXPosition -= 2;
				}

				if (ie5_5) {
					menuXPosition -= 2;
				}
			}

		// ** Put in IE Mac position fixes here if we need them (not tested). **				
			if (ie && mac) {
				menuXPosition -= 23;
			}
			
			if (ie) {
				menuXPosition -= 2;
				menuYPosition -= 2;
			}
			
			if (ie5_0 || ie5_5) {
				menuXPosition += 2;
			}
			
			if (isSecondary) {
				menuXPosition += currentMenuWidth - 2;
				if (topDiv.className == "firstli")
				{
					if (!ie) {
						menuYPosition -= 2;
					}
				}
				if (ie) {
					menuYPosition -= 31;
				} else {
					menuYPosition -= 29;
				}
			}
			
			
			
		
		// ** Set left & top positions. **
			thisMenu.style.left = menuXPosition + "px";
			menuYPosition = menuYPosition + 30;
			thisMenu.style.top = menuYPosition + "px";

			if (isSecondary) {
				layerMenuSecDiv = topDiv;
				currentSecMenu = menuName;
			} else {
				layerMenuDiv = topDiv;
				currentMenu = menuName;
			}

			showDropDownMenu(isSecondary);
		}
	}
	
	function rollOverNoMenu(topDiv) {
		if (PageLoaded) {
			topDiv.childNodes[0].style.visibility = "visible";
		}
	}
	
	function rollOutNoMenu(topDiv) {
		if (PageLoaded) {
			topDiv.childNodes[0].style.visibility = "hidden";
		}
	}


// ** Generic Function Library **

	function divLink(url) {
		document.location.href = url;
	}