var hoverPreloadArray = new Array();

function autoPreload() {
  hoverConfigureByTag("img");
}

function hoverConfigureByTag(tag) {
  var objs, i, src, qual, img;
  objs = document.getElementsByTagName(tag);
  for(i = 0; i < objs.length; i++) {
    src = objs[i].getAttribute("src");
    qual = src.substring(src.lastIndexOf("_"), src.lastIndexOf("."));
    if(qual == "_off" || qual == "_on") {
      img = hoverPreloadArray.push(new Image());
      hoverPreloadArray[img-1].setAttribute("src", src.substring(0, src.lastIndexOf("_")) + (qual == "_off" ? "_on" : "_off") + src.substr(src.lastIndexOf(".")));

      if(qual == "_off") {        
        objs[i].onmouseover = function() {
          hoverOn(this);
        }
        objs[i].onmouseout = function() {
          hoverOff(this);
        }
      }
    }
  }
}  

function hoverOn(obj) {
  var src;
  src = obj.getAttribute("src");
  qual = src.substring(src.lastIndexOf("_"), src.lastIndexOf("."));
  if(qual == "_off") {
    obj.setAttribute("src", src.substring(0, src.lastIndexOf("_")) + "_on" + src.substr(src.lastIndexOf(".")));
  }
}

function hoverOff(obj) {
  var src;
  src = obj.getAttribute("src");
  obj.setAttribute("src", src.substring(0, src.lastIndexOf("_")) + "_off" + src.substr(src.lastIndexOf(".")));
}
