// This toggles an images source based on a predefined suffix to use as a constant
// and a reference to an image

// The suffix constant
var HOVER_SUFFIX = '_over'; 
	
function toggleImageOn(imageToToggle) {
	// Find the position of the last period which is where the extension begins
	var extensionPosition = imageToToggle.src.lastIndexOf('.');
	
	// Save the extension to a var
	var extension = imageToToggle.src.substring(extensionPosition, imageToToggle.src.length);
	
	// Grab the file name without the extension
	var fileName = imageToToggle.src.substring(0, extensionPosition);
	
	// Image source with hover suffix added
	imageToToggle.src = fileName + HOVER_SUFFIX + extension;
}

function toggleImageOff(imageToToggle) {
	// Find the position of the last period which is where the extension begins
	var extensionPosition = imageToToggle.src.lastIndexOf('.');
	
	// Save the extension to a var
	var extension = imageToToggle.src.substring(extensionPosition, imageToToggle.src.length);
	
	// Grab the file name without the extension
	var fileName = imageToToggle.src.substring(0, extensionPosition);
	
	// Apply the image source without hover suffix as long as that suffix is there
	if (imageToToggle.src.lastIndexOf(HOVER_SUFFIX) != -1) {
		imageToToggle.src = fileName.substring(0, fileName.length-HOVER_SUFFIX.length) + extension;
	}
}

// This allows a containing element of an image to
// be call the toggle image with just a reference to this
// if the image is the first child.
function toggleChildImageOn(whosChildImage) {
	toggleImageOn(whosChildImage.firstChild);	
}

function toggleChildImageOff(whosChildImage) {
	toggleImageOff(whosChildImage.firstChild);	
}