// Swap images
var swapped = false; // Declares that no images are currently swapped.
var active_extension = "_on"; // Sets the filename extension for image active states.
var restore_info = new Array(); // Holds the image object names and urls for swapped images.

function swapImg(){ // Swaps and restores single or multiple images. Called by any event handler, usually onMouseOver.
	if (document.images && loaded == true && swapped == false){ // Performs if the images[] array (JavaScript 1.1 and higher) exists and if the loadImg function has completed.
		for (var i = 0; i < swapImg.arguments.length; i++){ // Loops for each set of two arguments (image name and url) passed by the event handler.
			restore_info[i * 2] = swapImg.arguments[i]; // Assigns the image name to the restore_info[] array.
			restore_info[i * 2 + 1] = document[swapImg.arguments[i]].src; // Assigns the original url to the restore_info[] array.
			document[swapImg.arguments[i]].src = document[swapImg.arguments[i]].src.substring(0, document[swapImg.arguments[i]].src.lastIndexOf('\.')) + active_extension + document[swapImg.arguments[i]].src.substring(document[swapImg.arguments[i]].src.lastIndexOf('\.')); // Assigns the new url to the image object.
		}
	} else if (document.images && loaded == true && swapped == true){ // Restores all swapped but non-locked images to their original urls. Called by any event handler, usually onMouseOut.
		for (var i = 0; i < restore_info.length; i += 2) document[restore_info[i]].src = restore_info[i + 1]; // Assigns the original url to the image object.
		restore_info = new Array(); // Resets the saved restore information.
	}
	swapped = !swapped; // Flips the swapped flag between swap and restore functionality.
}
