// Activate rollovers & preload images.
// NOTE: images that get rollovers must have a class of roll
//			and have an associated *_o.gif file to preload

function prepRollovers() {
	var rollfound=0;
	if (document.getElementsByTagName) {
		// grab all the images on a page
		for (z=0;z<document.getElementsByTagName("img").length;z++) {
			thisImg = document.getElementsByTagName("img")[z];
			// check that its got the proper class
			if (thisImg.className !=null) { /* safari seems to break when these two tests are combined */
				if (thisImg.className.indexOf("roll") != -1) {
					rollfound++;
					// define states, preload the image and attach the event handlers
					thisImg.out = new Image(); thisImg.out.src = thisImg.src;
					thisImg.over = new Image(); thisImg.over.src = thisImg.src.toString().replace(/.gif/i,"_o.gif");
					thisImg.parentNode.onmouseover = function () {
						this.getElementsByTagName("img")[0].src = this.getElementsByTagName("img")[0].over.src;
					};
					thisImg.parentNode.onmouseout = function () {
						this.getElementsByTagName("img")[0].src = this.getElementsByTagName("img")[0].out.src;				
					};
				}
			}
			
		}
	}
}


function positionToolboxNav() { // this just takes the nav and makes it flush right

	// a little bit of a hack because i can't add the offsets the same in each browser

	if ((navigator.appName.indexOf('Microsoft') != -1) && (navigator.platform.indexOf("Win") != -1)) {
		document.getElementById("toolboxnav").style.left = 
			(document.getElementById("toolboxnav").parentNode.parentNode.offsetLeft
			+ document.getElementById("toolboxnav").parentNode.offsetLeft
			+ document.getElementById("toolboxnav").parentNode.offsetWidth
			- 150)
			+ "px";
	} else {
		document.getElementById("toolboxnav").style.left = 
			(document.getElementById("toolboxnav").parentNode.offsetLeft
			+ document.getElementById("toolboxnav").parentNode.offsetWidth
			- 150)
			+ "px";
	}

}

function sumOffsetLefts(node) {
	var currentTally = 0;
	if (node.parentNode) {
		currentTally += sumOffsetLefts(node.parentNode);
	} else {
		curentTally += node.offsetLeft;
	}
	return currentTally;
}



// NOTE: with the change to just center these no calculations need to be made.
//			thus all code but step 1 can be removed.
function showCaption(thisNav) {

	// step 1: set text
	document.getElementById("navTips").innerHTML = thisNav.title;

//198 alert(thisNav.offsetLeft);
//991 alert(document.getElementById("navTips").offsetWidth);
	// step 2: calc new position
	if (thisNav.offsetLeft >0) { // everything but IE/win
		var newOffsetLeft = (thisNav.offsetLeft + 0.5*thisNav.offsetWidth - 0.5*document.getElementById("navTips").offsetWidth);
	} else {
		var newOffsetLeft = (thisNav.offsetLeft + thisNav.parentNode.offsetLeft + 0.5*thisNav.offsetWidth - 0.5*document.getElementById("navTips").offsetWidth);
	}
//-186.5 alert(newOffsetLeft);
	// step 3a: test bounds - right edge
	if (newOffsetLeft+document.getElementById("navTips").offsetWidth > document.getElementById("mainnav").offsetLeft+document.getElementById("mainnav").offsetWidth) {
		newOffsetLeft = document.getElementById("mainnav").offsetLeft + document.getElementById("mainnav").offsetWidth - document.getElementById("navTips").offsetWidth;
	}
//-186.5 alert(newOffsetLeft);
	// step 3b: test bounds - left edge
	if (newOffsetLeft < document.getElementById("mainnav").offsetLeft) {
		newOffsetLeft = document.getElementById("mainnav").offsetLeft+10;
	}	
//198 alert(newOffsetLeft);	

	// step 4: set position and show
//	document.getElementById("navTips").style.left = newOffsetLeft+"px";
//	document.getElementById("navTips").style.visibility = 'visible';
}
function hideCaption(thisNav) {
//	document.getElementById("navTips").style.visibility = 'hidden';
	document.getElementById("navTips").innerHTML = '';

}

// This is for the top nav toolbox dropdown
function showToolboxNav() {
    positionToolboxNav();
    document.getElementById('toolboxnav').style.display='block';
}
function hideToolboxNav() {
    document.getElementById('toolboxnav').style.display='none';
}

// This is the left had nav stuff
function leftNavOver(whichItem) {
	// double check that they're all closed.. the flyouts seem sticky sometimes
	
	for (var x=0; x<whichItem.parentNode.childNodes.length; x++) {
		if (whichItem.parentNode.childNodes[x].nodeName == "LI") {
			whichItem.parentNode.childNodes[x].childNodes[0].style.backgroundColor = baseBg;
			whichItem.parentNode.childNodes[x].childNodes[0].style.color = baseColor;
			whichItem.parentNode.childNodes[x].childNodes[1].style.display = 'none';
		}
	}
	whichItem.childNodes[0].style.backgroundColor = rolloverBg;
	whichItem.childNodes[0].style.color = rolloverColor;
	whichItem.childNodes[1].style.display = 'block';
}

function noleftNavOver(whichItem) {
       whichItem.childNodes[0].style.backgroundColor = rolloverBg;
       whichItem.childNodes[0].style.color = rolloverColor;
       whichItem.childNodes[1].style.display = 'block';
       whichItem.childNodes[1].style.display = 'none';

}


function leftNavOut(whichItem) {
	whichItem.childNodes[0].style.backgroundColor = baseBg;
	whichItem.childNodes[0].style.color = baseColor;
	whichItem.childNodes[1].style.display = 'none';

}

function noleftNavOut(whichItem) {
	    whichItem.childNodes[0].style.backgroundColor = baseBg;
	    whichItem.childNodes[0].style.color = baseColor;
	    whichItem.childNodes[1].style.display = 'block';
	    whichItem.childNodes[1].style.display = 'none';

}
// This is the icon rollover stuff
function iconOver(thisIcon) {
	document.getElementById("iconCaption").innerHTML = "loading"
	document.getElementById("iconCaption").innerHTML = thisIcon.title;
}

function iconOut(thisIcon) {
	document.getElementById("iconCaption").innerHTML = "";
}


function initPage() {
    prepRollovers();
    positionToolboxNav();
}