// SETS THE TIMER FOR THE FADE IN/OUT SCRIPT
var timer = 7000;

// ALL SCRIPTS THAT RUN ON PAGE LOAD
function setup() {
	// OUTBOUND LINKS OPEN IN A NEW WINDOW UNLESS EXPLICITLY TOLD OTHERWISE
	// FORCE SAME WINDOW: rel="self" in anchor
	// FORCE EXTERNAL WINDOW: rel="external" in anchor
	var domain = window.location+'';
	domain = domain.replace('//','');
	domain = domain.substring(domain.indexOf(':')+1,domain.indexOf('/'));
	if (!document.getElementsByTagName) return;
	var anchors = document.getElementsByTagName("a");
	for (var i=0; i<anchors.length; i++) {
		var URL = anchors[i].href;
		if ((URL.search(domain)===-1 && URL.search('http')!==-1 && anchors[i].rel !== 'self') || anchors[i].rel === 'external') anchors[i].target = "_blank";
	}
	so_init();
}

window.onload = setup;

// FORM ACTIVATION SCRIPT
function activate(brillig) {
	document.getElementById('config').name = "config";
	document.getElementById('config').value = brillig;
}

/*****
Image Cross Fade Redux
Version 1.0
Last revision: 02.15.2006
steve@slayeroffice.com

Please leave this notice intact. 

Rewrite of old code found here: http://slayeroffice.com/code/imageCrossFade/index.html
*****/

//window.addEventListener?window.addEventListener("load",so_init,false):window.attachEvent("onload",so_init);

var d=document, total, stopTrigger, imgs = new Array(), tabtext = new Array(), morebtn = new Array(), tabs = new Array(), preimage = new Array(), zInterval = null, current=0, nextPic, pause=false;

function so_init() { if(document.getElementById('imageContainer')) { // Only trigger the fade script when imageContainer exists!
	if((!d.getElementById || !d.createElement))return;

	css = d.createElement("link");
	css.setAttribute("href","xfade.css");
	css.setAttribute("rel","stylesheet");
	css.setAttribute("type","text/css");
	d.getElementsByTagName("head")[0].appendChild(css);

	imgs = d.getElementById("imageContainer").getElementsByTagName("img");
	//morebtn = d.getElementById("morebtn").getElementsByTagName("a");
	tabs = d.getElementById("tabs").getElementsByTagName("a");
	tabtext = d.getElementById("tabtext").getElementsByTagName("div");
	total = imgs.length-1;
	
	for(i=1;i<imgs.length;i++) { 
		imgs[i].xOpacity = 0;
		tabtext[i].xOpacity = 0;
		preimage[i] = new Image(952,340);
		preimage[i].source = imgs[i].src;
	}
	imgs[0].style.display = "block";
	tabtext[0].style.display = "block";
	imgs[0].xOpacity = .99;
	tabtext[0].xOpacity = .99;
	
	nextPic = setTimeout(so_xfade,timer);
} }

function so_xfade() {
	cOpacity = imgs[current].xOpacity; 
	nIndex = imgs[current+1]?current+1:0;

	nOpacity = imgs[nIndex].xOpacity;
	
	cOpacity-=.05; 
	nOpacity+=.05;
	
	imgs[nIndex].style.display = "block";
	imgs[current].xOpacity = cOpacity;
	imgs[nIndex].xOpacity = nOpacity;
	tabtext[nIndex].style.display = "block";
	tabtext[current].xOpacity = cOpacity;
	tabtext[nIndex].xOpacity = nOpacity;
	
	setOpacity(imgs[current]); 
	setOpacity(imgs[nIndex]);
	setOpacity(tabtext[current]); 
	setOpacity(tabtext[nIndex]);

	if(cOpacity<=.50 && cOpacity>.45) {
		moreSwitch();
	}
	
	if(cOpacity<=0) {
		imgs[current].style.display = "none";
		tabtext[current].style.display = "none";
		current = nIndex;
		nextPic = setTimeout(so_xfade,timer);
	} else {
		setTimeout(so_xfade,50);
	}
	
	function setOpacity(obj) {
		if(obj.xOpacity>.99) {
			obj.xOpacity = .99;
			return;
		}
		obj.style.opacity = obj.xOpacity;
		obj.style.MozOpacity = obj.xOpacity;
		obj.style.filter = "alpha(opacity=" + (obj.xOpacity*100) + ")";
	}
	
}

function so_xfade2(foo) {
	clearTimeout(nextPic);
	stopTrigger = 1;
	for (i=0 ; i<imgs.length ; i++) { 
		imgs[i].style.display = 'none';
		imgs[i].style.opacity = 1;
		imgs[i].style.MozOpacity = 1;
		imgs[i].style.filter = "alpha(opacity=100)";
		tabtext[i].style.display = 'none';
		tabtext[i].style.opacity = 1;
		tabtext[i].style.MozOpacity = 1;
		tabtext[i].style.filter = "alpha(opacity=100)";
	}
	current = foo;
	imgs[current].style.display = 'block';
	tabtext[current].style.display = 'block';
	moreSwitch();
}

function tabtextwitch(foo) {
	for (i=0 ; i<tabtext.length ; i++) {
		tabtext[i].style.display = 'none'
	}
	tabtext[foo].style.display = 'block';
	moreSwitch();
}

function moreSwitch() {
	if (stopTrigger === 1) var picPos = current; else var picPos = nIndex;
	
	// Switch the "more" button
	// for (i=0 ; i<morebtn.length ; i++) morebtn[i].display = 'none';
	// morebtn[picPos].style.display = 'block';
	
	// Switch the arrow on the left
	for (i=0 ; i<tabs.length ; i++) tabs[i].className = '';
	tabs[picPos].className = 'active';
}

function arrowSwitch() {
	if (stopTrigger === 1) var picPos = current; else var picPos = nIndex;
	if (picPos === 0) document.getElementById('highlight').style.marginLeft = '0px';
	else document.getElementById('highlight').style.marginLeft = (picPos*72)+'px';
}
