////////////////////////////////////////////////////////////////////////
// Filename: rollover.js
// 
////////////////////////////////////////////////////////////////////////

// Obtain the domain of the current window and set this script's domain 
// equal to it. (temporarily disabled)

//if (document.images) {
//	parts = window.location.hostname.split(".");
//	if (parts.length > 1) {
//		document.domain = parts[parts.length - 2] + "." + 
//			parts[parts.length - 1];
//	}
//}

// Load the images to be used by the swap() function

if (document.images) {
	// If an image_path variable is not defined, use a default value.
	if (typeof(image_path) == "undefined") {
		var image_path = "images/";
	}
	// If an on_suffix variable is not defined, use a default value.
	if (typeof(on_suffix) == "undefined") {
		var on_suffix = "-on.gif";
	}
	// If an off_suffix variable is not defined, use a default value.
	if (typeof(off_suffix) == "undefined") {
		var off_suffix = "-off.gif";
	}

	// Use the rollover array built by the caller to load the images
	for (var ctr = 0; ctr < rollover.length; ctr++) {
		var item = rollover[ctr];

		if (item.substring(0,1) != "~") {
			// If the first character of the item is not "~", it's a
			// primary image, so preload the "on" versions.
			document["on" + ctr] = new Image();
			document["on" + ctr].src = image_path + item + on_suffix;
		}
		else {
			// Otherwise it's a secondary image, so just load the filename.
			document["sec" + ctr] = new Image();
			document["sec" + ctr].src = image_path + item.substring(1,item.length);
		}		
	}
}

// This function is called by event handlers to swap images. Any number
// parameters may be passed. If a parameter contains an "=", it's a
// secondary image, so load the passed filename into the specified object.
// Otherwise it's a primary image, so if the object currently contains the
// "on" version, reload it with the "off" version and vice-versa.

function swap() {
	if (document.images) {
		// Iterate through all passed parameters
		for (var ctr = 0; ctr < swap.arguments.length; ctr++) {
			var parm = swap.arguments[ctr];
			if (parm.indexOf("=") == -1) {
				// If it's a primary image and the "on" version is
				// currently loaded, replace with the "off" version
				// and vice-versa.
				document[parm].src =
					(document[parm].src.indexOf(on_suffix) == -1) ?
						image_path + parm + on_suffix :
						image_path + parm + off_suffix;
			}
			else {
				// Otherwise, it's a secondary image, so split at the "="
				// and load the left-side object with the right-side image.
				arg = parm.split("=");
				document[arg[0]].src = image_path + arg[1];
			}
		}
	}
}

