/*
 * 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 items = new Array();
  var parentItems = new Array();
  var par  = document.getElementById("resultsLB");
  var nav = document.getElementById("nav");
  parentItems.push(par);
  parentItems.push(nav);

  for(p=0; p < parentItems.length; p++ ) {
    if (parentItems[p] != null) {
      items = parentItems[p].getElementsByTagName('li');

      for (var ii = 0; ii < items.length; ii++) {
        var item = items[ii];
          // apply hover state behaviour to list item
          item.onmouseover = hoverOn;
          item.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', '');
}