/**
 * KZSU-specific javascript image rollover routines.
 * Meant as a temporary shim until we retire Hannah's
 * godawful rollovers for good.
 *
 * Inspired by:
 * http://onlinetools.org/articles/unobtrusivejavascript/chapter2.html
 *
 * Usage:
 * 1. call hookAllImages() from body onLoad.
 * 2. Set all nav <img> tags to class="navroll" src="/images/OTHER_PAGE.gif",
 *    except for the nav image that represents that page, which should not have
 *    that class, and should be src="/images/THISPAGE_mo.gif".
 * 3. Set img tag's id attribute. if <img class="navroll" id="yourmom"/>, then
 *    The rollon image is /images/yourmom_mo.gif, and the rolloff image is
 *    /images/yourmom.gif.
 * 
 * @author Andrew Widdowson <apw>
 */

/**
 * mouse rollover routine
 * @param image_element the <img /> element to act on
 */
function mouseOn(image_element) {
  image_element.src="/images/"+image_element.id+"_mo.gif";
  var allImages = document.getElementsByTagName('img');
  for (i=0; i< allImages.length; ++i) {
    if (allImages[i].className == 'navroll' &&
        allImages[i] != image_element) {
      mouseOff(allImages[i]);
    }
  }
}

/**
 * mouse rolloff routine
 * @param image_element the <img /> element to act on
 */
function mouseOff(image_element) {
  image_element.src="/images/"+image_element.id+".gif";
}

/**
 * infect all images of class="navroll" with roll on/off hooks.
 */
function hookAllImages() {
  var allImages = document.getElementsByTagName('img');
  for (i=0; i< allImages.length; ++i) {
    if (allImages[i].className == 'navroll') {
      allImages[i].onmouseover = function() { mouseOn(this); };
      allImages[i].onmouseout = function() { mouseOff(this); };
    }
  }
}

/* Legacy crap. */
function heartOn()  {
  document.images.heart.src="/images/heart_listen.gif";
}

function heartOff()  {
  document.images.heart.src="/images/heart_beat.gif";
}
