/* NWNL scripts for most pages */

// 1. mailLink-NWNL.js for message links
// 2. cfScript.js for cross-fade slide show
// 3. new script for hover sidebar links
// 4. styleNWNLswitch.js for sidebar links
// 5. switch.js for 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 */

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


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


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


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


/* test for Opera 9 or greater */
var isOpera = (agt.indexOf('opera\/')!=-1);
if (isOpera !=-1) {
   var opIndex = agt.indexOf('opera\/');
   var opVersion = parseInt(agt.substring(opIndex+6,opIndex+7),10);
}


/* test for IE 6 or greater */
var isIE = (agt.indexOf('msie')!=-1);
if ((isIE !=-1)) {
   var ieIndex  = agt.indexOf('msie');
   var ieVersion = parseInt(agt.substring(ieIndex+5,ieIndex+6),10);
}


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



/* for the cross-fade slide show */


/*  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
 */


var useBSNns;
var bsn;

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


_bsn.Crossfader = function (divs, fadetime, delay ) {	
	this.nAct = -1;
	this.aDivs = divs;
	
	for (var 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.nDelay = delay;
		
	this._newfade();
};


_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);
};


_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)+")";
	}
	
	if (this.nTime == this.nDur) {
		clearInterval( this.nID2 );
		
		if (this.nOldAct > -1) {
			document.getElementById( this.aDivs[this.nOldAct] ).style.visibility = "hidden";	
		}
		var p=this;
		this.nID1 = setInterval(function() { p._newfade(); }, this.nDelay);
	}
};


_bsn.Crossfader.prototype._easeInOut = function(t,b,c,d) {
	return c/2 * (1 - Math.cos(Math.PI*t/d)) + b;
};

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






/* 3. 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()
	}
}

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






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

function styleNWNLswitchJS() {

	/* 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>');
}

function styleNWNLswitch1JS() {
	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>');
}

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





/* 5. 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';
		}
	}
}

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



