﻿function stopEvent(e) {
	if (!e) var e = window.event;
	e.cancelBubble = true;
	if (e.stopPropagation) e.stopPropagation();
}

TreeMenuNode.prototype = {
	isFolder : false,
	folded : null,
	
	fold : function() {
		this.domref.className = this.domref.className.replace("minus","plus");
		this.folded = true;
	},

	unfold : function() {
		this.domref.className = this.domref.className.replace("plus","minus");
		this.folded = false;
	},

	mousedown : function(e) {
		if (this.isFolder) {
			if (this.folded) this.unfold();
			else this.fold();
		}
		stopEvent(e);
	}
}

function TreeMenuNode(objHTMLDefinitionData) {
	this.domref = objHTMLDefinitionData;
	if (this.domref.className) this.isFolder = true;
	var This = this;
	this.domref.onmousedown = function(e){This.mousedown(e);};

	this.folded = !!this.domref.className.match('plus');
}

TreeMenu.prototype = {
	nodes : [],

	returnFalse : function() {
		return false;
	}
}

function TreeMenu(objHTMLTree) {
	var dds = objHTMLTree.getElementsByTagName('dd');
	var as = objHTMLTree.getElementsByTagName('a');

	for (var i = 0; i < dds.length; i++) {
		this.nodes.push(new TreeMenuNode(dds[i]));
	}
	//for (var i = 0; i < as.length; i++) {
	//	as[i].onclick = this.returnFalse;
	//}
}

window.onload = function() {
	new TreeMenu(document.getElementById("tree"));
}


function toggle(obj) {
    var oP = document.getElementsByTagName('dd');//the collection of <dd> tags
    for(var i=0;i<oP.length;i++){
        oP[i].className = ('minus');//open 'em all
        //alert(oP[i].className);
    }
	
}
