// JavaScript Document

// <![CDATA[

// onload look for the personNav div, if it's there then bind the showBios function to the onclick event for all anchor tags within personNav
window.onload=function()	{		
	if (document.getElementById("personNav")) {	
		if (document.getElementsByTagName) {
			var tempEl = document.getElementById("personNav").getElementsByTagName("A");			
			for( var i=0; i < tempEl.length; i++ ){	
				tempEl[i].onclick = function(){
				return showBios(this);
				};
			}
		}
	}
	//look for print and printAll links in main content
	if (document.getElementsByTagName) {
		var tempEl = document.getElementsByTagName("A");			
		for( var i=0; i < tempEl.length; i++ ){	
			if ((tempEl[i].className == "print") || (tempEl[i].className == "printAll")) {
				tempEl[i].onclick = function(){
				return printBios(this);
				};
			}
		}
	}
}

// showBios will show the bio the user clicked on and hide all others
function showBios(linkElement) {
	// use the HREF to grab the bio ID
	var firstIndex = (parseInt(linkElement.href.indexOf("#")) + 1);
	var lastIndex = linkElement.href.length;
	var theBio = document.getElementById(linkElement.href.substring(firstIndex,lastIndex));
	// turn off all anchors in the personNav
	var tempEl = document.getElementById("personNav").getElementsByTagName("A");			
	for( var i=0; i < tempEl.length; i++ ){	
		tempEl[i].className = "";
	}
	// turn the anchor user clicked on
	linkElement.className = "on";
	// loop through all class=person and hide them
	var allBios = document.getElementsByTagName("DIV");			
	for( var i=0; i < allBios.length; i++ ){
		if (allBios[i].className == "person") {
			allBios[i].style.display = "none";
		}
	}
	// show the bio the user clicked
	theBio.style.display = "block";
	return false;
}

// print bios, window.print for print class, add override class for printAll class
function printBios(pEl) {	
	var theOpenBio = getGroupParent(pEl,"DIV");
	//alert(theOpenBio.innerHTML);
	if (pEl.className == "printAll") {
		var tempEl = document.getElementsByTagName("DIV");			
		// show all bios
		for( var i=0; i < tempEl.length; i++ ){	
			if (tempEl[i].className == "person") {
				tempEl[i].style.display = "block";					
			}
		}	
		// print
		window.print();		
		// hide all bios
		for( var i=0; i < tempEl.length; i++ ){	
			if (tempEl[i].className == "person") {
				tempEl[i].style.display = "none";					
			}
		}
		
	} else {		
		window.print();
	}
	// turn on the bio they had open
	theOpenBio.style.display = "block";
	return false;
}

function getGroupParent(pNode,strTagName) {
	var groupParent = pNode.parentNode;
	while (groupParent.tagName != strTagName.toUpperCase()) {
		groupParent = groupParent.parentNode;
	}	
	return groupParent;
}


// ]]>

