/* NWNL scripts for most pages  *  Validated by JSLint, April 28, 2011  *  switch.js reverted May 9, 2011 to fix a problem in IE 5 Mac.

   1. mailLink-NWNL.js for message links
   2. cfScript.js for cross-fade slide show
   3. styleNWNLswitch.js for sidebar links
   4. switch.js for sidebar links
   5. new script for hover sidebar links
*/





/* 1. start of mailLink-NWNL.js for message links */

function text(part1, text1, linktext, text2, part2) {
  var result = (text1 + '<a href="' + '&#109;ail' + 'to&#58;' + part1 + '&#64;' + part2 + '">' + linktext + '<\/a>' + text2);
  return result;
}

/* 1. end of mailLink-NWNL.js for message links */





/* 2. start of cfScript.js for cross-fade slide show */

/* tests whether to run the cross-fade slide show or display static images  *  Validated by JSLint, January 25, 2011 */

var agt = navigator.userAgent.toLowerCase();
var appVer = navigator.appVersion.toLowerCase();
// 33

/* test for iCab 4 or greater */
var isiCab = (agt.indexOf('icab\/')!==-1);
if (isiCab === true) {
   var iCabIndex = agt.indexOf('icab\/');
   var iCabVersion = parseInt(agt.substring(iCabIndex+5,iCabIndex+6),10);
}
// 41

/* test for Safari 1.3 for Mac (WebKit 312 or greater) */
var isSafari = ((agt.indexOf('safari')!==-1)&&(agt.indexOf('applewebkit')!==-1))?true:false; /* 'AppleWebKit' April 28, 2010 */
if (isSafari === true) {
   var safariIndex = agt.indexOf('applewebkit\/');
   var safariVersion = parseInt(agt.substring(safariIndex+12,safariIndex+17),10);
}
// 49

/* test for Firefox 1.5 or greater */
var isFirefox = (agt.indexOf('firefox\/')!==-1);
if (isFirefox === true) {
   var fxIndex = agt.indexOf('firefox\/');
   var fxVersion = parseFloat(agt.substring(fxIndex+8,fxIndex+11),10);
}
// 57

/* test for Opera 9 or greater */
var isOpera = (agt.indexOf('opera\/')!==-1);
var isPresto = (agt.indexOf('presto\/')!==-1);
if (isOpera === true) {
   if (isPresto === true) {  /* isPresto April 28, 2010 */
      var prIndex = agt.indexOf('version\/');
      var opVersion = parseFloat(agt.substring(prIndex+8,prIndex+12),10);
   } else {
      var opIndex = agt.indexOf('opera\/');
      var opVersion = parseInt(agt.substring(opIndex+6,opIndex+7),10);
   }
}
// 71

/* test for IE 6 or greater */
var isIE = ((agt.indexOf('msie')!==-1) && (agt.indexOf('windows')!==-1)); /* test for "Windows" to avoid spoofing mobiles, added April 19, 2010 */
if (isIE === true) {
   var ieIndex  = agt.indexOf('msie');
   var ieVersion = parseInt(agt.substring(ieIndex+5,ieIndex+6),10);
}
// 79

/* test for mobile versions */
var isMobile = ((agt.indexOf('mini')!==-1) || (agt.indexOf('mobil')!==-1)); /* test for mobile versions, added April 19, 2010 */
// 83


/* test for iCab 4, Safari 1.3.2, Firefox 1.5, Opera 9, or IE 6 */
var cf_okay = (isMobile === false) && ((isiCab && (iCabVersion >= 4) === true) || (isSafari && (safariVersion >= 312) === true) || (isFirefox && (fxVersion >= 1.5) === true) || (isOpera && (opVersion >= 9) === true) || (isIE && (ieVersion >= 6) === true));

/* test for iCab 3, Safari 2.0, Firefox 3, or Opera 10.5 (added April 12 & 28, 2010, for navigation menus) */
var menus_okay = (isMobile === false) && ((isiCab && (iCabVersion >= 3) === true) || (isSafari && (safariVersion >= 419) === true) || (isFirefox && (fxVersion >= 3.0) === true) || (isOpera && (opVersion >= 10.5) === true));
// 91


/* for the cross-fade slide show
   detection of single delay or array added April 28, 2011 */


/*  author:  Timothy Groves - http://www.brandspankingnew.net
 *  version: 1.3 - 2006-11-02
 *           1.2 - 2006-11-01
 *           1.1 - 2006-09-29
 *           1.0 - 2006-09-25
 *
 *  requires:  nothing
 */

