function externalLinks() 
{
	if (!document.getElementsByTagName) return;
	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";
	}
}

// ADD IMAGE SWAP -------------------------------------------------
// adds a JS mouse over swap to all image inputs and image links
// in the document with '_off' or '_on' as the last bit of the
// filename before the extension
function AddSwap() {
//	declare variables
	var	inputs,
		hyperlinks,
		numElements,
		childImages,
		numImages,
		i,
		j;
//	test for DOM Methods and get all input elements
	if(	(typeof document.getElementById != 'undefined') &&
		(typeof document.getElementsByTagName != 'undefined') &&
		(inputs = document.getElementsByTagName('input')) &&
		(hyperlinks = document.getElementsByTagName('a'))
		) {
//		loop through the inputs
		numElements = inputs.length;
		for (i = 0; i < numElements; i++) {
//			find the ones that are of type 'image'
			if (inputs[i].type.toLowerCase() == 'image') {
//				pass image inputs to the function that adds the swap
				this.makeSwap(inputs[i]);
			}
		}
//		loop through the anchors
		numElements = hyperlinks.length;
		for (i = 0; i < numElements; i++) {
//			find the ones that have image children
			childImages = hyperlinks[i].getElementsByTagName('img');
			numImages = childImages.length;
			if (numImages > 0) {
//				pass the images to the function that adds the swap
				for (j = 0; j < numImages; j++) {
					this.makeSwap(childImages[j]);
				}
			}
		}
		// addUnloadHandler(this.cleanUp);
		// Event.observe(window, 'unload', cleanUp, false);
		return true;
	}
	return false;
}
AddSwap.prototype.makeSwap = function (el) {
	if ((typeof el.src == 'string') && (el.src.indexOf('_off.') != -1)) {
//		if the image name contains 'off' set the src of off state img to the current
//		src and swap the 'off' with 'on' to get the src for the on state
		el.offImg = new Image();
		el.offImg.src = el.src;
		el.onImg = new Image();
		el.onImg.src = el.src.replace(/_off\./,'_on.');
	} else if ((typeof el.src == 'string') && (el.src.indexOf('_on.') != -1)) {
//		otherwise, if the image name contains 'on' set the src of on state img to the
//		current src and swap the 'on' with 'ooff' to get the src for the on state
		el.offImg = new Image();
		el.offImg.src = el.src;
		el.onImg = new Image();
		el.onImg.src = el.src.replace(/_on\./,'_off.');
//	if neither of the state slugs is present, return false
	} else return false;
//	add mouseover and mouseout functions
	el.onmouseover = function() { this.src = this.onImg.src; return true; }
	el.onmouseout = function() { this.src = this.offImg.src; return true; }
	return true
}
AddSwap.prototype.cleanUp = function () {
	var	inputs = document.getElementsByTagName('input'),
		hyperlinks = document.getElementsByTagName('a'),
		numElements = inputs.length,
		childImages,
		numImages,
		i,
		j;
//	loop through the inputs
	for (i = 0; i < numElements; i++) {
//		find the ones that are of type 'image'
		if (inputs[i].type.toLowerCase() == 'image') {
//			remove handlers & expandos
			inputs[i].offImg = null;
			inputs[i].onImg = null;
			inputs[i].onmouseover = null;
			inputs[i].onmouseout = null;
		}
	}
//	loop through the anchors
	numElements = hyperlinks.length;
	for (i = 0; i < numElements; i++) {
//		find the ones that have image children
		childImages = hyperlinks[i].getElementsByTagName('img');
		numImages = childImages.length;
		if (numImages > 0) {
//			pass the images to the function that adds the swap
			for (j = 0; j < numImages; j++) {
				childImages[j].offImg = null;
				childImages[j].onImg = null;
				childImages[j].onmouseover = null;
				childImages[j].onmouseout = null;
			}
		}
	}
	return true;
}
// addLoadHandler(function() { return new AddSwap();});

function initSwaps() { return new AddSwap(); }

var newWindow = null;

function closeWin(){
	if (newWindow != null){
		if(!newWindow.closed)
			newWindow.close();
	}
}

function popUpWin(url, type, strWidth, strHeight){
	
	closeWin();
		
	type = type.toLowerCase();
	
	if (type == "fullscreen"){
		strWidth = screen.availWidth;
		strHeight = screen.availHeight;
	}
	var tools="";
	if (type == "standard") tools = "resizable,toolbar=yes,location=yes,scrollbars=yes,menubar=yes,width="+strWidth+",height="+strHeight+",top=0,left=0";
	if (type == "console" || type == "fullscreen") tools = "resizable,toolbar=no,location=no,scrollbars=no,width="+strWidth+",height="+strHeight+",left=0,top=0";
	newWindow = window.open(url, 'newWin', tools);
	newWindow.focus();
}

function doPopUp(e)
{
//set defaults - if nothing in rel attrib, these will be used
var t = "console";
var w = "400";
var h = "400";
//look for parameters
attribs = this.rel.split(" ");
if (attribs[1]!=null) {t = attribs[1];}
if (attribs[2]!=null) {w = attribs[2];}
if (attribs[3]!=null) {h = attribs[3];}

//call the popup script
popUpWin(this.href,t,w,h);
//cancel the default link action if pop-up activated
if (window.event) 
	{
	window.event.returnValue = false;
	window.event.cancelBubble = true;
	} 
else if (e) 
	{
	e.stopPropagation();
	e.preventDefault();
	}
}

function findPopUps()
{
	var popups = document.getElementsByTagName("a");
	for (i=0;i<popups.length;i++)
	{
		if (popups[i].rel.indexOf("popup")!=-1)
		{
			// attach popup behaviour
			popups[i].onclick = popups[i].onkeypress = doPopUp;
		}
	}
}

function doOnload ()
{
	externalLinks();
	initSwaps();
	findPopUps();
	// initLightbox ();
}

Event.observe(window, 'load', doOnload, false);


function hasFlashVersion(majorVersion, buildVersion) 
{
	var reqVersion = parseFloat(majorVersion + "." + buildVersion);
	
	if (navigator.plugins && typeof navigator.plugins["Shockwave Flash"] == "object") 
	{
		var desc = navigator.plugins["Shockwave Flash"].description;
		if (desc) 
		{
			var versionStr = desc.replace(/^.*\s+(\S+\s+\S+$)/, "$1");
			var major = parseInt(versionStr.replace(/^(.*)\..*$/, "$1"));
			var build = parseInt(versionStr.replace(/^.*r(.*)$/, "$1"));
			var flashVersion = parseFloat(major + "." + build);
		}
	}
	else if (window.ActiveXObject) 
	{
		try {
			var flashObj = new ActiveXObject("ShockwaveFlash.ShockwaveFlash");
			var desc = flashObj.GetVariable("$version");
			if (desc) {
				var versionArr = desc.replace(/^\S+\s+(.*)$/, "$1").split(",");
				var major = parseInt(versionArr[0]);
				var build = parseInt(versionArr[2]);
				var flashVersion = parseFloat(major + "." + build);
			}
		}
		catch(e) {}
	}
	if (typeof flashVersion != "undefined")
	{
		return (flashVersion >= reqVersion ? true : false); 
	}
	return false;
}