
/**********************************************************
	scripts.js

	Author: masni bennett
	
	Various scripts to be used on pages. Includes:
		- Rollover UL menu (for some content pages) (now initGenericNavigation() - Macca)

**********************************************************/


function show(id) {

	if (document.getElementById(id)) {
		document.getElementById(id).style.display = "block";
	}

}

function hide(id) {

	if (document.getElementById(id)) {
		document.getElementById(id).style.display = "none";
	}

}



/**********************************************************

	Rollover unordered list menu
	
	Author: masni bennett
	 
	Description: 
	
		Adds rollover menu effects to list items 
		by adding and removing the applied CSS class. This 
		is necessary only for IE (other browsers will do it
		by use of the :hover psuedo-class).
		
		The current page is also highlighted, if it is in 
		the menu.
		
	Instructions: 
		Add a unordered list to the page, and give it an 
		id of "menu".
		
		Note: CSS styles for the menu are crucial. See
		the styles for #rightmenu #menu in "includes/main.css".


**********************************************************/

function initGenericNavigation(menuId,hoverClass) {
	
	if (document.getElementById(menuId)) {
		
		var menu = document.getElementById(menuId);		
		
		var menuNodes = menu.childNodes[0].childNodes;						// Get all the child nodes of the menu (which will be the LIs, as well as others)	
		// For every list item in the menu...
		
		
		for (var i=0; i<menuNodes.length; i++)
		{
		
			// For each LI element that doesn't have a class ...
			// (menu elements shouldn't have classes unless they are "special" elements that shouldn't have a rollover anyway :| )
			// (If one of these needs to be a rollover, just do a "&& (menuNodes[i].className == "" || menuNodes[i].className == "thisClass")")
			if (menuNodes[i].nodeName == "LI" && menuNodes[i].className == "")
			{
				// Switch to "highlighted" class on mouseover
				menuNodes[i].onmouseenter = function menuMouseOver() {	
					//this.className += " "+hoverClass;
					this.className = hoverClass;
					
					var childItems = this.getElementsByTagName("UL");
					
					for (var j=0; j<childItems.length; j++)
						childItems[j].style.display = "block";
				}
	
				// Remove "highlighted" class on mouseout
				menuNodes[i].onmouseleave = function() {
					this.className = this.className.replace(new RegExp(hoverClass+"\\b"), "");
					
					var childItems = this.getElementsByTagName("UL");
					
					for (var j=0; j<childItems.length; j++)
						childItems[j].style.display = "none";
				}	
			}
		}
	}
}




