//----------------------------------------------------------------------------------
// Encrypt Email script- Please keep notice intact.
// Tool URL: http://www.dynamicdrive.com/emailriddler/
//----------------------------------------------------------------------------------
function GetEmail()
{
	var a = new Array(101,109,97,105,108,64,116,111,112,108,101,118,46,99,111,109);
	var e = '';
	for(var i = 0; i < a.length; i++) {
		e += String.fromCharCode(a[i]);
	}
	return e;
}
/*The functions below are for tidyness and because including them inline causes XHTML validation errors*/
function WriteEmailLink(){document.write('<a href="mailto:'+GetEmail()+'">'+GetEmail()+'<\/a>');}
function WriteEmailLink2(){document.write('<a href="mailto:'+GetEmail()+'">'+GetEmail()+' &gt;<\/a>');}
//----------------------------------------------------------------------------------
//----------------------------------------------------------------------------------
var ticker;
var ticker2; // a copy of ticker
var tickerWidth;
var tickerB;
var tickerB2; // a copy of ticker
var tickerBWidth;
// Set up event handlers
if (window.addEventListener) {
	window.addEventListener("load", TLOnLoad, false);
} else if (window.attachEvent) {
	window.attachEvent("onload", TLOnLoad);
} else if (document.getElementById) {
	window.onload = TLOnLoad;
}

function TLOnLoad()
{
    ClearCurrentLinks(); // because it is not always called from code in the body of the page
	InitTicker();
	InitTickerB();
	AddReturnURLToFormLinks();
}

function InitTicker()
{
	ticker = document.getElementById("ticker");
	if(!ticker) return;
	ticker.style.left = "0px";
	ticker2 = ticker.cloneNode(true); // deep copy
	if(!ticker2) return;
	ticker2.id = "ticker2";
	ticker.parentNode.appendChild(ticker2);
	ticker.style.left = "0px";
	tickerWidth = ticker.offsetWidth;
	ticker2.style.left = tickerWidth + "px";
	//setTimeout('lefttime=setInterval("ScrollTicker()", 30)', 1000) // 1 second delay before scroll
	setInterval("ScrollTicker()", 30);	// no delay
}

function ScrollTicker()
{
	if(bPaused) return;
	var p = parseInt(ticker.style.left) - 1;
	if(p < -tickerWidth) {
		p = tickerWidth;
	}
	ticker.style.left = p + "px";
	p = parseInt(ticker2.style.left) - 1;
	if(p < -tickerWidth) {
		p = tickerWidth;
	}
	ticker2.style.left = p + "px";
}

var bPaused = false;
function PauseTicker()
{
	bPaused = true;
}
function ResumeTicker()
{
	bPaused = false;
}


//--- 2nd ticker
function InitTickerB()
{
	tickerB = document.getElementById("tickerB");
	if(!tickerB) return;
	tickerB.style.left = "0px";
	tickerB2 = tickerB.cloneNode(true); // deep copy
	if(!tickerB2) return;
	tickerB2.id = "tickerB2";
	tickerB.parentNode.appendChild(tickerB2);
	tickerB.style.left = "0px";
	tickerBWidth = tickerB.offsetWidth;
	tickerB2.style.left = tickerBWidth + "px";
	//setTimeout('lefttime=setInterval("ScrollTicker()", 30)', 1000) // 1 second delay before scroll
	setInterval("ScrollTickerB()", 30);	// no delay
}

function ScrollTickerB()
{
	if(bPausedB) return;
	var p = parseInt(tickerB.style.left) - 1;
	if(p < -tickerBWidth) {
		p = tickerBWidth;
	}
	tickerB.style.left = p + "px";
	p = parseInt(tickerB2.style.left) - 1;
	if(p < -tickerBWidth) {
		p = tickerBWidth;
	}
	tickerB2.style.left = p + "px";
}

var bPausedB = false;
function PauseTickerB()
{
	bPausedB = true;
}
function ResumeTickerB()
{
	bPausedB = false;
}
//----------------------------------------------------------------------------------
// Fix up links to enquiry & partner query forms so if user cancels they are returned to the page they came from.
function AddReturnURLToFormLinks()
{
	// this is a non-essential function so suppress errors
	try {
		var links = document.links;
		for(var i = 0; i < links.length; i++) {
			var href = links[i].href;
			if(href.endsWithNoCase('QueryForm.ofml')) {
				href += '?CloseURL=' + urlencode(window.location);
				links[i].href = href;
			}
		}
	}
	catch(e) {}
}
// Utility fns
String.prototype.endsWith = function(str){return (this.match(str+"$")==str);}
String.prototype.endsWithNoCase = function(strIn){var str = strIn.toLowerCase();return (this.toLowerCase().match(str+"$")==str);}
function urlencode(str) {
	var v;
	// encodeURIComponent results in a utf-8 encoded string. escape does not.
	try { v = escape(str); } catch (e) { v = encodeURIComponent(str); }
	return v.replace(/%20/g,"+");
}

