/******************************************************
 autoRollover.js  v1.0
Byron Tredwell (byron@NOSPAM.blastradius.com)
******************************************************/

function initAutoRoll(dwnSrc){
  var docImages = document.images.length;
  var matchPattern = /_auto_off./;
  for(i=0; i<docImages ;i++){
    var thisImg = document.images[i];
    if(matchPattern.test(thisImg.src)){
      var preLoad    = new Image();
      preLoad.src    = thisImg.src.replace(matchPattern,"_auto_on.");
      thisImg.onImg  = preLoad.src;
      if(dwnSrc){
        preLoad.src    = thisImg.src.replace(matchPattern,"_auto_dwn.");
        thisImg.dwnImg = preLoad.src;
      };
      thisImg.offImg = thisImg.src;
      addEvents(thisImg,dwnSrc);
    }
  }
}

function aRollOn(img){
  if(img.onImg)
  img.src = img.onImg;
}
function aRollOff(img){
  if(img.offImg)
  img.src = img.offImg;
}
function aMouseDown(img){
  if(img.dwnImg)
  img.src = img.dwnImg;
}
function aMouseUp(img){
  if(img.onImg)
  img.src = img.onImg;
}

function addEvents(img,dwnSrc){
    img.onmouseover = function(){aRollOn(img)};
    img.onmouseout  = function(){aRollOff(img)};
    if(dwnSrc) img.onmouseup   = function(){aMouseUp(img)};
    if(dwnSrc) img.onmousedown =  function(){aMouseDown(img)};
}

function removeEvents(img,dwnSrc){
    img.onmouseover = function(){return false;};
    img.onmouseout  = function(){return false;};
    if(dwnSrc) img.onmouseup   = function(){return false;};
    if(dwnSrc) img.onmousedown =  function(){return false;};
}
