/*
Filename: rollover.js
Desc:     Generic mouse rollover script for shared use.
Author:   Relevant Arts Enterprise, Inc. <http://www.relevantarts.com/>
          John A. Lock <jlock@relevantarts.com>
Created:  1997-Oct-15
Modified: 1997-Nov-18 Modified to swap primary and secondary images
          1997-Dec-01 Added variables for path and file extensions
          1999-Jun-17 Modified to work on WebTV
          2000-Feb-03 Modified to break frames and preload images
                      after page is loaded.
          2001-Jun-26 Modified to remove uneeded startup code
          2001-Jul-18 Modified to detect file extension as well as "~"
                      to distinguish primary and secondary rollovers 
          2002-Mar-05 Added code to target all external links to a new window
          2003-Aug-13 Change frame buster code to disable when runnning in Web Edit Pro
          2003-Nov-09 Added code to target all PDF links to a new window
          2003-Dec-10 Modified to ignore PDF's called within javascript
					2005-Jun-02 Changed frame buster code to preserve history for back button
					2006-May-05 Added new window override check for domain families
					2009-Apr-22 Changed URL property from .host to .hostname
					2011-Jan-24 - Added "new window" icon, style, and title text
*/

// 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";
var domain_family = "";
var Ctr = 0;

// Initialize the script
function Init(FrameOK) {
	// If we're framed, break out of it, unless a parm is passed saying it's OK or we're inside Web Edit Pro
	if ((!FrameOK) && (self != top) &&
			(window.location.href.indexOf("webedit") == -1) &&
			(window.location.href.indexOf("wep_temp") == -1) &&
			(window.name != "wep_temp")) {
		top.location.replace(window.location.href);
	}
	// Preload the images in the rollover array
	if (document.images) {
		rollover_load();
	}
	// Target all PDFs and external links to a new window
	if (!document.NewWin) {
		var CurrHost = window.location.hostname;
		for (Ctr=0;Ctr<=(document.links.length-1);Ctr++) {
		  var LinkHost = document.links[Ctr].hostname;
			if ((document.links[Ctr].href.indexOf(".pdf") > -1) &&
 				  (document.links[Ctr].className != "noicon") &&
					(document.links[Ctr].href.indexOf("javascript") < 0)) {
				document.links[Ctr].target = "NewWin";
				document.links[Ctr].className = "pdflink";
				if (document.links[Ctr].title == "") {
				  document.links[Ctr].title = "Opens a new window";
				}
				else {
  				document.links[Ctr].title = document.links[Ctr].title + " (Opens a new window)";
				}
			}	else if ((document.links[Ctr].href.indexOf(CurrHost) < 0) &&
								 (document.links[Ctr].href.indexOf("http") == 0) &&
        				 (document.links[Ctr].className != "noicon") &&
								 (domain_family.indexOf(LinkHost) == -1)) {
				document.links[Ctr].target = "NewWin";
				document.links[Ctr].className = "extlink";
				if (document.links[Ctr].title == "") {
				  document.links[Ctr].title = "Opens a new window";
				}
				else {
  				document.links[Ctr].title = document.links[Ctr].title + " (Opens a new window)";
				}
			}
		}
	}
}

// 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];
		}
	}
}