// Easter Egg
function TestChangeImage(i)
{
	var r='';
	switch(i.src.substr(i.src.length-5,1)) {
		case 'r': r='1'; break;
		case '1': r='2'; break;
	}
	i.src = 'images/sector_third_sector' + r + '.png';
	return false;
}
//----------------------------------------------------------------------------------
// Stop links to current page being links
// (Heavily) adapted from public domain code "CLCP v2.1 Clear Links to Current Page" by Jonathan Snook http://www.snook.ca/jonathan/
function ClearCurrentLinks() {
    var links = document.getElementsByTagName("A");
    for (var i = 0; i < links.length; i++) {
        var a = links[i];
        if (a.href == window.location.href.split("#")[0]) {
            if (a.parentNode.parentNode.className == "leftnavcol") {
                // Link in left nav col, either H1, or link below H1
                ClearCurrentLink(a);
            } else if (a.parentNode.className == "menubar") {
                // Link in menu bar. Instead of removing the link (which would remove padding etc),
                // we assign the existing link a class and just style it to not look like a link.
                a.className += " currentpagelink";
            } else if (a.parentNode.className == "fourthlevellinks") {
				a.className += " currentpagelink";
			}
        }
    }
}
function ClearCurrentLink(n) {
    var myNode = null;
    if (n.hasChildNodes()) {
        for (var i = 0; i < n.childNodes.length; i++) {
            myNode = n.childNodes[i].cloneNode(true);
            n.parentNode.insertBefore(myNode, n);
        }
    }
    n.parentNode.removeChild(n);
    // Remove the > and wrap in a span (for ordinary left nav links only, not H1)
    if (myNode) {
        var s = myNode.parentNode.innerHTML;
        if (s.endsWith(" &gt;")) {
            myNode.parentNode.innerHTML = "<span class=\"currentpagelink\">" + s.substring(0, s.length - 5) + "</span>";
        }
    }
}
//----------------------------------------------------------------------------------
// CrossFader
//----------------------------------------------------------------------------------
/**
 *  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
 *
 *  Various modifications by Simon Plummer, Toplevel Computing Ltd 31/7/2008.
 *	Incorporated StartFade & StopFade functions by Gregory Smith, from http://beaglewriter.com/crossfader/
 */
//-----------------------------
// CrossFader initial start/stop helpers (in case user mouses over banner before crossfader object is created)
var cf;
var cfInitiallyStopped = false;
function CFStop()
{
	if(cf) {
		cf.StopFade();
	} else {
		cfInitiallyStopped = true;
	}
}
function CFStart()
{
	cfInitiallyStopped = false;
	if(cf) {
		cf.StartFade();
	}
}
//-----------------------------

var useBSNns;

if (useBSNns)
{
	if (typeof(bsn) == "undefined")
		bsn = {}
	var _bsn = bsn;
}
else
{
	var _bsn = this;
}





