/* submenu.js 

This script will provide dropdown menus
Requires prototype.js

*/

function Menu(button,menu) {
	this.button = button;
	this.menu = menu;
}

Menu.prototype.initialize = function() {
	var thisMenu = this;
		thisMenu.button.onmouseover = function () {
			thisMenu.showMenu();
		}
		thisMenu.button.onmouseout = function () {
			thisMenu.rollOff();
		}
		if (this.menu != null) {
			thisMenu.menu.onmouseover = function () {
				thisMenu.cancelTimer();
			}
			thisMenu.menu.onmouseout = function () {
				thisMenu.rollOff();
			}
		}
}

Menu.prototype.cancelTimer = function () {
	clearTimeout(this.timer);
}

Menu.prototype.rollOff = function () {
	var closeMenu = "menuObjects["+this.id+"].hideMenu()";
	this.timer = setTimeout(closeMenu,1000);
}

Menu.prototype.showMenu = function () {
	for (i=0;i<menuObjects.length;i++) {
		menuObjects[i].hideMenu();
		menuObjects[i].cancelTimer();
	}
	if (this.menu != null) {
	this.menu.style.display = "block";
	this.button.className += " on";
	}
}

Menu.prototype.hideMenu = function () {
	if (this.menu != null) {
	this.menu.style.display = "none";
	this.button.className = "dropdown";
	}
}


// initialize menus //

var menuObjects = new Array();

Event.observe(window, 'load', function() {
	var menus = $$("a.dropdown");
	for (var y=0; y < menus.length; y++) {
		var submenuID = "dropdown-"+menus[y].id;
		var submenu = $(submenuID);
		menuObjects[y] = new Menu(menus[y],submenu);
		menuObjects[y].id = y;
		menuObjects[y].initialize();
	}
});
	

