// code for primary navigation rollovers

// How it works:

// Rollovers are inactive until nav_active is set to
// true, which is done by navstart(), which should be called
// at the bottom of each page. navstart() records the current
// section and sets the current section's main nav box's
// background color.

// When mouse passes over any link in one of the main nav boxes,
// onmouseover() calls navon(). This function resets any previous
// rollovers if necessary, sets the new box's background, and turns
// on the rollover link's highlighted state.

// When mouse leaves a link, onmouseout() calls navoff(), which restores
// the current rollover item, and starts a timer to call navreset().

// navreset() restores the nav box backgrounds back to their initial states.

// colors of the nav boxes
var nav_color_normal = "#89b2bf";
var nav_color_highlight = "#66cccc";


// active flag - allows rollovers to operate - set to true by navstart()
var nav_active = false;

// this page's section - set by navstart()
var current_section = "";

// current rollover section and item
var ro_section = "";
var ro_item = "";

// timer for delayed reset
var timerid = null;

//
// initialization - call at the end of every page
//
function navstart(section) {
  current_section = section;
  if (section != "") {
    setcellcolor("td"+section, nav_color_highlight);
    highlightimage(section);
  }
  nav_active = true;
}

//
// call when mouse passes over any graphic in a box
//
function navon(section, item) {
  if (timerid != null) {
    clearTimeout (timerid);
    timerid = null;
  }
  if (nav_active) {
    // swap in image rollover
    if (item != "") {
      highlightimage(item);
      ro_item = item;
    }
    // turn off previous section highlighting
    if (ro_section != "" && ro_section != section)
      navreset();
    // highlight new section
    if (section != current_section) {
      setcellcolor("td"+section, nav_color_highlight);
      highlightimage(section);
    }
    ro_section = section;
  }
}

//
// call when mouse leaves any graphic in a box
//
function navoff() {
  if (nav_active) {
    // swap out image rollover
    if (ro_item != "") {
      unhighlightimage(ro_item);
      ro_item = "";
    }
    // start delay to restore background color
    timerid = setTimeout("navreset()", 50); // last arg is delay in milliseconds
  }
}

//
// restore box backgrounds and box heading rollovers
//
function navreset() {
  if (timerid != null) {
    clearTimeout (timerid);
    timerid = null;
  }
  if (ro_section != "") {                              // if a rollover section is active,
    if (ro_section != current_section) {               // and if it's not the current page's section,
      setcellcolor("td"+ro_section, nav_color_normal); // set its background to normal color
      unhighlightimage(ro_section);                    // turn off the section heading
    }
    ro_section = "";                                   // forget the rollover section
  }
}

function setcellcolor(cellid, color) {
  var obj = MM_findObj(cellid);
  if (obj) {
    if (obj.style)
      obj = obj.style;
    obj.backgroundColor = color;
  }
}

//
// swap in an image's highlighted version
//
function highlightimage(imageid) {
  var obj = MM_findObj(imageid);
  if (obj) {
    var i = obj.src.lastIndexOf("_hi.gif");
    if (i < 0) {
      i = obj.src.lastIndexOf(".gif");
      if (i >= 0) {
        obj.src = obj.src.substring(0,i)+"_hi.gif";
      }
    }
  }
}
//
// swap in an image's unhighlighted version
//
function unhighlightimage(imageid) {
  var obj = MM_findObj(imageid);
  if (obj) {
    var i = obj.src.lastIndexOf("_hi.gif");
    if (i >= 0) {
      obj.src = obj.src.substring(0,i)+".gif";
    }
  }
}
