/*
 * Adds hover/rollover functionality to document elements
 *
 * @author scampbell
 * @date 21-03-2006
 */


/**
 * Simulates the :hover state for elements in Internet Explorer
 *
 * Works by applying a class 'hover' to specified elements when
 * rolled over. The .hover class should share the same properties
 * as the corresponding :hover class.
 *
 * This Searson Buck-specific version applies the hover state to
 * the following elements:
 *   - top-level <li> elements in the main nav
 *   - the <div> within each of those <li>s
 *   - top-level <li> elements in the side nav
 *
 * Adapted from http://www.alistapart.com/articles/dropdowns
 *
 * @param rootElem     The element at which to root the search
 *                     for elements to be made 'hoverable'.
 * @param hoverTagName A string identifying the tagname of
 *                     elements to be made 'hoverable'.
 */
function init_hover() {
	//quick IE check
	if (!document.all || !document.getElementById) {
		return;
	}

	var menus = new Array();
	menus[0] = document.getElementById("main-nav").getElementsByTagName("ul").item(0);
	menus[1] = document.getElementById("subnav");

	for (var ii = 0; ii < menus.length; ii++) {
		var menu = menus[ii];
		if (!menu) {
			continue;
		}

		for (var jj = 0; jj < menu.childNodes.length; jj++) {
			var nav = menu.childNodes[jj];

			if (nav.nodeName != "LI") {
				continue;
			}

			// apply hover state behaviour to list item
			nav.onmouseover = hoverOn;
			nav.onmouseout = hoverOff;

			// get child divs (if any) and apply behaviour to them too
			for (var kk = 0; kk < nav.childNodes.length; kk++) {
				var navDiv = nav.childNodes[kk];
				if (navDiv.nodeName != "DIV") {
					continue;
				}
				navDiv.onmouseover = hoverOn;
				navDiv.onmouseout = hoverOff;
			}
		}
	}
}


/**
 * Adds a makeshift hover state to an element by adding the
 * word 'hover' to the element classname.
 */
function hoverOn() {
	this.className += ' hover';
}


/**
 * Removes the makeshift hover state applied by hoverOn by
 * removing the word 'hover' from the element classname.
 */
function hoverOff() {
	this.className = this.className.replace(' hover', '');
}