
var elmsBox = document.getElementById("Elements");

if (elmsBox) { // simple check - homepage has no Elements box

var elms = {
	Sp: {
		title: document.getElementById("speedTitle"),
		content: document.getElementById("speedContent"),
		btn: document.getElementById("SpEleBtns"),
		className: "speedOn",
		link: ""
	},
	Ac: {
		title: document.getElementById("accuracyTitle"),
		content: document.getElementById("accuracyContent"),
		btn: document.getElementById("AcEleBtns"),
		className: "accuracyOn",
		link: ""
	},
	Cn: {
		title: document.getElementById("consistencyTitle"),
		content: document.getElementById("consistencyContent"),
		btn: document.getElementById("CnEleBtns"),
		className: "consistencyOn",
		link: ""
	},
	Pw: {
		title: document.getElementById("powerTitle"),
		content: document.getElementById("powerContent"),
		btn: document.getElementById("PwEleBtns"),
		className: "powerOn",
		link: ""
	},
	Cl: {
		title: document.getElementById("clarityTitle"),
		content: document.getElementById("clarityContent"),
		btn: document.getElementById("ClEleBtns"),
		className: "clarityOn",
		link: ""
	}
};

var current;
var initialSymbol;

// deep link will override elmsbox
var deepLink = (location.search || location.hash);
var deepLinkRegex = /element=(.+)/;

if (deepLinkRegex.test(deepLink))
{
	initialSymbol = deepLink.match(deepLinkRegex)[1];
}
else
{
	switch(elmsBox.className) {
		case elms.Ac.className:
			initialSymbol = "Ac";
			break;
		case elms.Sp.className:
			initialSymbol = "Sp";
			break;
		case elms.Cn.className:
			initialSymbol = "Cn";
			break;
		case elms.Pw.className:
			initialSymbol = "Pw";
			break;
		case elms.Cl.className:
		default:
			initialSymbol = "Cl";
			break;
	}
}

var elmRot = [ "Cn", "Sp", "Ac", "Pw", "Cl" ];
var elmRotI = 0;
for (var i = 0; i < elmRot.length; i++)
{
	if (elmRot[i] == initialSymbol)
	{
		elmRotI = i;
		break;
	}
}
var elmRotTID;
var elmRotInterval = 10000;

function rotateElms()
{
	elmRotI++;
	if (elmRotI == elmRot.length)
		elmRotI = 0;
	
	setElement(elmRot[elmRotI]);
}

// set up 10 second cycle
var timeoutID = setTimeout("rotateElms()", elmRotInterval);


if (unFocus.FlashPlayerInfo.getVersion() >= 9 && !/noflash/.test(location))
{
	var bgSwfID = "bgSwf";
	var bghtml = new unFocus.SwfHTML();
	bghtml.setSrc("/_flash/bg-subPages.swf");
	bghtml.setId(bgSwfID);
	bghtml.setName(bgSwfID);
	bghtml.setMenu(false);
	bghtml.setQuality("high");
	bghtml.setScale("noscale");
	bghtml.setWMode("transparent");
	bghtml.setSAlign("tl");
	
	bghtml.setWidth(633);
	bghtml.setHeight(456);
	
	// second deep link check
	if (initialSymbol)
		bghtml.addFlashvar("startToken", initialSymbol.toLowerCase());
	
	else {
		switch (elmsBox.className) {
			case elms.Sp.className:
				bghtml.addFlashvar("startToken", "sp");
				break;
			case elms.Ac.className:
				bghtml.addFlashvar("startToken", "ac");
				break;
			case elms.Cn.className:
				bghtml.addFlashvar("startToken", "cn");
				break;
			case elms.Pw.className:
				bghtml.addFlashvar("startToken", "pw");
				break;
			case elms.Cl.className:
			default:
				bghtml.addFlashvar("startToken", "cl");
				break;
		}
	}
	
	bghtml.addFlashvar("SpLink", elms.Sp.link);
	bghtml.addFlashvar("AcLink", elms.Ac.link);
	bghtml.addFlashvar("CnLink", elms.Cn.link);
	bghtml.addFlashvar("PwLink", elms.Pw.link);
	bghtml.addFlashvar("ClLink", elms.Cl.link);
	
	bghtml.outputToInnerHTML (document.getElementById("flashBg"));
	
	var bgSwfRef = unFocus.SwfUtilities.getSwfReference(bgSwfID);
}
else
{
	document.getElementById("bg-noflash").style.display = "block";
}



// Check for FF 2.0 and lower on Mac OS X.
// That browser cannot use any opacity over a wmode flash element.
var ua = navigator.userAgent;

if (
	ua.indexOf("Mac OS X") != -1 &&
	ua.indexOf("Firefox/") != -1 &&
	ua.match(/Firefox\/(\d+)/)[1] < 3
) {

	function setElement(symbol)
	{
	
	
		if (current != elms[symbol])
		{
			current.content.style.visibility =
			current.title.style.visibility = "hidden";
			current.btn.style.background = "";
			current.content.style.zIndex = 50;
			
			// created hook for init tricker
			setElementOn(symbol);
		}
		resetElmTimeout();
	}
	
	function setElementOn(symbol)
	{
		current = elms[symbol];
		
		current.content.style.zIndex = 100;
				current.title.style.visibility = "visible";
		current.btn.style.background = "#FFF";
		
		if (bgSwfRef) // check in case no flash is used
			bgSwfRef.goNewPage(symbol);
	}

} else {
	
	function setElement(symbol)
	{
	
		if (elms && current != elms[symbol])
		{
			if (bgSwfRef) {
				var animOut = new Animator({
					onComplete: function () {
						bgSwfRef.goNewPage(symbol);
					}
				});
			}
			animOut.addSubject(
				new NumericalStyleSubject(
					[current.content, current.title], 'opacity', 1, 0
				)
			);
			animOut.play();
			
			current.content.style.zIndex = 50;
			
			current.btn.style.background = "";
			
			// created hook for init tricker
			setElementOn(symbol);
		}
		resetElmTimeout();
	}
	
	function setElementOn(symbol)
	{
		current = elms[symbol];
		
		current.content.style.zIndex = 100;
		
		// part of the Mac FF 2 workaround
		current.content.style.visibility =
		current.title.style.visibility = "visible";
		current.content.style.opacity =
		current.title.style.opacity = 0;
		current.btn.style.background = "#FFF";
		
		var animIn = new Animator();
		animIn.addSubject(
			new NumericalStyleSubject(
				[current.content, current.title], 'opacity', 0, 1
			)
		)
		animIn.play();
	}
}

function resetElmTimeout() {
	clearTimeout(timeoutID);
	timeoutID = setTimeout("rotateElms()", elmRotInterval);	
}

setElementOn(initialSymbol)

} // elmsBox check
