var tNavAnimationTimer = null;
var iMaxNavStages = 5;
var iTimerSpeed = 15;

function startNavAnimations() {
	tNavAnimationTimer = window.setInterval("updateNavAnimations()",(iTimerSpeed * (document.all ? .85 : 1)));	// last browser sniff is to lessen the noticeability of the javascript performance differences between IE and everything else
}

function stopNavAnimations() {
	window.clearInterval(tNavAnimationTimer);
	tNavAnimationTimer = null;
}

function updateNavAnimations() {
	var iItemsStillMoving = 0;
	var listObj = document.getElementById("nav");					// get a handle to the list
	var aElements = listObj.getElementsByTagName("LI");				// get an array of the list elements in the list
	for (var i=0; i<aElements.length; i++) {						// loop through the array of list elements
		if (aElements[i].className && aElements[i].className.indexOf("selected")>=0) {	// if it is the selected nav item
		} else {													// if it is not the selected nav item
			var aObj = aElements[i].getElementsByTagName("A")[0];	// get a handle to the link in the list element
			var sCurrentClass = aObj.className;						// save the class in to a string so that we don't have to keep accessing the DOM
			if (sCurrentClass == "o0") {							// if it is already in its rest state
			} else if (sCurrentClass == "o"+iMaxNavStages) {		// if this is the furthest that it extends and it was being pulled out
			} else if (sCurrentClass == "i1") {						// if it was being pulled back in and it's on the final step
				aObj.className = "o0";								// mark the item as being at rest, and don't increment the counter of items still in motion
			} else {												// if it is still in the middle of a motion
				iItemsStillMoving++;
				var sDirection = sCurrentClass.substring(0,1);
				var sCurrentStep = parseInt(sCurrentClass.substring(1,sCurrentClass.length),10);
				aObj.className = sDirection + (sCurrentStep + (sDirection=="o" ? +1 : -1));			// increment the class name to the next stage, preserving the direction
			}
		}
	}
	if (iItemsStillMoving<=0) {
		stopNavAnimations();
	}
}

function handleNavMouseOver(aObj) {
	if (aObj.parentNode.className.indexOf("selected")<0) {	// if it is not the current page's list item, start a hover animation to slide the item out
		var sCurrentClass = aObj.className;
		if (sCurrentClass=="o0") {
			aObj.className = "o1";
		} else {
			aObj.className = "o" + sCurrentClass.substring(1,sCurrentClass.length);	// swap the moving direction
		}
		if (tNavAnimationTimer==null) {
			startNavAnimations();
		}
	}
}

function handleNavMouseOut(aObj) {
	if (aObj.parentNode.className.indexOf("selected")<0) {	// if it is not the current page's list item, start a hover animation to slide the item back in
		var sCurrentClass = aObj.className;
		aObj.className = "i" + sCurrentClass.substring(1,sCurrentClass.length);	// swap the moving direction 
	}
	if (tNavAnimationTimer==null) {
		startNavAnimations();
	}
}

var oTagline = null;
function animateTagline() {
	oTagline = document.getElementById("welcometagline");
	if (oTagline) {
		var sOpacityInstruction =  "oTagline.style.filter = \"alpha(opacity=" + "{0}" + ")\";\
									oTagline.style.opacity = (" + "{0}" + "/100);\
									oTagline.style.mozOpacity = (" + "{0}" + "/100);";
		for (var i=0; i<100; i+=10) {
			setTimeout((sOpacityInstruction.split("{0}").join(i)),(500+(5*i)));
		}
		if (document.all) {	// If it's Internet Explorer
			setTimeout("oTagline.style.filter='';",(500+(5*i)));	// Correct the bug where filtered text appears with dark fringing unless you use a background color
		}
	}
}

window.onload = animateTagline;



/* Dynamic illustration behaviors */

var oCaptionTable;
var bMovingCaptionTable = false;
function setTechIllustrationHighlight(areaObj,sGroup,iPosition) {
	if (bMovingCaptionTable == false) {
		oCaptionTable = document.getElementById("techpicCaption").getElementsByTagName("TABLE")[0];
		var oHighlight1 = document.getElementById("techpicHighlight1");
		var oHighlight2 = document.getElementById("techpicHighlight2");
		var oHighlight;
		var pSource = {"top":parseFloat(oCaptionTable.offsetTop), "left":parseFloat(oCaptionTable.offsetLeft)};
		var pDestination = {"top":0,"left":(-196*(iPosition-1))};
	
		if (sGroup=="overview") {
			oHighlight1.style.display = "block";
			oHighlight2.style.display = "none";
			oHighlight = oHighlight1;
			pDestination.top = 0;
		} else {
			oHighlight1.style.display = "none";
			oHighlight2.style.display = "block";
			oHighlight = oHighlight2;
			pDestination.top = -334;
		}
		
		// move the highlight to the position of the area
		var aCoordinates = areaObj.coords.split(",");
		var iLeftMostCoord = 50000;
		var iTopMostCoord = 50000;
		for (var i=0; i<aCoordinates.length; i+=2) {
			if (iLeftMostCoord>parseInt(aCoordinates[i],10)) { iLeftMostCoord = parseInt(aCoordinates[i],10); }
			if (iTopMostCoord>parseInt(aCoordinates[i+1],10)) { iTopMostCoord = parseInt(aCoordinates[i+1],10); }
		}
		oHighlight.style.top = (iTopMostCoord+2) + "px";
		oHighlight.style.left = (iLeftMostCoord+2) + "px";
		
		// smoothly scroll the table to the source position to the destination position
		var iMaxScrollSteps = 15;
		for (var i=1; i<=iMaxScrollSteps; i++) {
			var fPercentage = (i/iMaxScrollSteps);
			var fNewTop = (fPercentage * (parseFloat(pDestination.top)-parseFloat(pSource.top))) + parseFloat(pSource.top);
			var fNewLeft = (fPercentage * (parseFloat(pDestination.left)-parseFloat(pSource.left))) + parseFloat(pSource.left);
			setTimeout("oCaptionTable.style.top = '" + fNewTop + "'+'px';\
						oCaptionTable.style.left = '" + fNewLeft + "'+'px'",(i*iTimerSpeed));
		}
	}
}



