
	//the below array corresponds to the first folder of the URL path - to add a new persistent nav page (where a 
	//top-level menu item remains highlighted), create the appropriate nav elements (in lttop.php), then add the
	//path name here. if nav elements are created without adding a path name to the array, the menu will fade out 
	//after the delay timer expires as opposed to snapping back to the persistent element
	var persistentMenuSelectionIDs = new Array("players", "addons", "adsolution", "partnerships", "support", "about", "cms");
	var killTimer, currentPersistentElementID, timedFunction = "";
	var selectedTextColor = "rgb(51, 51, 51)";
	var selectedTextColorIE = "#333"; //of course IE represents this differently
	var overlayFadeInTime = 400;
	var overlayFadeOutTime = 400;
	var subNavFadeInTime = 200;
	var subNavFadeOutTime = 10;

	$(document).ready(function() {
	    //check the url for a persistent ID - the menu will behave differently if one is found
	    currentPersistentElementID = location.href.split("/")[3].replace("?", "").replace("=", "");;

	    for (var i in persistentMenuSelectionIDs) 
		{
	        if (currentPersistentElementID == persistentMenuSelectionIDs[i]) 
			{
	            highlightPersistentElement();
	            break;
	        }
	    }

	    //determine the correct hide function to call based on menu type - add some additional handling 
        //for mousing out of the persistent element (to stop it from reloading)
	    if (typeof (currentPersistentElementID) == "undefined" || currentPersistentElementID == "")
	        timedFunction = "hideAll()";
	    else
	    {
	        timedFunction = "hideAllButPersistentElement()";
	        
	        $('#' + currentPersistentElementID).mouseout(function() {
	            $('body').oneTime(1, 'hide', function() {
	                $('body').stopTime('hide');

					//if at this point the persistent element isn't highlighted, restart the timer to highlight it
					//(addresses an obscure bug where if the user mouses out of a non-persistent element very quickly 
					//into and out of a link in the submenu of the persistent element, the menu will not snap back)
					if($('#' + currentPersistentElementID + ' a').css("color") != selectedTextColor && 
					   $('#' + currentPersistentElementID + ' a').css("color") != selectedTextColorIE)
						mouseOutDelayedExecute();
	            });
	        });
	    }

	    //attach event to main top-level menu item elements
	    $('.navbutlink').mouseover(function() {
	        $('body').stopTime('hide');

	        //prevent a menu element from being refreshed if it is moused over, then off, then back over
	        if ($(this).css("color") == selectedTextColor || $(this).css("color") == selectedTextColorIE)
	            return;

	        hideSubMenuAndRevertAllTopStyles();

	        //the overlay should only fade back in for the non-persistant menu as it is present all the time 
            //in the persistent menu
	        if (typeof (currentPersistentElementID) == "undefined" || currentPersistentElementID == "")
	            $('#grayoverlay').fadeIn(overlayFadeInTime);

            //fade in the submenu and apply styles to the currently selected top-level menu button element
	        $('#' + $(this).attr('id')).next().fadeIn(subNavFadeInTime);
	        applyStyles($('#' + $(this).attr('id')));
	    });

        //attach appropriate events to menu elements - a timer runs for 1 second before closing the menu, 
	    //unless it it cancelled by a mouse action over another element
	    $('.mouseovertimerelement').mouseover(function() {
	        $('body').stopTime('hide');
	    });

		$('.mouseouttimerelement').mouseout(function() {
	        mouseOutDelayedExecute();
	    });
	});
	
	function hideAll()
	{
		$('#grayoverlay').fadeOut(overlayFadeOutTime);
		hideSubMenuAndRevertAllTopStyles();
	}

	function mouseOutDelayedExecute()
	{
		$('body').oneTime(1000, 'hide', function() {
			eval(timedFunction);
	    });
	}

	function hideAllButPersistentElement()
	{
		for (var i in persistentMenuSelectionIDs)
		{
			if(currentPersistentElementID == persistentMenuSelectionIDs[i]) 
				continue;

			revertTopStyles(persistentMenuSelectionIDs[i]);
		} 

		$('.subtopnav').fadeOut(subNavFadeOutTime);
		highlightPersistentElement();
	}

	function hideSubMenuAndRevertAllTopStyles()
	{
		$('.subtopnav').fadeOut(subNavFadeOutTime);
		revertAllTopStyles();
	}

	function applyStyles(elementToStyle)
	{
	    elementToStyle.css({ background: 'url(/jw/images/gray-back.png)' });
	    elementToStyle.css({ color: '#333' });
	}

	function revertAllTopStyles()
	{
		$('.navbutlink').css({background: 'url(/jw/images/greenbaronly-back.png)'});
		$('.navbutlink').css({color: '#FFF'});
	}

	function revertTopStyles(revertElementId)
	{
		$('#' + revertElementId + ' > a').css({background: 'url(/jw/images/greenbaronly-back.png)'});
		$('#' + revertElementId + ' > a').css({color: '#FFF'});
	}

	function highlightPersistentElement()
	{
		applyStyles($('#' + currentPersistentElementID + ' > a'));
		$('#' + currentPersistentElementID + ' a').next().fadeIn(subNavFadeInTime);
		
		//clear any residual timers that may try to deselect the persistent element
		$('body').stopTime('hide');
	}
