// This menu code works on timeout events based on mousein/mouseout events, using the 'isInMenu' property
// of each menu object to track in/out on the buttons and menus. The event order is important, so a bad
// layout of the divs could mess this up severely.
var menus = {};

// I would do this as a closure, but certain foul old browsers won't handle window.setTimeout with function values.
function possiblyHideMenu(menu_name)
{
	var menu = menus[menu_name];
	
	if(! menu.isInMenu){
		hide(menu.div);
		
		if(menu.shader) hide(menu.shader);
	}
}

function menu(menu_name, divid, buttonid, shaderid){
	menus[menu_name] = this;
	this.button = document.getElementById(buttonid);
	this.div = document.getElementById(divid);	
	
	switch( navigator.appmenu_name ){
		case "Microsoft Internet Explorer":
			this.shader = document.getElementById(shaderid);
			
			if(this.shader){
				this.shader.innerHTML = "<iframe style='position: absolute; top: -5px; left: -5px; width: 153px; height: 400px; border: solid 0px black; margin: 0px; padding: 0px;filter:alpha(opacity=0)'></iframe>";
			}
		default:
			break;
	}
	
	var menu = this;
	
	// If these two functions are not called *after* the appropriate onmouseout events
	// when moving between buttons, things break. Lay out thy pages accordingly.
	this.button.onmouseover = function(){
	 	menu.isInMenu = true;
			
		if(menu.shader != null){	
			menu.shader.style.height = menu.div.offsetHeight;		
			show(menu.shader);
		}	
		
		show(menu.div);
	}
	
	this.div.onmouseover = function(){
		menu.isInMenu = true;
	} 
	
	// When leaving the button or the menu, set up the dissappearance.
	this.button.onmouseout = this.div.onmouseout = function(){
		menu.isInMenu = false;
		window.setTimeout("possiblyHideMenu('" + menu_name + "')",80);
	}
	
	this.clear = function(){		
		this.button.onmouseover = this.div.onmouseover = this.button.onmouseout = this.div.onmouseout = null;
		this.button = this.div = this.shader = null;
	}
		
	this.isInMenu = false;

	return this;
}

function show(object){	
	object.style.visibility = "visible";
}

function hide(object){
	object.style.visibility = "hidden";
}

     

// Stupid IE
window.onunload = function()
{
	for(m in menus){
		var menu = menus[m];
		menu.clear();
		menus[m] = null;
	}
}    