// Automatically preloads the images.
function loadImg(URL)
{
	if (document.images) 
	{
    	newImg = new Image();
    	newImg.src = URL;
    	return newImg;
	}
}

// The images objects.  Stores all the image settings.
function objImg (imgId, offImgURL, overImgURL, onImgURL)
{
	this.imgId = imgId;
	this.state = "off";
	
	if (offImgURL)
	{
		this.offImg = loadImg(offImgURL);
	}
	if (overImgURL)
	{
		this.overImg = loadImg(overImgURL);
	}
	if (onImgURL)
	{
		this.onImg = loadImg(onImgURL);
	}
}

/* Image swapping function
 * imgNum = number of image in the imageArray
 * newState = which state should the image be changed to (accepts "over", "off", "on"
 */
function swapImg (imgNum, newState)
{
	var img = document.getElementById(imageArray[imgNum].imgId);
	
	if (newState == "over")
	{
		if(activeRollover || imageArray[imgNum].state != "on")
		{
			img.src = imageArray[imgNum].overImg.src;
		}
	}
	
	if (newState == "off")
	{
		if (imageArray[imgNum].state == "on")
		{
			img.src = imageArray[imgNum].onImg.src;
		}
		else
		{
			img.src = imageArray[imgNum].offImg.src;
		}
	}
	
	if (newState == "on")
	{
		imageArray[imgNum].state = "on";
		img.src = imageArray[imgNum].onImg.src;
	}
}

// Create the image objects (new objImg(imageId, offImg, overImg, onImg)).
var img1 = new objImg('img01', '/_images/home/FIND_CLUB.png', '/_images/home/FIND_CLUB_over.png');
var img2 = new objImg('img02', '/_images/home/FREE_TrIAL.png', '/_images/home/FREE_TrIAL_over.png');
var img3 = new objImg('img03', '/_images/home/WORLDCLASS.png', '/_images/home/WORLDCLASS_over.png');

// Pass each of the images created above into this array.
var imageArray = new Array(img1, img2, img3);

// Sets if the currently "on"/active image should allow image swapping onMouseOver.
var activeRollover = false;