// JavaScript Document

// http://www.danwebb.net/lab/archives/000018.html

	function TreeMenu(id) {
		if (document.getElementById) {
			this.menuRoot = document.getElementById(id);
			var listEls = this.menuRoot.getElementsByTagName("LI");
			for (var i = 0; i < listEls.length; i++) {
				if (listEls[i].className.indexOf("folder")>-1) {
					listEls[i].getElementsByTagName("A")[0].onclick = function () {
						this.parentNode.toggleOpen();
						return false;
					}
					listEls[i].toggleOpen = function() {
						(this.className.indexOf("closed")>-1)?this.open():this.close();
					}
					listEls[i].open = function() {
						this.className = this.className.replace(/\sclosed(\s|$)/, "");
					}
					listEls[i].close = function() {
						this.className += " closed";
					}
					listEls[i].toggleOpen();
				}
			}
		}
	}	
	
	TreeMenu.prototype.expandTo = function(id) {
		if (document.getElementById) {
			var node = document.getElementById(id);
			while (node!=null && node!=this.menuRoot) {
				if (node.open) node.open();
				node = node.parentNode;
			}
		}
	}
	
	window.onload = function() {
		menu = new TreeMenu("infoTree");
		menu = new TreeMenu("demoTree");
		menu = new TreeMenu("newsTree");
	}