
// Generic page setup to initialize variables, break out
// of frames, and preload the rollover images.
var rollover_image_path = "img/";
var rollover_on_suffix = "-on.gif";
var rollover_off_suffix = "-off.gif";

// Initialize the script
function Init(FrameOK) {
	// If we're framed, break out of it, unless a parm is passed saying it's OK
	if ((FrameOK) && (self != top)) {
		top.location.href = self.location.href;
	}
	// Preload the images in the rollover array
	if (document.images) {
		rollover_load();
	}
	// Target all external links to a new window
	var CurrHost = window.location.hostname;
	for (Ctr=0;Ctr<=(document.links.length-1);Ctr++) {
		if ((document.links[Ctr].href.indexOf(CurrHost) == -1) && (document.links[Ctr].href.indexOf("http:") == 0)) {
			document.links[Ctr].target = "NewWin";
		}
	}
}

// Alias for init function
function InitRollover(FramesOK) {
	Init(FramesOK);
}

// This function loads the rollover images into the browser cache.
function rollover_load() {
	// Use the rollover array built by the caller to load the images.
	for (ctr = 0; ctr < rollover.length; ctr++) {
		var item = rollover[ctr];
		// If it's old code with a leading "~", remove it
		if (item.charAt(0) == "~") {
			item = item.substr(1,item.length);
		}
		if (item.indexOf(".") == -1) {
			// If no file extension is present, it's a primary image, so
			// preload the "on" version.
			document["on" + ctr] = new Image();
			document["on" + ctr].src = rollover_image_path + item + rollover_on_suffix;
		}
		else {
			// Otherwise it's a secondary image, so just load the filename.
			document["sec" + ctr] = new Image();
			document["sec" + ctr].src = rollover_image_path + item;
		}		
	}
}

/*
This function is called by event handlers to swap images. Any number
of parameters may be passed. If a parameter does not contain an "=",
it's a primary image, so if the object currently contains the "on"
version, reload it with the "off" version and vice-versa.
Otherwise it's a secondary image, so load the passed filename
into the specified object.
*/

function swap() {
	if (!document.images) return;
	// Iterate through all passed parameters
	for (ctr = 0; ctr < swap.arguments.length; ctr++) {
		parm = swap.arguments[ctr];
		if (parm.indexOf("=") == -1) {
			// If it's a primary image and the "off" version is
			// currently loaded, replace with the "on" version
			// and vice-versa.
			document[parm].src = (document[parm].src.indexOf(rollover_off_suffix) > -1) ? rollover_image_path + parm + rollover_on_suffix : rollover_image_path + parm + rollover_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 = rollover_image_path + arg[1];
		}
	}
}
