/**
 * This script provides functions for the operation of the primary and secondary nav
 * controls
 *
 * Author: Dylan Smith <dylansmith@gmail.com>
 * Date: 11 May 2006
 */

/**
 * Primary nav script initialiser
 */
function init_primaryNav() {
	forceParentLinkHighlights();
}

/**
 * The A elements in the primary-level lists that control the showing and hiding
 * of the second-level lists have CSS to trigger their image rollover states (using
 * background positioning. However, when you roll off the A element onto the secondary
 * list, the rollover state reverts back to "off". This method ensures that the rollover
 * state remains "on" while the child list is being hovered over.
 */
function forceParentLinkHighlights() {
	var nav = document.getElementById('primary_nav');
	if (!nav) return;
	var li = nav.getElementsByTagName('li');
	for (var i=0; i< li.length; i++)
	{
		if (li[i].parentNode == nav) {
			ul = li[i].getElementsByTagName('ul')[0];
			ul.onmouseover = function() {
				Element.addClassName(this.parentNode.getElementsByTagName('a')[0],'hover')
			}
			ul.onmouseout = function() {
				Element.removeClassName(this.parentNode.getElementsByTagName('a')[0],'hover');
			}
		}	
	}
}

/**
 * initialise primary nav scripting onload
 */
Event.observe(window,'load',init_primaryNav);