_bsn.Crossfader = function (divs, fadetime, delay )
{	
	this.nAct = 0; // Simon: was -1;
	this.aDivs = divs;
	//for(var i=0;i<divs.length;i++)
	for(var i=1;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.stopPending = false;
	this.stopped = false;
	
	if(cfInitiallyStopped) {
		this.StopFade();
	}
	this._newfade();
}

_bsn.Crossfader.prototype.StopFade = function()
{
	if (this.stopped || this.stopPending)
	{
		return;
	}
	this.stopPending = true;
}
_bsn.Crossfader.prototype.StartFade = function()
{
	if (this.stopPending)
	{
		this.stopPending = false; // Cancel pending stop
		return;
	}
	else if (!this.stopped)
	{
		return;
	}
	this._newfade();
}

_bsn.Crossfader.prototype._newfade = function()
{
	if (this.nID1)
		clearInterval(this.nID1);
	
	if (this.stopPending)
	{
		this.stopPending = false;
		this.stopped = true;
		return;
	}
	this.stopped = false;
	
	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;
}
//----------------------------------------------------------------------------------
// Script Source: CodeLifter.com
// Copyright 2003
// Do not remove this notice.

// SETUPS:
// ===============================

// Set the horizontal and vertical position for the popup

PositionX = 100;
PositionY = 90;

// Set these value approximately 20 pixels greater than the
// size of the largest image to be used (needed for Netscape)

defaultWidth  = 500;
defaultHeight = 500;

// Set autoclose true to have the window close automatically
// Set autoclose false to allow multiple popup windows

var AutoClose = true;

// Do not edit below this line...
// ================================
if (parseInt(navigator.appVersion.charAt(0))>=4){
var isNN=(navigator.appName=="Netscape")?1:0;
var isIE=(navigator.appName.indexOf("Microsoft")!=-1)?1:0;
}
var optNN='scrollbars=no,width='+defaultWidth+',height='+defaultHeight+',left='+PositionX+',top='+PositionY;
var optIE='scrollbars=no,width=150,height=100,left='+PositionX+',top='+PositionY;
function popImage(imageURL,imageTitle){
if (isNN){imgWin=window.open('about:blank','',optNN);}
if (isIE){imgWin=window.open('about:blank','',optIE);}
with (imgWin.document){
writeln('<html><head><title>Loading...</title><style>body{margin:0px;}</style>');writeln('<sc'+'ript>');
writeln('var isNN,isIE;');writeln('if (parseInt(navigator.appVersion.charAt(0))>=4){');
writeln('isNN=(navigator.appName=="Netscape")?1:0;');writeln('isIE=(navigator.appName.indexOf("Microsoft")!=-1)?1:0;}');
writeln('function reSizeToImage(){');writeln('if (isIE){');writeln('window.resizeTo(300,300);');
writeln('width=300-(document.body.clientWidth-document.images[0].width);');
writeln('height=300-(document.body.clientHeight-document.images[0].height);');
writeln('window.resizeTo(width,height);}');writeln('if (isNN){');       
writeln('window.innerWidth=document.images["George"].width;');writeln('window.innerHeight=document.images["George"].height;}}');
writeln('function doTitle(){document.title="'+imageTitle+'";}');writeln('</sc'+'ript>');
if (!AutoClose) writeln('</head><body bgcolor=000000 scroll="no" onload="reSizeToImage();doTitle();self.focus()">')
else writeln('</head><body scroll="no" onload="reSizeToImage();doTitle();self.focus()" onblur="self.close()">');
writeln('<a href="javascript:window.close();"><img name="George" src='+imageURL+' style="display:block" title="Click to close" border="0"></a></body></html>');
close();		
}}
//----------------------------------------------------------------------------------
// Search
function qs(){var f=document.formSear;var qe=f.searWords.value;if(window.encodeURIComponent)qe=encodeURIComponent(qe);if(f.area)if(f.area.value==2){document.location="http://www.google.com/search?q="+qe;return false;}var pt=document.location.href;var iq=pt.indexOf('?');if(iq!=-1)pt=pt.substring(0, iq);if(f.action)if(f.action!="")pt=f.action;var ue=pt+"?searWords="+qe;if(f.search)ue+="&search="+f.search.value;if(f.match)ue+="&match="+f.match.value;document.location=ue;return false;}
//----------------------------------------------------------------------------------
// Fisher-Yates shuffle to randomise sn array, copied from http://sedition.com/perl/javascript-fy.html
function ShuffleArray(a) {
  var i = a.length;
  if(i == 0) return false;
  while(--i) {
     var j = Math.floor(Math.random() * (i + 1));
     var tempi = a[i];
     var tempj = a[j];
     a[i] = tempj;
     a[j] = tempi;
   }
}
//----------------------------------------------------------------------------------
var quoteDivs;
function InitQuoteFader()
{
	// DIVs containing quotes have ids q1, q2, q3 ...
	// q1 initially has style visibility:visible, for noscript users
	var i = 1;
	quoteDivs = new Array();
	while(true) {
		if(document.getElementById("q" + i) == null) {
			break;
		}
		quoteDivs.push("q" + i);
		i++;
	}
	if(quoteDivs.length == 0) return;
	document.getElementById(quoteDivs[0]).style.visibility = 'hidden';	// the first one is declared visible for noscript users
	ShuffleArray(quoteDivs);
	document.getElementById(quoteDivs[0]).style.visibility = 'visible';	// show first image initially, no fade in

	if(window.addEventListener) {
		window.addEventListener("load", InitQuotesCrossFader, false);
	} else if(window.attachEvent) {
		window.attachEvent("onload", InitQuotesCrossFader);
	}
}
function InitQuotesCrossFader()
{
	setTimeout('cf = new Crossfader(quoteDivs, 1000, 9000)', 9000); // 9 second delay (after page has loaded) before first fade, then fade every 9s, fade takes 1s.
}
