/**
 * MSIE Drop-down menu implementation
 *
 * Required for MSIE only as it does not support the hover psuedo
 * class for anything other than links.
 * Recurses an unordered list, adding mouseover and mouseout events
 * to li nodes. Combined with CSS a multi-level drop-down list can be created.
 *
 * @package   TheBeastlyBeasts
 * @author    PBM Web Development <enquiries@pbm-webdev.co.uk>
 * @copyright 2006 PBM Web Development. All rights reserved.
 * @version   CVS: $Id: msiemenu.js,v 1.1 2006/07/29 12:21:08 Chris Exp $
 * @since     Release 1.0.0
 */

/**
 * Determines the root of the list to recurse
 * then passes this to the recursive function
 */
function startList()
{
  var navRoot;


  /* Only do this in MSIE */
	if (document.all && document.getElementById) {
    navRoot = document.getElementById("nav");
    addOnMouseEvents(navRoot, 0);
	}
}

/**
 * Recurse the navigation menu tree adding mouseover and mouseout events
 * to all the <li> nodes
 *
 * @param  object  root root of the current level
 * @param  integer level level within the tree
 */
function addOnMouseEvents(root, level)
{
  var i, j;
  var node, listNode;

  /* Look at each of the child nodes of root */
  for (i = 0; i < root.childNodes.length; i++) {
  	node = root.childNodes[i];

    /* If a node is a list look for the list items */
    if (node.nodeName == "UL") {
      for (j = 0; j < node.childNodes.length; j++) {
        listNode = node.childNodes[j];

        /* Only deal with list items */
      	if (listNode.nodeName == "LI") {
          /* Add the mouse events to the list item */
      		listNode.onmouseover = function()
          {
      			this.className += " over" + level;
      		}
      		listNode.onmouseout = function()
          {
      			this.className = this.className.replace(" over" + level, "");
      		}

          /* Recurse the tree */
          addOnMouseEvents(listNode, level + 1);
        }
      }
  	}
  }
}
addLoadEvent(startList);
//--><!]]>