/*
 * File: navbar.js
 * Creator: George Ferguson
 * Created: Tue Dec 18 20:28:03 2007
 * Time-stamp: <Tue Dec 18 20:28:23 EST 2007 pcb>
 */

/* IE6 browser detect for rollover navbar */
var appName = navigator.appName; 
var appVersion = parseInt(navigator.appVersion); 
var IE6 = (appName == "Microsoft Internet Explorer" && appVersion < 7);

/*
 * current(BOOL)
 *
 * Called from a non-current navbar li `elt' to show or hide the submenu for
 * the current navbar li. It's not quite as simple as changing the
 * visibility of `current' item itself. Rather, if it's a first-level
 * item, then we have to hide/show its ul child. Otherwise (assuming a
 * a two-level navbar), we have to hide/show the ul of which it is a
 * child.
 * This could be generalized, but who needs that many levels of navbar?
 */
function current(elt,bool) {
  // Merge in IE6 hover compatibility code to this mouseover/mouseout handler
  if (IE6) {
    // bool false => current off => this elt on
    if (!bool) {
      elt.className += ' hover';
    } else {
      elt.className = elt.className.replace(' hover', '');
    }
  }
  // Ignore from current sibling or parent
  var current = document.getElementById('current');
  if (elt.parentNode.parentNode == current ||
      elt.parentNode.parentNode.className.search('currentAncestor') != -1) {
    return true;
  }
  var ul = null;
  if (current.parentNode.parentNode.className == 'currentAncestor') {
    // current is not toplevel: toggle parent which should be ul
    ul = current.parentNode;
  } else {
    // current is toplevel: toggle (first and hopefully only) ul child
    var children = current.getElementsByTagName('ul');
    if (children) {
      ul = children[0];
    }
  }
  if (ul) {
    ul.style.visibility = (bool ? 'visible' : 'hidden');
  }
  return true;
}