// 106
var useBSNns;
var bsn;

if (useBSNns) {
	if (typeof(bsn) === "undefined") {
		bsn = {}; }
	var _bsn = bsn;
} else {
	var _bsn = this;
}
// 117

var dType = "";
// var aDelay;
// var nDelay;
_bsn.Crossfader = function (divs, fadetime, delay ) {
	this.nAct = -1;
	this.aDivs = divs;
	this.argDelay = delay;
	if (dType === "")	 {
		if (typeof delay !== "number") { 
			dType = "a";
		} else {
			dType = "n";
		}
	}

	var i;
	for (i=0;i<divs.length;i++) {
		document.getElementById(divs[i]).style.opacity = 0;
		document.getElementById(divs[i]).style.position = "absolute";
		document.getElementById(divs[i]).style.filter = "alpha(opacity=0)";
		document.getElementById(divs[i]).style.visibility = "hidden";
	}
	
	this.nDur = fadetime;
	this._newfade();
};
// 146

_bsn.Crossfader.prototype._newfade = function() {
	if (this.nID1) {
		clearInterval(this.nID1);
	}
	this.nOldAct = this.nAct;
	this.nAct++;
	if (!this.aDivs[this.nAct]) {	this.nAct = 0;
	}
	if (this.nAct === this.nOldAct) {
		return false;
	}
	document.getElementById( this.aDivs[this.nAct] ).style.visibility = "visible";
	
	this.nInt = 50;
	this.nTime = 0;
	
	var p=this;
	this.nID2 = setInterval(function() { p._fade(); }, this.nInt);
};
// 167

_bsn.Crossfader.prototype._fade = function() {
	this.nTime += this.nInt;
	
	var ieop = Math.round( this._easeInOut(this.nTime, 0, 1, this.nDur) * 100 );
	var op = ieop / 100;
	document.getElementById( this.aDivs[this.nAct] ).style.opacity = op;
	document.getElementById( this.aDivs[this.nAct] ).style.filter = "alpha(opacity="+ieop+")";
	
	if (this.nOldAct > -1) {
		document.getElementById( this.aDivs[this.nOldAct] ).style.opacity = 1 - op;
		document.getElementById( this.aDivs[this.nOldAct] ).style.filter = "alpha(opacity="+(100 - ieop)+")";
	}
// 181
	if (this.nTime === this.nDur) {
		clearInterval( this.nID2 );
		
		if (this.nOldAct > -1) {
			document.getElementById( this.aDivs[this.nOldAct] ).style.visibility = "hidden";	
		}
		var p=this;
		if (dType === "a") {
			this.nID1 = setInterval(function() { p._newfade(); }, this.argDelay[this.nAct]);
		} else if (dType === "n") {
			this.nID1 = setInterval(function() { p._newfade(); }, this.argDelay);
		}
	}
};
// 196

_bsn.Crossfader.prototype._easeInOut = function(t,b,c,d) {
	return c/2 * (1 - Math.cos(Math.PI*t/d)) + b;
};
// 201
/* 2. end of cfScript.js for cross-fade slide show */






/* 3. start of styleNWNLswitch.js for sidebar links */

var styleNWNLswitchJS = function() {

	/* styleNWNLswitchJS based on a method by Stu Nicholls, http://www.stunicholls.com/various/more_again.html */
	/* Note: keep </H4><div class="hide"> together in the HTML; separating them will break the style in some browsers! */

	document.writeln('<STYLE TYPE="text\/css"><!--');
	document.writeln('.switch {color:#4976C7; }');
	document.writeln('.switch:hover {text-decoration:underline; }');
	document.writeln('.off {color:#4976C7; }'); /* was #AA5500 */
	document.writeln('DIV#sidebar H2, DIV#sidebar H3, DIV#sidebar H4 {color:#4976C7; }'); /* make headings the same color as the links */
	document.writeln('.off:hover {text-decoration:none; }');

	document.writeln('.switch {cursor:pointer; }');
	document.writeln('H2 b img, H3 b img {width:14px; height:17px; background:url(\/images\/f-open2.gif); vertical-align:middle; }');
	document.writeln('.hide {display:none; }');
	document.writeln('.show {position:relative; display:block; }');
	document.writeln('--><\/STYLE>');
};

