

/** start ImageSwap object **/

/*
usage:

1. save images in a folder with the following naming convention:

image1name.gif  - default image
image1name.on.gif - rollover image
image1name.down.gif - rollover image
...
2. add the following to your page in a script tag:

imageswap.add('path/to/images',['image1name','image2name',...]);

3. add these calls to your a tags:

<a href="#" onmouseover="imageswap.over('image1name');" onmouseout="imageswap.out('image1name'); onmousedown="imageswap.down('image1name');" ></a><img name="image1name"  src="..."></a>
...

*/
function ImageSwap() {
  this.imagesDefault = new Object();
  this.imagesOn = new Object();
  this.imagesDown = new Object();
}

ImageSwap.prototype.add = 
function (arg_path,arg_names) {
  
  if(!document.images) return;

  //preload images
  for (var i=0; i<arg_names.length;i++) {
    var name = arg_names[i];

    if (this.imagesDefault[name]) {
      //there is existing image with this name
      //notify that there was a name collision
      alert("ImageSwap Error!\nThere is already a image with this name: " + name);
    }
    this.imagesDefault[name] = new Image();
    this.imagesDefault[name].src = arg_path + "/" + name + ".gif";
    this.imagesOn[name] = new Image();
    this.imagesOn[name].src = arg_path + "/" + name + ".on.gif";
    this.imagesDown[name] = new Image();
    this.imagesDown[name].src = arg_path + "/" + name + ".down.gif";

  }
}

ImageSwap.prototype.addMouseOver = 
function (arg_path,arg_names) {
  
  if(!document.images) return;

  //preload images
  for (var i=0; i<arg_names.length;i++) {
    var name = arg_names[i];

    if (this.imagesDefault[name]) {
      //there is existing image with this name
      //notify that there was a name collision
      alert("ImageSwap Error!\nThere is already a image with this name: " + name);
    }
    this.imagesDefault[name] = new Image();
    this.imagesDefault[name].src = arg_path + "/" + name + ".gif";
    this.imagesOn[name] = new Image();
    this.imagesOn[name].src = arg_path + "/" + name + ".on.gif";
  }
}

ImageSwap.prototype.addMouseDown = 
function (arg_path,arg_names) {
  
  if(!document.images) return;

  //preload images
  for (var i=0; i<arg_names.length;i++) {
    var name = arg_names[i];

    if (this.imagesDefault[name]) {
      //there is existing image with this name
      //notify that there was a name collision
      alert("ImageSwap Error!\nThere is already a image with this name: " + name);
    }
    this.imagesDefault[name] = new Image();
    this.imagesDefault[name].src = arg_path + "/" + name + ".gif";
    this.imagesDown[name] = new Image();
    this.imagesDown[name].src = arg_path + "/" + name + ".down.gif";
  }
}

ImageSwap.prototype.over = 
function (which) {

  if(document.images){
    if (document.images[which]) {
      document.images[which].src = this.imagesOn[which].src; 
    } else if (document.getElementsByName) {
      //it wasn't img tag try getting it by name anyway (might be a submit button)
      document.getElementsByName(which)[0].src = this.imagesOn[which].src;
    }
  }
}

ImageSwap.prototype.out = 
function (which) {
  if(document.images){
    if (document.images[which]) {
      document.images[which].src = this.imagesDefault[which].src;
    } else if (document.getElementsByName) {
      //it wasn't img tag try getting it by name anyway (might be a submit button)
      document.getElementsByName(which)[0].src = this.imagesDefault[which].src;
    }
  }
}

ImageSwap.prototype.down = 
function (which) {
  if(document.images){
    if (document.images[which]) {
      document.images[which].src = this.imagesDown[which].src;
    } else if (document.getElementsByName) {
      //it wasn't img tag try getting it by name anyway (might be a submit button)
      document.getElementsByName(which)[0].src = this.imagesDown[which].src;
    }

  }  
}



//create the global rollovers object
var imageswap = new ImageSwap();


/** end ImageSwap object **/

/** global open pop up script */
function openPopup(loc, name, width, height) {
    popup = window.open(loc, name, 'toolbar=no,location=no,directories=no,status=no,scrollbars=no,resizable=yes,' +
		         'menubar=no,width='+ width +',height='+ height +',dependent=yes');
    if (popup) popup.focus();
}

function openPopupNoResize(loc, name, width, height) {
    popup = window.open(loc, name, 'toolbar=no,location=no,directories=no,status=no,scrollbars=no,resizable=no,' +
		         'menubar=no,width='+ width +',height='+ height +',dependent=yes');
    if (popup) popup.focus();
}












