/*
 * $Id: menu.js 29 2009-09-01 11:50:37Z root $
 */

/**
 * Default Menu functions.
 * These functions can be used to create a (dropdown) menu from a list of items.
 * The prepareMenu function can be applied to an HTML UL element.
 * An UL element that is inside an LI-element will be shown on mouse over of the LI element,
 * the UL element is hidden on mouse out of the parent LI element.
 */

/**
 * mnuShow()
 * Shows the childList in an LI element.
 */
function mnuShow(elem) {
	obj = getSubItem(elem);
	obj.style.display = "block";
}

/**
 * mnuHide()
 * Hides the childList in an LI element.
 */
function mnuHide(elem) {
	obj = getSubItem(elem);
	obj.style.display = "none";
}

/**
 * getSubItem()
 * Returns the sublist in an LI element.
 */
function getSubItem(li) {
	var liChilds = li.childNodes.length;
	for (j=0; j < liChilds; j++) {
		if (li.childNodes[j].nodeType == 1 && li.childNodes[j].tagName.toLowerCase() == "ul") {
			return (li.childNodes[j]);
		}
	}

}

/**
 * getObj()
 * Returns the HTML element with a specific id.
 */
function getObj(name) {
  if (document.getElementById){
  	return (document.getElementById(name));
  }
  else if (document.all) {
	return (document.all[name]);
  }
  else if (document.layers) {
   	return(document.layers[name]);
  }
}

function prepare(ul) {
    if(ul==null) return false;
	var length = ul.childNodes.length;
	var i,j,liChilds,sub;
	for(i=0; i< length; i++) {
		if (ul.childNodes[i].nodeType != 1) { continue; }
		liChilds = ul.childNodes[i].childNodes.length;
		if (liChilds <= 1) { continue; }
		sub = null;
		for (j=0; j < liChilds; j++) {
			if (ul.childNodes[i].childNodes[j].nodeType == 1 && ul.childNodes[i].childNodes[j].tagName.toLowerCase() == "ul" ) {
				ul.childNodes[i].onmouseover	= function() { mnuShow(this); };
				ul.childNodes[i].onmouseout		= function() { mnuHide(this); };
				prepare(ul.childNodes[i].childNodes[j]);
				break;
			}
		}
	}
}

/**
 * prepareMenu()
 * This function prepares the menu for showing/hiding sub menu's
 * @param string menuId the id of the Ul element that contains the menu to prepare.
 */
function prepareMenu(menuId) {
	var menu = getObj(menuId);
	prepare(menu);
}