var IMAGE_PATH = "/images/"
var BTN_UP = "";
var BTN_OVER = "over";
var BTN_DOWN = "down";


function loadImage(url)
{
	var img = new Image();

	img.src = url;

	return img;
}



function cacheImage(imageName)
{
	var d = document;
	var arImages;


	// Creates document's "preloadImages" array so the images don't fall out of scope.
	// This is because the loadImage function does not block--it returns immediately.
	// This way, we'll always have a reference to the images as long as the page is open.
	if(!d.preloadImages) d.preloadImages = new Array();
	
	return d.preloadImages[d.preloadImages.length] = loadImage(imageName);
}



function cacheRollover(baseName, imgPath)
{
	if (!imgPath) imgPath = IMAGE_PATH;

	cacheImage(IMAGE_PATH + baseName + BTN_UP + ".gif");
	cacheImage(IMAGE_PATH + baseName + BTN_OVER + ".gif");
	cacheImage(IMAGE_PATH + baseName + BTN_DOWN + ".gif");
}



/*---------------------------------------------------------
 For all of these img<Event> functions, the image's id is
 assumed to be the same as the base graphic file name for that
 particular image.

 Hence, the home button's id is "Home" which corresponds to the
 three images, "Home.gif", "Home_over.gif" and "Home_down.gif".

 The over and down suffixes are defined above in the three
 constants BTN_UP, BTN_OVER and BTN_DOWN.
-----------------------------------------------------------*/
function imgOver(img)
{
	// Set an "expand-o" property, oldSrc to remember the image's current src.
	// We'll use this property later to restore the image on mouseout.
	img.oldSrc = img.src;

	// We generate a new src by using the image's id.  So if image id is "Home", the
	// new mouseover image should be called Home_over.gif
	img.src = IMAGE_PATH + img.id + BTN_OVER + ".gif";
}



function imgOut(img)
{
	// If an oldSrc has been remembered, restore it, else use the image's id to generate
	// a new image src.
	if (img.oldSrc)
		img.src = img.oldSrc;
	else
		img.src = IMAGE_PATH + img.id + ".gif";
}


function imgDown(img)
{
	// Use the image's id to choose a proper "down" button graphic.
	img.src = IMAGE_PATH + img.id + BTN_DOWN + ".gif";
}


function setButtonState(btnName, newState)
{
	document.images[btnName].src = document.images[btnName].src.replace(".gif", newState + ".gif");
}
