// gets hash value of url, and uses it to open the nested list, as well as any subnodes in that //opened list item. Also displays associated picture for node, calling swapProjectPageImageTo() from
//swapProjectPageImage.js

//BIG NOTE: this fn is meant to operate on the first level of LIs in the aqtree3clickable UL

function openNestedListToAnchor(){
	var urlHashValue;
	urlHashValue = location.hash;

	//if there's no anchor value (i.e., the hash is empty), do nothing
	if(!urlHashValue || urlHashValue <= 0 || urlHashValue == "undefined"){
		return;
	}
	//otherwise, find the anchor, and change its class name to aq3open, per //aqtree3clickable.js
	else{
		//for each link on the page
			//if its hash matches the location hash
				//change the link's containing LI's class to aq3open
				//for each child node
					//if it has a child
						//call recursive fn		
		var i;
		for(i = 0; i < document.links.length; i++){
			if(document.links[i].hash.length > 0){
				if(document.links[i].hash == urlHashValue){
					//relies on situation where A (link) is direct child of LI, which is only
					//node type that can get aq3open className and display some effect on page
					//change class, so node opens
					document.links[i].parentNode.className = "aq3open";
					//display associated image for this hash
					swapProjectPageImageTo(urlHashValue);
					//open all sub-trees for this node
					if(document.links[i].childNodes.length > 0){
						openChildNodeRecursive(document.links[i].parentNode);
					}
					break;
				}
			}
		}
		
	}
}

//for each child node
	//if it's an LI and has an A child 
		//change its class to aq3open
		//break
	//else if it has a child
		//call self
function openChildNodeRecursive(linkItem){
	var i;	
	var currentChildNode;
	for(i = 0; i < linkItem.childNodes.length; i++){
		currentChildNode = linkItem.childNodes[i];
		if(currentChildNode.childNodes.length > 0){
			openChildNodeRecursive(currentChildNode);
		}
		if(currentChildNode.nodeName == "A" && currentChildNode.parentNode.nodeName == "LI"){
			currentChildNode.parentNode.className = "aq3open";
		}
	}
}