//Define global variables 
var timecount = 1000; // Change this to the time delay that you desire 

function ReloadWindow() 
{  
	window.location.reload();  
} 

// Show or hide the layer
function setLayerVisible(layerName, visible) 
{  
	// Decide to set element visible or hidden
	var visibility = "visible";
	if (!visible)
	{
		visibility = "hidden";
	}
	
	switch (this.browserId)
	{
		case "none":
			break;
		case "dom1":
			var element = document.getElementById(layerName);
			element.style.visibility = visibility;
			break;
		default:
			eval(this.layerRef + '["' + layerName + '"]' + this.styleSwitch + ' = "' + visibility + '"');  
			break;
	}
} 

// Check the browsertype, etc...
function BrowserInfo()
{
	// What browser are we running in
	this.newbrowser = true; // Unknown browser??

	// Set methods for this object
	this.SetLayerVisible = setLayerVisible;

	// Default values for browser identification
	this.layerRef    = "document.all";  
	this.styleSwitch = ".style";  
	this.visibleVar  = "visible";  
	
	// Check to see if we need to change the defaults
	if(document.getElementById)
	{
		this.browserId   = "dom1";  
		this.layerRef    = "document.getElementByID";  
	}
	else if (document.layers) 
	{  
		this.browserId   = "ns4";  
		this.layerRef    = "document.layers";  
		this.styleSwitch = "";  
		this.visibleVar  = "show";  
		this.screenSize  = window.innerWidth;  
		
		// For older browsers that don't update the DOM 
		// on a resize of the window
		window.onresize = ReloadWindow; 
	}  
	else if(document.all) 
	{  
		this.browserId   = "ie4";  
		this.layerRef    = "document.all";  
		this.screenSize  = document.body.clientWidth + 18;  

		// For older browsers that don't update the DOM 
		// on a resize of the window
		window.onresize = ReloadWindow; 
	}  
	else 
	{  
		this.browserId   ="none";  
		this.newbrowser  = false;  
	} 
} 

//
// Menu System Class definition
//
function showMenu(menuId)
{
	this.HideAll();
	this.Browser.SetLayerVisible(menuId,true);
}

function hideMenu(menuId)
{
	this.Browser.SetLayerVisible(menuId,false);
}

function hideAllMenus()
{
	for(var i=0; i<this.MenuList.length; i++)
	{
		var menuId = this.MenuList[i];
		this.Hide(menuId);
	}
	this.StopTimeout();
}

function addMenu(menuId)
{
	this.MenuList.push(menuId);
	this.Hide(menuId);
}

function startDelayTimer() 
{  
	if (this.timerID == null) 
	{  
		this.timerID = setTimeout( this.Instance + ".HideAll()" , this.HideTimeout);  
	}  
} 

function stopDelayTimer() 
{  
	if (this.timerID != null) 
	{  
		clearTimeout(this.timerID);  
		this.timerID = null;  
	}  
} 

function MenuSystem(instance)
{
	this.Instance = instance;
	
	this.Browser = new BrowserInfo();
	this.MenuList = new Array();
	
	// The delay before the menu is closed again
	this.HideTimeout = 1000;
	this.StartTimeout = startDelayTimer;
	this.StopTimeout = stopDelayTimer;
	this.timerID = null;
	
	this.AddMenu = addMenu;
	this.Show = showMenu;
	this.Hide = hideMenu;
	this.HideAll = hideAllMenus;
}

// Create the global mainmenu system
var MainMenu = new MenuSystem("MainMenu");


