/////////////////////////////////////////////////////////////////////////
//      _
//    <' )_,  RealDecoy
//    (    ) 
//   ~~~~~~~~
//
/////////////////////////////////////////////////////////////////////////

/*	---------------------------------------------------------------------	
	FUNCTION NAME: externalLinks

	PURPOSE: Finds any <A> tag and looks to see if it has a rel="external".
	If so, it adds the "target" attribute with a value of "_blank".  In
	this way, you have valid XHTML code.
---------------------------------------------------------------------	*/
function externalLinks() {
	if (document.getElementsByTagName) {
		var anchors = document.getElementsByTagName("a");
		for (var i = 0; i < anchors.length; i++) {
			var anchor = anchors[i];
			if (anchor.getAttribute("href") && anchor.getAttribute("rel") == "external") {
				anchor.target = "_blank";
			}
		}
		
		//	Also need to get areas from an image map
		var anchors = document.getElementsByTagName("area");
		for (var i = 0; i < anchors.length; i++) {
			var anchor = anchors[i];
			if (anchor.getAttribute("href") && anchor.getAttribute("rel") == "external") {
				anchor.target = "_blank";
			}
		}
	}
}
/*	---------------------------------------------------------------------
	FUNCTION NAMES: assignRollOvers, lookForRollOverObjects,
	assignRollOverStates

	PURPOSE: Three functions that automatically add rollover states to
	images without needing to add onMouseOver events within the <A>
	tags.
	
	* assignRollOvers() takes the IDs of an element where the linked images
	are kept.  It cycles through the IDs passed to it and passes each ID to
	the lookForRollOverObjects function.
	
	* lookForRollOverObjects() move through the DOM tree and look for <A>
	tags.  When you find one, pass it as an object to assignRollOverStates.
	
	* assignRollOverStates() adds an onMouseOver and onMouseOut events that
	automatically looks through child elments of the <A> tag for an <IMG>
	(so there can also be test and other stuff within the <A> tag.
	 When it finds an <IMG>, it swaps its source attributes PROVIDED THAT
	 the images are named the same thing, but ending with "-on" and "-off."
	 
	 Also, if the IMG has a class "current", it will not change it in
	 case the nav image is different on a certain page and should not
	 be swapped out.
---------------------------------------------------------------------	*/
function assignRollOvers() {
	if(document.getElementById) {
		for(var a = 0; a < assignRollOvers.arguments.length; a++) {
			var rootNavNode = document.getElementById(assignRollOvers.arguments[a]);
			lookForRollOverObjects(rootNavNode);
		}
	}
}

function lookForRollOverObjects(navNode) {
	// Cycle through all of the elements of the element
	
	for (var i = 0; i < navNode.childNodes.length; i++) {
		var tempNode = navNode.childNodes[i];

		// If we hit an <A> tag, then...
		if (tempNode.nodeName=="A") {
			assignRollOverStates(tempNode);
		} else {
			if(tempNode.childNodes) {
				lookForRollOverObjects(tempNode);
			}					
		}
	}
}

function assignRollOverStates(navNode) {
	// Now, onMouseOver the <A> tag
	navNode.onmouseover = function() {
		for (var j=0; j < this.childNodes.length; j++) {
			if (this.childNodes[j].tagName=="IMG"  && (this.childNodes[j].className.indexOf("current") < 0)) {
				var tmpImgSrc = this.childNodes[j].src;
				tmpImgSrc = tmpImgSrc.replace("-off", "-on");
				this.childNodes[j].src = tmpImgSrc;
				break;
			}
		}
	}

	// Now, onMouseOut the <A> tag
	navNode.onmouseout = function() {
		for (var j=0; j < this.childNodes.length; j++) {
			if (this.childNodes[j].tagName=="IMG"  && (this.childNodes[j].className.indexOf("current") < 0)) {
				var tmpImgSrc = this.childNodes[j].src;
				tmpImgSrc = tmpImgSrc.replace("-on", "-off");
				this.childNodes[j].src = tmpImgSrc;
				break;
			}
		}
	}
}




/*	---------------------------------------------------------------------	
	FUNCTION NAME: setDropDowns

	PURPOSE: Apply events to list items (<li>s) to allow for dropdown events
	since there is not complete support for :hover on objects other
	than <A> tags (e.g. IE).

	This fucntion takes IDs of <UL>s or <OL>s that are passed to it and
	applies onmouseover and onmouseout events to the <LI>s within those
	list objects.
	
	TO EXECUTE: Call with window.onload, passing the IDs of the objects
	that this function will be applied to.
---------------------------------------------------------------------	*/

