var ImageSwap = function()
{
	this._images = [];
}

ImageSwap.prototype.addImageAnchor = function(aHrefTagId, onImg, offImg)
{
	// Cause preload
	new Image().src = offImg;
	new Image().src = onImg;			
			
	var docElem = document.getElementById(aHrefTagId);
	docElem.onmouseover = function()
	{
		imageSwap.doMouseOver(this.id);
	}
	
	docElem.onmouseout = function()
	{
		imageSwap.doMouseOut(this.id);
	}		
		
	var imgElem = docElem.childNodes[0];

	var temp = {};
	temp.id = aHrefTagId;
	temp.img = imgElem;
	temp.anch = docElem;
	temp.onImg = onImg;
	temp.offImg = offImg;			
	temp.selected = false;
	
	//Default selected
	if(temp.selected)
	{
		temp.img.src = temp.onImg;
	}
	
	this._images.push(temp);
}

ImageSwap.prototype.select = function(aHrefTagId)
{
  try
  {
  	var imgObj = this.getImageObjectById(aHrefTagId);
	if(imgObj != null)
	{
		imgObj.selected = true;
		imgObj.img.src = imgObj.onImg;
	}
	}catch(e){}
}

ImageSwap.prototype.deselect = function(aHrefTagId)
{
	var imgObj = this.getImageObjectById(aHrefTagId);
	imgObj.selected = false;
}		

ImageSwap.prototype.doMouseOver = function(aHrefTagId)
{
	var imgObj = this.getImageObjectById(aHrefTagId);
	imgObj.img.src = imgObj.onImg;
}

ImageSwap.prototype.doMouseOut = function(aHrefTagId)
{
	var imgObj = this.getImageObjectById(aHrefTagId);
	if(!imgObj.selected)
	{
		imgObj.img.src = imgObj.offImg;
	}
}

ImageSwap.prototype.getImageObjectById = function( aHrefTagId )
{
	for(var i=0; i < this._images.length; i++)
	{
		if(this._images[i].id == aHrefTagId)
		{
			return this._images[i];
		}
	}
	return null;
}

