// pn.js - Page (Side) Navigation Scripts
var pnSetupFinished=0;
var pnImages = new Array();



function collapseBranch (which) {
	if (pnSetupFinished) {
		// alert(which.nodeName);
		if (which.childNodes.length > 1) { // double check to prevent closing nodes w. no children
			for (i=0;i<which.childNodes[1].childNodes.length;i++) { // all the children of the 2nd child (a UL)
				// skip text nodes
				if (which.childNodes[1].childNodes[i].nodeName == "LI") { which.childNodes[1].childNodes[i].style.display="none"; }
			}
		}
		// close the tree icon if this is a n item with sub elements
		if (which.className.indexOf("subtopic") != -1) {
			which.style.listStyleImage = "url(../_media/_i/pn/1_off.gif)";
			which.pnhState = 0;
		}
	}
}
function expandBranch (which) {
	if (pnSetupFinished) {
		// open this branch
		for (i=0;i<which.childNodes[1].childNodes.length;i++) { // all the children of the 2nd child (a UL)
			// skip text nodes
			if (which.childNodes[1].childNodes[i].nodeName == "LI") { which.childNodes[1].childNodes[i].style.display="list-item"; }
		}
		// set the list item properly
		which.style.listStyleImage = "url(../_media/_i/pn/1_actopen.gif)";
		which.pnhState = 1;
	}
}

function toggleBranch (which) {
 	if (pnSetupFinished) {
		//alert (which.pnhState);
		if (which.pnhState == 1) {
			collapseBranch(which);
		} else {
			// collapse all sibling brances and expand this one
			
			// alert(which.parentNode.childNodes.length);
			for (x=0;x<which.parentNode.childNodes.length;x++) {
				if (which.parentNode.childNodes[x] == which) {
					expandBranch(which.parentNode.childNodes[x]);
				} else if (which.parentNode.childNodes[x].nodeName=="LI") { // only try and collapse LIs
					collapseBranch(which.parentNode.childNodes[x]);
				}
			}
		}
		return false;
	}
	return true;
}


function handleNodeOver(which) {
	if (pnSetupFinished) {
		if (which.className.indexOf("current") != -1) { // if node is for the given page bail
			return;
		} else if (which.className.indexOf("view") != -1) { // if node is a view
			which.getElementsByTagName("a")[0].style.color= "rgb(205,217,225)";
			// if node is a top level view
			which.style.listStyleImage = "url(../_media/_i/pn/1_v_act.gif)";
			// if node is a 2nd level view
		} else if (which.className.indexOf("subtopic") != -1) { // if node is a top level category
			which.getElementsByTagName("a")[0].style.color= "rgb(205,217,225)";
			//alert(which.pnhState);
			if (which.pnhState) {// if node is open
				which.style.listStyleImage = "url(../_media/_i/pn/1_actopen.gif)";
			} else { // if node is closed
				which.style.listStyleImage = "url(../_media/_i/pn/1_act.gif)";
			}
		} else if (which.className.indexOf("data") != -1) { // if node is a data item
			which.getElementsByTagName("a")[0].style.color= "rgb(205,217,225)";
		}
	}
}

function handleNodeOut(which) {
	if (pnSetupFinished) {
		if (which.className.indexOf("current") != -1) { // if node is for the given page bail
			return;
		} else if (which.className.indexOf("view") != -1) { // if node is a view
			which.getElementsByTagName("a")[0].style.color= "rgb(42,51,53)";
			// if node is a top level view
			which.style.listStyleImage = "url(../_media/_i/pn/1_v_off.gif)";
			// if node is a 2nd level view
		} else if (which.className.indexOf("subtopic") != -1) { // if node is a top level category
			which.getElementsByTagName("a")[0].style.color= "rgb(119,133,137)";
			if (which.pnhState) {// if node is open
				which.style.listStyleImage = "url(../_media/_i/pn/1_open.gif)";
			} else { // if node is closed
				which.style.listStyleImage = "url(../_media/_i/pn/1_off.gif)";
			}
		} else if (which.className.indexOf("data") != -1) { // if node is a data item
			which.getElementsByTagName("a")[0].style.color= "rgb(42,51,53)";
		}
	}
}

function initTree(treeid) {
	if (document.getElementById) {
	
		// hack to get around moz bug 50630 - show the selection arrow if
		// 		its not mozilla
		if ((navigator.userAgent.indexOf("Gecko") == -1) ||
			(navigator.userAgent.indexOf("KHTML") != -1)) {
			if (document.getElementById("snarrow")) {
				document.getElementById("snarrow").style.display = "inline";
			}
		}
	
	
	
		// if the LI has a class of current its active
		for (i=0;i<document.getElementById(treeid).getElementsByTagName("li").length;i++) {
			document.getElementById(treeid).getElementsByTagName("li")[i].pnhState = 0;
			if (document.getElementById(treeid).getElementsByTagName("li")[i].className.indexOf("open") != -1) {
				document.getElementById(treeid).getElementsByTagName("li")[i].pnhState = 1;			
			}
		}
		
		// preload images for different states
		pnImages["topView"] = new Image();
		pnImages["topViewOver"] = new Image();
		pnImages["topOpen"] = new Image();
		pnImages["topOpenOver"] = new Image();
		pnImages["topClosed"] = new Image();
		pnImages["topClosedOver"] = new Image();
		pnImages["topView"].src = "../_media/_i/pn/1_v_off.gif";
		pnImages["topViewOver"].src = "../_media/_i/pn/1_v_act.gif";
		pnImages["topOpen"].src = "../_media/_i/pn/1_open.gif";
		pnImages["topOpenOver"].src = "../_media/_i/pn/1_actopen.gif";
		pnImages["topClosed"].src = "../_media/_i/pn/1_off.gif";
		pnImages["topClosedOver"].src = "../_media/_i/pn/1_act.gif";
		
		
		pnSetupFinished = 1;
	}
}