// Scan webpage for images to cache
function cacheImages() {
	// Exectue function to return array with images for rollovers
	var imageNames = getName();
	var theImage = new Array();
	// Loop through the returned array of images
	for (count = 0; count < imageNames.length; count++) {
		// Filter out _x images
		if (false == (filter = imageNames[count].match(/_x$/))) {
			theImage[count] = new Image();
			theImage[count].src = imageNames[count];
		}
	}
}


// Grab names of images to cache and return an array
function getName() {
	// Set new array to hold image names
	var imageNames = new Array();
	// Set tracking variable, used to set array positions for valid entries only
	var track = 0;
	// Loop through all images in document, writing valid entries to the array imageNames
	for (count = 0; count < document.images.length; count++) {
		// If the image name is not blank
		var fileName = document.images[count].src;
		var tempName = document.images[count].name;
   		// Filter out names with nothing in the,
		if (tempName != "") {
			// Check for file format via extension...
			if (false != (ext = fileName.match(/(.jpg|.gif|.png)$/))) {
				// If match found then we know the format to use...
				if  (ext.length >= 1) {
					// Write name to array position for both up and over instances
					imageNames[track++] = (fileName);
					imageNames[track++] = (fileName.replace(/-up/, "-ov"));
				}
			}
		}
	}
	// Send the array back to calling function
	return imageNames;
}


// Swap images on page
function itemSwap(opt_name, state) {
	// Set filename and target for testing...
	var fileName = document.images[opt_name].src;
	var targetFile = opt_name;
	// Check for file format via extension...
	if (false != (ext = fileName.match(/\.{1}(jpg|gif|png){1}$/))) {
		// If match found then we know the format to use...
		if  (ext.length >= 1) {
			// Switch the image
			if (state == 'ov') {
				var newFile = fileName.replace('-up', '-' + state);

			} else if (state == 'up') {
				var newFile = fileName.replace('-ov', '-' + state);
			}
			document [opt_name].src = (newFile);
		}
	}
}