(function(){

    var DomReady = window.DomReady = {};

	// Everything that has to do with properly supporting our document ready event. Brought over from the most awesome jQuery. 

    var userAgent = navigator.userAgent.toLowerCase();

    // Figure out what browser is being used
    var browser = {
    	version: (userAgent.match( /.+(?:rv|it|ra|ie)[\/: ]([\d.]+)/ ) || [])[1],
    	safari: /webkit/.test(userAgent),
    	opera: /opera/.test(userAgent),
    	msie: (/msie/.test(userAgent)) && (!/opera/.test( userAgent )),
    	mozilla: (/mozilla/.test(userAgent)) && (!/(compatible|webkit)/.test(userAgent))
    };    

	var readyBound = false;	
	var isReady = false;
	var readyList = [];

	// Handle when the DOM is ready
	function domReady() {
		// Make sure that the DOM is not already loaded
		if(!isReady) {
			// Remember that the DOM is ready
			isReady = true;
        
	        if(readyList) {
	            for(var fn = 0; fn < readyList.length; fn++) {
	                readyList[fn].call(window, []);
	            }
            
	            readyList = [];
	        }
		}
	};

	// From Simon Willison. A safe way to fire onload w/o screwing up everyone else.
	function addLoadEvent(func) {
	  var oldonload = window.onload;
	  if (typeof window.onload != 'function') {
	    window.onload = func;
	  } else {
	    window.onload = function() {
	      if (oldonload) {
	        oldonload();
	      }
	      func();
	    }
	  }
	};

	// does the heavy work of working through the browsers idiosyncracies (let's call them that) to hook onload.
	function bindReady() {
		if(readyBound) {
		    return;
	    }
	
		readyBound = true;

		// Mozilla, Opera (see further below for it) and webkit nightlies currently support this event
		if (document.addEventListener && !browser.opera) {
			// Use the handy event callback
			document.addEventListener("DOMContentLoaded", domReady, false);
		}

		// If IE is used and is not in a frame
		// Continually check to see if the document is ready
		if (browser.msie && window == top) (function(){
			if (isReady) return;
			try {
				// If IE is used, use the trick by Diego Perini
				// http://javascript.nwbox.com/IEContentLoaded/
				document.documentElement.doScroll("left");
			} catch(error) {
				setTimeout(arguments.callee, 0);
				return;
			}
			// and execute any waiting functions
		    domReady();
		})();

		if(browser.opera) {
			document.addEventListener( "DOMContentLoaded", function () {
				if (isReady) return;
				for (var i = 0; i < document.styleSheets.length; i++)
					if (document.styleSheets[i].disabled) {
						setTimeout( arguments.callee, 0 );
						return;
					}
				// and execute any waiting functions
	            domReady();
			}, false);
		}

		if(browser.safari) {
		    var numStyles;
			(function(){
				if (isReady) return;
				if (document.readyState != "loaded" && document.readyState != "complete") {
					setTimeout( arguments.callee, 0 );
					return;
				}
				if (numStyles === undefined) {
	                var links = document.getElementsByTagName("link");
	                for (var i=0; i < links.length; i++) {
	                	if(links[i].getAttribute('rel') == 'stylesheet') {
	                	    numStyles++;
	                	}
	                }
	                var styles = document.getElementsByTagName("style");
	                numStyles += styles.length;
				}
				if (document.styleSheets.length != numStyles) {
					setTimeout( arguments.callee, 0 );
					return;
				}
			
				// and execute any waiting functions
				domReady();
			})();
		}

		// A fallback to window.onload, that will always work
	    addLoadEvent(domReady);
	};

	// This is the public function that people can use to hook up ready.
	DomReady.ready = function(fn, args) {
		// Attach the listeners
		bindReady();
    
		// If the DOM is already ready
		if (isReady) {
			// Execute the function immediately
			fn.call(window, []);
	    } else {
			// Add the function to the wait list
	        readyList.push( function() { return fn.call(window, []); } );
	    }
	};
    
	bindReady();
	
})();
var Tree = {
	lft:null,
	rgt:null,
	el:null,
	selected:null,
	nodeText:null,
	clonedNode:null,
	cutting:null,
	timer:null,
	deleted:null,
	count_depth:0,
	init:function(){
		this.setLftRgt();
		this.el = this.$('tree').getElementsByTagName('a');
		for(var i=0;i<this.el.length;i++){
			this.el[i].parentNode.onclick = function(e){
				Tree.stopBubbling(e);
				if(this.getAttribute("nodeDisabled")=='true') return;
				if(this.id=='t1' || this.id=='t2') return;
				Tree.collapseNode(this);
				this.focus();
			}
		}
		this.openUrl();
	},
	openUrl:function(){
		var loc = location.href.substr(location.href.lastIndexOf('/')+1,location.href.length);
		if(loc.lastIndexOf('?')>0) loc = loc.substr(0,loc.lastIndexOf('?'));
		for(var i=0;i<this.el.length;i++){
			if(this.el[i].href.substr(this.el[i].href.lastIndexOf('/')+1,this.el[i].href.length)==loc){
				Tree.openNodeRecursive(this.el[i].parentNode);
				this.el[i].className = 'menuon';
				break;
			}
		}
	},
	getDepth:function(node,e){
		var count =0;
		while(node = node.parentNode){
			if(node.getAttribute("id")=='tree') break;
			if(node.nodeName=='UL'){
				count++;
			}
			node = node.parentNode;
		}
		return count;
	},
	getParent:function(node){
		var obj = node;
		do{
			if(node.getAttribute("id")=='tree') break;
			if(node.nodeName=='LI' && node.id!='t1'){
				obj.setAttribute("parent",node.getAttribute("id"));
			}
		
		} while(node = node.parentNode);
	},
	resetBackGroundColor:function(obj){
		for(var j=0;j<Tree.el.length;j++){
			if(Tree.el[j]!=obj)
				Tree.el[j].style.backgroundColor = 'transparent';
		}
	},
	nodeDisabled:function(nodes /** array **/){
		for(var i=0;i<nodes.length;i++){
			if(nodes[i]!='t1')
				this.setOpacity(this.$(nodes[i]),50);
			this.$(nodes[i]).setAttribute("nodeDisabled","true");
			this.$(nodes[i]).firstChild.style.cursor = 'text!important';
		}
	},
	collapse:function(){
		var li = this.$('tree').getElementsByTagName('li');
		for(var i=0;i<li.length;i++){
			this.collapseNode(li[i]);
		}
		this.collapseNode(li[0]);
	},
	doNode:function(node){
		if(node.previousSibling){ 
			Tree.lft = parseInt(node.previousSibling.getAttribute("rgt"))+1;
		} 
		var lft = Tree.lft;
		var rgt = Tree.rgt;
		rgt = (Tree.lft+(node.getElementsByTagName('li').length*2))+1;
		node.setAttribute("lft",lft);
		node.setAttribute("rgt",rgt);
		Tree.lft++;
	},
	setLftRgt:function(){
		var li = this.$('tree').getElementsByTagName('li');
		Tree.lft = 1;
		Tree.rgt = li.length*2;
		for(var k=0;k<li.length;k++){
			Tree.doNode(li[k]);
		}
	},
	collapseNode:function(obj){
		var node = obj;
		for(var i=0;i<node.childNodes.length;i++){
			if(node.childNodes.item(i).nodeName=="UL"){
				node.childNodes.item(i).style.display = Tree.getCurrentStyle(node.childNodes.item(i),'display')=='block'?'none':'block';
				Tree.getANode(obj);
				
			}
		}
	},
	openNode:function(obj){
		var node = obj;
		if(node.id=='t1' || node.id=='t2') return;
		if(obj.className!='folder_closed') return;
		for(var i=0;i<node.childNodes.length;i++){
			//alert(node.childNodes.item(i).nodeName);
			if(node.childNodes.item(i).nodeName=="UL"){
				node.childNodes.item(i).style.display = 'block';
				Tree.getANode(obj);
				return;
				
			}
		}
	},
	openNodeRecursive:function(obj){
		var node = obj;
		for(var i=0;i<node.childNodes.length;i++){
			//alert(node.childNodes.item(i).nodeName);
			if(node.childNodes.item(i).nodeName=="UL"){
				node.childNodes.item(i).style.display = 'block';
				Tree.getANode(obj);
			}
		}
		while(obj.parentNode){
			if(obj.nodeName=='UL'){
				obj.style.display = 'block';
				
			}
			if(obj.nodeName=='LI'){
				if(obj.className != '')
					obj.className = 'folder';
			}
			obj = obj.parentNode;
		}
	},
	getANode:function(obj){
		obj.className = obj.className=='folder_closed'?'folder':'folder_closed';
	},
	$:function(){
		return document.getElementById(arguments[0]);
	},
	stopBubbling:function(e){
		if (!e) var e = window.event;
		e.cancelBubble = true;
		if (e.stopPropagation) e.stopPropagation();
	},
	getCurrentStyle:function(obj,prop){
		return document.defaultView?document.defaultView.getComputedStyle(obj,null).getPropertyValue(prop):
		obj.currentStyle[prop];
	}
}

DomReady.ready(function() {
	Tree.init();
});