var styleNWNLswitch1JS = function() {
	document.writeln('<STYLE TYPE="text\/css"><!--');

	/* Note: for hover to work, Firefox needs complete ELEMENT.class:hover selector. */
	document.writeln('.switch {color:#4976C7; }');
	document.writeln('H2.switch:hover {text-decoration:underline; }');
	document.writeln('DIV#sidebar H2, DIV#sidebar H3, DIV#sidebar H4 {color:#4976C7; }');
	
	document.writeln('.switch {cursor:pointer; }');
	document.writeln('H2 b img, H3 b img {width:14px; height:17px; background:url(\/images\/f-open2.gif); vertical-align:middle; }');
	document.writeln('@media all {.hide {display:none !important; } }'); /* hide from IE 5 Mac and older browsers */
	
	/* new December 2009: */
	document.writeln('.hide P {margin-left:0em; text-indent:0em; }');
	document.writeln('DIV.s2:hover {position:relative; z-index:10; }');
	document.writeln('DIV.s2:hover .hide {display:block !important; position:absolute; left:28px; min-width:130px; border-left:1px solid #4976C7; border-bottom:1px solid #4976C7; background-color:white; }');
	document.writeln('--><\/STYLE>');
};

/* 3. end of styleNWNLswitch.js for sidebar links */





/* 4. start of switch.js for sidebar links */

/* based on an example by Stu Nicholls, 
   http://www.stunicholls.com/various/more_again.html */

function switchJS() {
	var showID = "";
	var showID2 = "";
	var showID3 = "";
	
	onload = function() {
		var e, i = 0;
		while (e = document.getElementsByTagName ('H4') [i++]) {
			if (e.className == 'switch') {
			e.onclick = function () {
				this.className = this.className == 'switch' ? 'switch off' : 'switch';
				this.nextSibling.className = this.className == 'switch' ? 'hide' : 'show';
				}
			}
		}
		var e3, i3 = 0;
		while (e3 = document.getElementsByTagName ('H3') [i3++]) {
			if (e3.className == 'switch') {
			e3.onclick = function () {
				this.className = this.className == 'switch' ? 'switch off' : 'switch';
				this.nextSibling.className = this.className == 'switch' ? 'hide' : 'show';
				}
			}
		}
		var e2, i2 = 0;
		while (e2 = document.getElementsByTagName ('H2') [i2++]) {
			if (e2.className == 'switch') {
			e2.onclick = function () {
				this.className = this.className == 'switch' ? 'switch off' : 'switch';
				this.nextSibling.className = this.className == 'switch' ? 'hide' : 'show';
				}
			}
		}
		if (document.getElementById(showID)) {
			document.getElementById(showID).className = this.className == 'switch off';
			document.getElementById(showID).style.cursor = 'pointer';
			document.getElementById(showID).nextSibling.className = this.className == 'show';
		}
		if (document.getElementById(showID2)) {
			document.getElementById(showID2).className = this.className == 'switch off';
			document.getElementById(showID2).style.cursor = 'pointer';
			document.getElementById(showID2).nextSibling.className = this.className == 'show';
		}
		if (document.getElementById(showID3)) {
			document.getElementById(showID3).className = this.className == 'switch off';
			document.getElementById(showID3).style.cursor = 'pointer';
			document.getElementById(showID3).nextSibling.className = this.className == 'show';
		}
	}
}

/* 4. end of switch.js for sidebar links */





/* 5. start of new script for hover sidebar links */


/* Tested in iCab 3, Safari 2.0.2 for Mac (WebKit 418), Firefox 1.5, Opera 9.2. Doesn't work yet in IE 8.
   See script 2 for variables. */
   
var isMobile = agt.indexOf('mobile');
var isMini = agt.indexOf('opera mini');


/* test for iCab 3, Safari 2 (AppleWebKit/418), Firefox 1.5, or Opera 9 */
var sidebarMenusOK = (isiCab && (iCabVersion >= 3) === true) || (isSafari && (safariVersion >= 418) === true) || (isFirefox && (fxVersion >= 1.5) === true) || (isOpera && (opVersion >= 9) === true);

if ((document.getElementsByTagName) && (isMobile === -1) && (isMini === -1)) {
	if (sidebarMenusOK === true) {
		styleNWNLswitch1JS();
	} // else {
	if (sidebarMenusOK === false) {
		styleNWNLswitchJS();
		switchJS();
	}
}

/* 5. end of new script for hover sidebar links */





