/*
 *****************************************************************
 * soopa-rollovers.js
 * 7/28/2001
 * http://webapp.youngpup.net/?request=/snippets/soopa-rollovers.xml
 ******************************************************************

 Documentus:
 
 1. link to javascript file (in <head> section):
    <script language="javascript" src="rollovers.js"></script>
    
 2. add imgSetup() function to onload attribute of <body> tag
    <body onload="imgSetup()">

 3. add hsrc attribute to <img> tags with "hover" image src: 
    <img src="normal.gif" hsrc="rollover.gif" />

 4. (optionally) add dsrc attribute to image tags with click "down" image src: 
    <img src="button-up.gif" hsrc="button-hover.gif" dsrc="button-down.gif" />

*/

function imgSetup() {
  var img, sh, sn, sd
  for (var i = 0; (img = document.images[i]); i++) {
    if (img.getAttribute) {

      sn = img.getAttribute("src");
      sh = img.getAttribute("hsrc");
      sd = img.getAttribute("dsrc");

      if (sn != "" && sn != null) {
        img.n = new Image();
        img.n.src = img.src;
      
        if (sh != "" && sh != null) {
          img.h = new Image();
          img.h.src = sh;
          img.onmouseover = imgSwapOn
          img.onmouseout  = imgSwapOff
        }

        if (sd != "" && sd != null) {
          img.d = new Image();
          img.d.src = sd;
          img.onmousedown = imgSwapDown
        }
      }
    }
  }
}

function imgSwapOn() {
  this.src = this.h.src;
}

function imgSwapOff() {
  this.src  = this.n.src;
}

function imgSwapDown() {
  this.src  = this.d.src;
  this.temp = typeof(document.onmouseup) != 'undefined' && typeof(document.onmouseup) != 'unknown' ? document.onmouseup : "";
  imgSwapUp.img = this;
  document.onmouseup = imgSwapUp;
}

function imgSwapUp() {
  var ths = imgSwapUp.img;
  ths.src = ths.n.src;
  if (ths.temp) document.onmouseup = ths.temp;
}
