/*

	== PHP FILE TREE JAVASCRIPT EXTENSION ==
		
		Based on the Expandable Listmenu Script by Daniel Nolan
		http://www.bleedingego.co.uk/webdev.php
		
		Modified by Cory S.N. LaViska
		http://abeautifulsite.net/
		
	== WHAT IT DOES ==
	
		This script makes the nested lists created by PHP File Tree expand and 
		collapse dynamically.
		
	== USAGE ==
	
		Include the script into the <head></head> section of the appropriate 
		page(s) as shown below:
	
			<script src="php_file_tree.js" type="text/javascript"></script>
			
		All file trees generated by PHP File Tree will automatically collapse to 
		the top level (as specified by $directory) and become dynamic.

	== FAQS ==
	
		Q Can I have more than one file tree on one page?
		A Yes.  You can have as many as you want and they will all function as expected.
		
*/

function init_php_file_tree(nodeary) {
	if (!document.getElementsByTagName) return;
		
	var aMenus = document.getElementsByTagName("LI");
	for (var i = 0; i < aMenus.length; i++) {
		var mclass = aMenus[i].className;
		if (mclass.indexOf("pft-directory") > -1) {
			var submenu = aMenus[i].childNodes;			
			for (var j = 0; j < submenu.length; j++) {
				if (submenu[j].tagName == "A") {
						
						submenu[j].onclick = function() {
						var node = this.nextSibling;
						getSelected(this);
						while (1) {
							if (node != null) {
								if (node.tagName == "UL") {
									var d = (node.style.display == "none")
									node.style.display = (d) ? "block" : "none";
									this.className = (d) ? "open" : "closed";
									//var links = document.getElementsByTagName('a');
									/*for (var i = 0; i < links.length; i++) {
										links[i].style.background =  "";
										links[i].style.color = "#000000";
									}
									if(this.className  == "open"){
										this.style.background = "#0000CC";
										this.style.color = "#FFFFFF";
										document.getElementById('Obj').value = this.name;
									}*/
									
									return false;
								}
								node = node.nextSibling;
							} else {
								return false;
							}
						}
						return false;
					}
					
					submenu[j].className = (mclass.indexOf("open") > -1) ? "open" : "closed";
				}
				var k; var flag=true;
				if (submenu[j].tagName == "UL"){
					for (k=0; k < nodeary.length; k++) {					
						if (nodeary[k] ==submenu[j].id) {
							flag = false
						}						
					}
					if(flag ==false)
						submenu[j].style.display = (mclass.indexOf("open") > -1) ? "block" : "block";
					else
						submenu[j].style.display = (mclass.indexOf("open") > -1) ? "block" : "none";
				}
			}			
		}
	}
	return false;
}

//window.onload = init_php_file_tree;