// JavaScript Document
/*
	Name:		menu.js
	Author:		Chad Hovell
	Desc:		rollover menu - supports only 1 level of submenu
				more than 1 level will require recursively hiding parent menus...
	
	History:
				22 - 02 - 2007
				Created
				shows, hides, inits, names

*/

//debug to print all object props
function writeProps(obj) {
	var i;
	var output;
	output += '<table>';
	for (i in obj) {
		output += '<tr><td>' + i + "</td><td>" + obj[i] + "</tr></td>";
	}
	output += '<table>';
	document.write(output);
}

//shortcut to get element
function getElement(id) {
	return document.getElementById(id);
}


//makes object visible
function showObj(obj) {
	var id = obj.subNode;
	var index = obj.index;
	var obj = getElement(id);
	obj.style.visibility = "visible";
	obj.style.zIndex = index * 100;
}
//hides object
function hideObj(obj) {
	var id = obj.subNode;
	getElement(id).style.visibility = "hidden";
}








function menuClass(id) {
	this.init(id);
}



menuClass.prototype.init = function(id) {
	this.menu_index = 0;
	
	var div = getElement(id);
	var node;
	
	//find top level UL
	for (var i=0; i<div.childNodes.length; i++) {
		node = div.childNodes[i];
		if (node.tagName == 'UL') {
			this.initList(node);
		}
	}
	
}

//inits list for menu rollovers
menuClass.prototype.initList = function(node) {
	var subNode;
	for (var i=0; i<node.childNodes.length; i++) {			//find the LI inside the UL
		subNode = node.childNodes[i];
		if (subNode.tagName == 'LI') {
			this.initListItem(subNode);
		}
	}
}

//inits listitem for menu rollovers
menuClass.prototype.initListItem = function(node) {
	var subNode;
	var index;
	for (var i=0; i<node.childNodes.length; i++) {			//find the UL inside the LI
		subNode = node.childNodes[i];
		if (subNode.tagName == 'UL') {
			index = this.menu_index++
			subNode.id = 'menu' + index;	//create unique id for submenu item
			node.subNode = subNode.id;		//now set actions to show submenu on rollover
			node.index = index;
			node.onmouseover = function() {showObj(this);}
			node.onmouseout = function() {hideObj(this);}
			
			this.initList(subNode);
		}
	}
}