/**
 * @author Arturas Paleicikas <paleicikas@gmail.com>
 * @last 2006-10-06
 */
function tree(title, base_href, img_base_href){
	this.nodes = new Array();
	this.icons = new Array(6);
	this.base_href = base_href;
	this.img_base = img_base_href;
	this.title = title;

	this.pIco = function() {
		this.icons[0] = new Image();
		this.icons[0].src = this.img_base+"plus.gif";
		this.icons[1] = new Image();
		this.icons[1].src = this.img_base+"plusbottom.gif";
		this.icons[2] = new Image();
		this.icons[2].src = this.img_base+"minus.gif";
		this.icons[3] = new Image();
		this.icons[3].src = this.img_base+"minusbottom.gif";
	}
	
	this.get = function(arrName, startNode) {
		this.nodes = arrName;
		if(this.nodes.length >= 0) {
			this.pIco();
			if (startNode == null) startNode = 0;
			if (startNode !=0) {
				var nodeValues = this.nodes[this.getArrId(startNode)].split("|");
				document.write("<img src=\""+this.img_base+"page.gif\" align=\"absbottom\" alt=\"\" /><a "+nodeValues[5]+" target=\"_parent\" href=\"" + nodeValues[3] + "\">" + nodeValues[2] + "</a><br />");
			} else document.write("<img src=\""+this.img_base+"base.gif\" align=\"absbottom\" alt=\"\" /><a target=\"_parent\" href=\""+this.base_href+"\">"+this.title+"</a /><br />");
			var recursedNodes = new Array();
			this.addNode(startNode, recursedNodes);
		}
	}

	this.getArrId = function(node) {
		for (i=0; i<this.nodes.length; i++) {
			var nodeValues = this.nodes[i].split("|");
			if (nodeValues[0]==node) return i;
		}
	}

	this.hasChildNode = function(parentNode) {
		for (i=0; i< this.nodes.length; i++) {
			var nodeValues = this.nodes[i].split("|");
			if (nodeValues[1] == parentNode) return true;
		}
		return false;
	}

	this.lastSibling = function(node, parentNode) {
		var lastChild = 0;
		for (i=0; i< this.nodes.length; i++) {
			var nodeValues = this.nodes[i].split("|");
			if (nodeValues[1] == parentNode)
				lastChild = nodeValues[0];
		}
		if (lastChild==node) return true;
		return false;
	}

	this.addNode = function(parentNode, recursedNodes) {
		document.write("<nobr>");
		for (var i = 0; i < this.nodes.length; i++) {
			var nodeValues = this.nodes[i].split("|");
			if (nodeValues[1] == parentNode) {
				
				var ls	= this.lastSibling(nodeValues[0], nodeValues[1]);
				var hcn	= this.hasChildNode(nodeValues[0]);

				for (g=0; g<recursedNodes.length; g++) {
					if (recursedNodes[g] == 1) document.write("<img src=\""+this.img_base+"line.gif\" align=\"absbottom\" alt=\"\" />");
					else  document.write("<img src=\""+this.img_base+"empty.gif\" align=\"absbottom\" alt=\"\" />");
				}

				if (ls) recursedNodes.push(0);
				else recursedNodes.push(1);

				if (ls){
					document.write("<img src=\""+this.img_base+"joinbottom.gif\" align=\"absbottom\" alt=\"\" />");
				} else {
					document.write("<img src=\""+this.img_base+"join.gif\" align=\"absbottom\" alt=\"\" />");
				}

				if (hcn) {
					document.write("<img id=\"icon" + nodeValues[0] + "\" src=\""+this.img_base+nodeValues[4]+"\" align=\"absbottom\" alt=\"\" /><a "+nodeValues[5]+" target=\"_parent\" href=\"" + nodeValues[3] + "\">"+nodeValues[2]+"</a><br />")

				} else {
					document.write("<img id=\"icon" + nodeValues[0] + "\" src=\""+this.img_base+nodeValues[4]+"\" align=\"absbottom\" alt=\"Page\" /><a "+nodeValues[5]+" target=\"_parent\" href=\"" + nodeValues[3] + "\">"+nodeValues[2]+"</a><br />")
				}
				
			
				if (hcn) {
					document.write("<div id=\"div" + nodeValues[0] + "\"");
					document.write(">");
					this.addNode(nodeValues[0], recursedNodes);
					document.write("</div>");
				}
				
				recursedNodes.pop();
			}
		}
		document.write("</nobr>");
	}

	this.oc = function(node, pic, bottom) {
		var theDiv = document.getElementById("div" + node);
		var theJoin	= document.getElementById("join" + node);
		var theIcon = document.getElementById("icon" + node);
		
		if (theDiv.style.display == 'none') {
			if (bottom==1) theJoin.src = this.icons[3].src;
			else theJoin.src = this.icons[2].src;
			theIcon.src = pic;
			theDiv.style.display = '';
		} else {
			if (bottom==1) theJoin.src = this.icons[1].src;
			else theJoin.src = this.icons[0].src;
			theIcon.src = pic;
			theDiv.style.display = 'none';
		}
	}

	if(!Array.prototype.push) {
		function array_push() {
			for(var i=0;i<arguments.length;i++)
				this[this.length]=arguments[i];
			return this.length;
		}
		Array.prototype.push = array_push;
	}

	if(!Array.prototype.pop) {
		function array_pop(){
			lastElement = this[this.length-1];
			this.length = Math.max(this.length-1,0);
			return lastElement;
		}
		Array.prototype.pop = array_pop;
	}
}