// menu.js
// A basic menu script
// by Greg Poole | greg@webengine.com.au | www.webengine.com.au

var menus = new Array();

function menus_init() {
	menu_create("why-newcrest", "menu-why-newcrest", "button-why-newcrest");
	menu_create("operations", "menu-operations", "button-operations");
	menu_create("culture", "menu-culture", "button-culture");
	menu_create("recruitment-process", "menu-recruitment-process", "button-recruitment-process");
	menu_create("diversity", "menu-diversity", "button-diversity");
}
addEventHandler(window,"onload",menus_init);

function Menu(obj) {
	
	obj.style.visibility = "hidden";
	
	this.menuobj = obj;
	this.showing = false;
	this.timer = new Timer(this);
	this.hideTimeout = -1;
	this.menubtn;
	
	this.show = function() {
		this.timer.clearTimeout(this.hideTimeout);
		this.hideTimeout = -1;
		this.menuobj.style.visibility = "visible";
		this.menubtn.className = "selected";
	}
	
	this.hide = function() {
		this.menubtn.className = this.menubtn.oldClassName;
		this.menuobj.style.visibility = "hidden";
		this.hideTimeout = -1;
	}
	
	this.startHide = function() {
		this.hideTimeout = this.timer.setTimeout("hide", 50);
	}
	
	this.bindTo = function(button, id) {
		this.menubtn = button;
		var top = getAbsOffsetTop(button) + button.offsetHeight;
		var left = getAbsOffsetLeft(button);
		this.menuobj.style.position = "absolute";
		this.menuobj.style.top = top + "px";
		this.menuobj.style.left = left + "px";
		this.menubtn.oldClassName = this.menubtn.className;
		addEventHandler(button, "onmouseover", function() { eval("menu_show('" + id + "')") });
		addEventHandler(button, "onmouseout", function() { eval("menu_hide('" + id + "')") });
	}
	
}

function menu_show(id) {
	menus[id].show();
}

function menu_hide(id) {
	menus[id].startHide();
}

function menu_create(id, div_id, button_id) {
	var div = document.getElementById(div_id);
	var button = document.getElementById(button_id);
	menus[id] = new Menu(div);
	menus[id].bindTo(button, id);
	addEventHandler(div, "onmouseover", function() { eval("menu_show('" + id + "')") });
	addEventHandler(div, "onmouseout", function() { eval("menu_hide('" + id + "')") });
}