var navRoot;
function setDropDowns() {
	if(document.all) {
		for (var a = 0; a < setDropDowns.arguments.length; a++) {	
			navRoot = document.getElementById(setDropDowns.arguments[a]);
			for (i=0; i<navRoot.childNodes.length; i++) {
				var node = navRoot.childNodes[i];
				if (node.nodeName=="LI") {
					node.onmouseover=function() {
						for (var j=0; j < this.childNodes.length; j++) {
							if (this.childNodes[j].tagName=="UL") {
								this.childNodes[j].className = this.childNodes[j].className.replace("no_show", "block");
								break;
							}
						}
					}
		
					node.onmouseout=function() {
						for (var j=0; j < this.childNodes.length; j++) {
							if (this.childNodes[j].tagName=="UL") {
								this.childNodes[j].className = this.childNodes[j].className.replace("block", "no_show");
								break;
							}
						}
					}
				}
			}
		}
	}
}



/*	---------------------------------------------------------------------
	FUNCTION NAME: preLoadNav
	
	PURPOSE: Standard preloader -- send absolute URL of the iamges and
	the function does the rest.
---------------------------------------------------------------------	*/
function preLoadNav() {
	var preLoadHolder = new Array(preLoadNav.arguments.length);
	for (var i = 0; i < preLoadNav.arguments.length; i++) {
		preLoadHolder[i] = new Image();
		preLoadHolder[i].src = preLoadNav.arguments[i];
	}
}


/*	---------------------------------------------------------------------
	FUNCTION NAME: popUp
	
	PURPOSE: Calls a pop-up window without scrollbars or anything.  Pass
	the <A> tag as an object (so, <a href="..." onClick="popUp(this...
	This allows the <A> tag to link to a real page, but put that page in
	a pop-up if JS is turned on.  Also pass the height and width of the
	window to the function.  Pop-up will be centered in the window.
---------------------------------------------------------------------	*/

function popUp(aObject, theHeight, theWidth) {
	sURL = aObject.href;
	
	//	Grab a random-name for the window
	aURL = sURL.split("/");
	sWinName = aURL[aURL.length-1];
	sWinName = sWinName.substring(0,sWinName.indexOf("."));
	
	//	If we are linking to something in an images folder, we will call the
	//	img-popup.html page and add a query string to it.  This page will read
	//	the query string, place the right image within the page.
	if(sURL.indexOf("/images/") > -1) {
		sURL = "/img-popup.html?" + sURL;
	}
		
	var winHeight = theHeight;
	var winWidth = theWidth;
	
	//	Grab screen size
	var iPageWidth, iPageHeight;
	if (self.innerHeight) {
		iPageWidth = self.innerWidth;
		iPageHeight = self.innerHeight;
	}
	else if (document.all && document.getElementById) {
		iPageWidth = screen.availWidth;
		iPageHeight = screen.availHeight;
	}
	else if (document.body) {
		iPageWidth = document.body.clientWidth;
		iPageHeight = document.body.clientHeight;
	}

	//	Using a "," in the query string since IE converts the "&" into an escape string and unescaping it at the other
	//	end results in a lot of data being lost for some reason.
	leftSideOfPopup = (iPageWidth - winWidth)/2;
	topSideOfPopup = (iPageHeight - winHeight)/2;
	features = "toolbar=0,width=" + winWidth + ",height=" + winHeight + ",status=0,scrollbars=0,resize=0,menubar=0,location=0,directories=0,screenX=" + leftSideOfPopup + ",left=" + leftSideOfPopup + ",screenY=" + topSideOfPopup + ",top=" + topSideOfPopup;    <!-- One line and no spaces  -->
	theWindow = window.open(sURL, sWinName, features); 
	theWindow.focus();
}


/*	---------------------------------------------------------------------
	FUNCTION NAME: addLoadEvent
	
	PURPOSE: Allows for multiple statements with for simulated onload
	events.  Should replace window.onload events, but will catch one
	provided window.onload appears before this.
---------------------------------------------------------------------	*/
function addLoadEvent(func) {
	if(document.getElementById) {
		var oldonload = window.onload;
		if (typeof window.onload != 'function') {
			window.onload = func;
		} else {
			window.onload = function() {
				if (oldonload) {
					oldonload();
				}
				func();
			}
		}
	}
}