// JavaScript Document

var NUMBOTTOMSUBMENUS = 7;

function BottomMenu() {
	// construct a new bottom menu object;
	
	this.type="bottom";
	this.delay = 750;

	this.defaultSubMenuId = null;
	
	this.overSubMenu = mouseOverBottom;	
	this.overMainMenu = mouseOverBottom;
	
	
	this.outMainMenu = returnToDefaultBottom;
	this.outSubMenu = returnToDefaultBottom;


	this.mouseOver = mouseOverBottom;
	this.showSubMenu = showSubMenuBottom;
	this.returnToDefault = returnToDefaultBottom;
	this.hideSubMenu = hideSubMenuBottom;
	this.hideAll = hideAllBottom;
	this.setDefaultMenu = setDefaultBottomMenu;
	
	this.returnToDefaultTimer = returnToDefaultTimerBottom;
	this.cancelReturnToDefaultTimerBottom = cancelReturnToDefaultTimerBottom;
}


function setDefaultBottomMenu(id) {
	this.defaultSubMenuId=id;
	this.returnToDefault(null, true);
}

function mouseOverBottom(id) {
	this.hideAll();
	this.showSubMenu(id);
	this.cancelReturnToDefaultTimerBottom();
}

function showSubMenuBottom(id) {
	if (document.getElementById("bottomMenuOption" + id)) {
		document.getElementById("bottomMenuOption" + id).style.backgroundColor="#cf84b4";
		document.getElementById("bottomMenuOption" + id).style.color="#ffffff";
	}
	if (document.getElementById("bottomSubMenu" + id)) {
		document.getElementById("bottomSubMenu" + id).style.display="block";
	}
}


function cancelReturnToDefaultTimerBottom() {
	if (this.returnToDefaultTimer()) {
		window.clearTimeout(this.returnToDefaultTimer());
		this.timerId=null;
	}
}

function returnToDefaultTimerBottom() {
	if (!arguments[0]) {
		return this.timerId || null;
	} else {
		this.timerId = arguments[0];	
	}
}


/* function returnToDefaultBottom() {

	this.hideAll();
	if (this.defaultSubMenuId) {
		//alert("defaulting to" + this.defaultSubMenuId); 
		this.showSubMenu(this.defaultSubMenuId);
	}
} */


function returnToDefaultBottom(menuid, rightNow) {
	var Tmp = this;
	this.doStuff = function () {
		Tmp.hideAll();
		if (Tmp.defaultSubMenuId) {
			//alert("defaulting to" + this.defaultSubMenuId); 
			Tmp.showSubMenu(Tmp.defaultSubMenuId);
		}
	}
	this.returnToDefaultTimer(setTimeout(this.doStuff, (rightNow ? 0 : this.delay)));
}

function hideSubMenuBottom(id) {
	if (document.getElementById("bottomMenuOption" + id)) {
		document.getElementById("bottomMenuOption" + id).style.backgroundColor="";	
		document.getElementById("bottomMenuOption" + id).style.color="#cf84b4";
	}
	if (document.getElementById("bottomSubMenu" + id)) {	
		document.getElementById("bottomSubMenu" + id).style.display="none";
	}
}

function hideAllBottom() {

	for (var i=0; i<NUMBOTTOMSUBMENUS; i++) {
		this.hideSubMenu(i+1);
	}
}

