/* 	Qualidigm Left Nav Logic
	v.1
	4/26/06

   Left Nav Structure
   ------------------
   IE-Win interprets the DOM tree differently than all other browsers
   Therefore we have added separate support for this.
*/
leftNav = function() {
	var browser = navigator.appName;
	var platform = navigator.platform;
	var pageid = document.getElementById("pageID").content;	
	
	//Check for page id
	if (document.getElementById(pageid)){
		var selectedNode = document.getElementById(pageid);		
	}
	else {
		var selectedNode = document.getElementById("0");
	}
		
	//Current item class name assignment
	selectedNode.firstChild.className = "current";
		
	//Condition for items that are too deep to display but must have their parent node highlighted
	if ((selectedNode.parentNode.parentNode.id != "left") && (selectedNode.parentNode.parentNode.parentNode.parentNode.id != "left") && (selectedNode.parentNode.parentNode.parentNode.parentNode.parentNode.parentNode.id != "left")){
		var testNode = selectedNode;
		var counter = 1;
		while (testNode.parentNode.parentNode.id != "left") {
			counter++;
			testNode = testNode.parentNode.parentNode;
		}
		testNode = selectedNode;
		for (z = 0; z < counter-3; z++) {
			testNode = testNode.parentNode.parentNode;
		}
		testNode.className = "current";
	}
	
	//Special handling for children of top elements
	if ((selectedNode.parentNode.parentNode.id == "left") && (selectedNode.getElementsByTagName("li").length > 0)) {
	    //get all li elements under the top lever li (like 'Hospital')
		var subNode = selectedNode.getElementsByTagName("li");
		
		//loop through these child LIs
		for (i = 0; i < subNode.length; i++) {
		    //if child has it's own kids of LI type
			if (subNode[i].getElementsByTagName("li").length > 0)
			{
			    //pull them into variable subGranLIs
			    var subGranLIs = subNode[i].getElementsByTagName("li");

                //iterate through these grandchildren
			    for (j = 0; j < subGranLIs.length; j++) 
			    {
			        //hide each
			        subGranLIs[j].style.display = 'none';
			    }
//legacy code. Doesn't fukin' work!!!		
//              subNode[i].childNodes[2].style.display = "none"; 
			}
		}
	}
	
	//Start Main Functionality
	hideSiblings(browser, platform, selectedNode);
	
	while (selectedNode.parentNode.parentNode.id != "left") {
		selectedNode = selectedNode.parentNode.parentNode;
		hideSiblings(browser, platform, selectedNode);
	}
	
	document.getElementById("left").getElementsByTagName("ul")[0].style.display = "block";
	
	//Fix IE rendering bug 
	if ((platform == "Win32") && (browser == "Microsoft Internet Explorer") && (document.getElementById("bodyBlock"))) {
		var leftHeight = document.getElementById("left").offsetHeight;
		var bodyHeight = document.getElementById("bodyBlock").offsetHeight;
		if (bodyHeight > leftHeight)
			document.getElementById("left").style.height = bodyHeight;
	}
}

function hideSiblings(browser, platform, selectedNode) {
	if ((browser == "Microsoft Internet Explorer") && (platform == "Win32")) { //ie-win fix
		var nNode = selectedNode.nextSibling;		
		var pNode = selectedNode.previousSibling;
		while (nNode) {
		    //if child has it's own kids of LI type
			if (nNode.getElementsByTagName("li").length > 0)
			{		
		        //pull them into variable subGranLIs
		        var subGranLIs = nNode.getElementsByTagName("li");

                //iterate through these grandchildren
		        for (j = 0; j < subGranLIs.length; j++) 
		        {
		            //hide each
		            subGranLIs[j].style.display = 'none';
		        }		
		    }
//legacy code. Doesn't fukin' work!!!		
//			if (nNode.childNodes[2])
//				nNode.childNodes[2].style.display = "none";
			nNode = nNode.nextSibling;
		}
		while (pNode) {
		    //if child has it's own kids of LI type
			if (pNode.getElementsByTagName("li").length > 0)
			{		
		        //pull them into variable subGranLIs
		        var subGranLIs = pNode.getElementsByTagName("li");

                //iterate through these grandchildren
		        for (j = 0; j < subGranLIs.length; j++) 
		        {
		            //hide each
		            subGranLIs[j].style.display = 'none';
		        }		
		    }	
//legacy code. Doesn't fukin' work!!!				    	
//			if (pNode.childNodes[2])
//				pNode.childNodes[2].style.display = "none";
			pNode = pNode.previousSibling;
		}
	}
	
	else {		
		try {
			var nNode = selectedNode.nextSibling.nextSibling;		
			var pNode = selectedNode.previousSibling.previousSibling;
		}
		catch (e) {	}
		while (nNode) {
			if ((nNode.getElementsByTagName("li").length) > 0)			
				nNode.childNodes[2].style.display = "none";			
			try { nNode = nNode.nextSibling.nextSibling; }
			catch (f) { break; }
		}
		while (pNode) {
			if ((pNode.getElementsByTagName("li").length) > 0)			
				pNode.childNodes[2].style.display = "none";
			try { pNode = pNode.previousSibling.previousSibling; }
			catch (g) { break; }
		}
	}
}

window.onload = leftNav;