/******************************************************************************
* Filename:    iehover.js                                                     *
* Description: This Javascript implements a sort of "hover" capability on     *
*              Internet Explorer. It's not particularly useful to call this   *
*              page from other browsers, but it shouldn't hurt. To make this  *
*              work, apply the same CSS to a class called ".over" as you do   *
*              to the CSS ":hover" pseudo-class.                              *
* Author:      Michael A. Smith and Dan Crane                                 *
* Modified:    2006-11-21                                                     *
******************************************************************************/
/** This function takes a PARENT ELEMENT ID and the CHILD ELEMENT NODENAME as
    arguments. It will make a child element have a class of "over" if the 
    mouse is over that element. */
function makeHoverById(id, tNode) {

  //check for basic IE functionality
  if(!document.all) return;
  
  navRoot = document.getElementById(id);
  
  //iterate through the children of navRoot
  for (var i = 0; i < navRoot.childNodes.length; i++) {
  
    //node is the element at the current iteration
    node = navRoot.childNodes[i];
    
    //only modify nodes with tNode as a nodeName  
    if (node.nodeName != tNode) continue;
    
    node.onmouseover = function() {
      this.className += " over";
      hideControls(navRoot);
    }

    node.onmouseout = function() {
      this.className = this.className.replace(" over", "");
      showControls(navRoot);
    }
    
  } //end for
} //end makeHoverById

/** hides controls that may collide with the hovered item */
function hideControls(menu) {
  var controls = document.getElementsByTagName("SELECT");
  var top = 289;
  for (var i = 0; i < controls.length; i++) {
    if (getTop(controls[i]) < top) hide(controls[i]);
  }
}

/** shows controls that may collide with the hovered item */
function showControls(menu) {
  var controls = document.getElementsByTagName("SELECT");
  for ( var i = 0; i < controls.length; i++) {show(controls[i]);}
}

/** not implemented */
function hasCollision(obj1, obj2) {
  if (getBottom(obj1) < getTop(obj2))    return false;
  if (getRight(obj1)  < getLeft(obj2))   return false;
  if (getLeft(obj1)   > getRight(obj2))  return false;
  if (getTop(obj1)    > getBottom(obj2)) return false;
  return true;
}

/** not implemented */
function getLeft(element) {
  var x;
  x = element.offsetLeft;
  if (element.offsetParent == null) return x;
  return x + getLeft(element.offsetParent);
}

/** finds the top of an element in pixels */
function getTop(element) {
  var y;
  y = element.offsetTop;
  if (element.offsetParent == null) return y;
  return y + getTop(element.offsetParent);
}

/** not implemented */
function getRight(element){return element.offsetWidth + getLeft(element);}

/** not implemented */
function getBottom(element){return element.offsetHeight + getTop(element);}

// These should probably go in some kind of library.
/** hides a given element */
function hide(element){element.style.visibility = "hidden";}

/** shows a given element */
function show(element){element.style.visibility = "visible";}
