/*
 * 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.
 *
 * Adapted from http://www.alistapart.com/articles/dropdowns
 */
function init_hover() {
  //quick IE check
  if (!document.all || !document.getElementById) {
    return;
  }

  var menus = new Array();
  var navContainer = document.getElementById("propertyDisplay");
  if (navContainer != null) {
    menus[0] = navContainer.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';
  
  var viewSince = document.getElementById('viewSinceSelector');
  if (viewSince != null) {
    viewSince.style.visibility = 'hidden';
  }
  
  var sortMessages = document.getElementById('sortMessages');
  if (sortMessages != null) {
    sortMessages.style.visibility = 'hidden';
  }  
}


/**
 * 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', '');
  
  var viewSince = document.getElementById('viewSinceSelector');
  if (viewSince != null) {
    viewSince.style.visibility = 'visible';
  }
  
  var sortMessages = document.getElementById('sortMessages');
  if (sortMessages != null) {
    sortMessages.style.visibility = 'visible';
  }
}