

treenode.prototype.toggle = function(){
	if(this.opened){
		this.collapse();
	}else{
		this.expand();
	}
}

treenode.prototype.expand = function(){

	if(this.src || this.oNode.oNodeChilds.childNodes.length){
		
		if(this.src && !this.loaded){
			this.load();
			return;
		}
		
		this.oNode.oNodeChilds.style.display = 'block';
		this.oNode.oNodeIcon.src = this.openIcon;
		this.opened = true;
		
		// set toggle icons
		if(this.getNextSibling()){
			this.oNodeImg.src = treeConfig.tMinusIcon;
			this.oNode.style.backgroundImage = 'url('+treeConfig.iIcon+')';
		}else{
			if(this.oNodeImg){
				this.oNodeImg.src = treeConfig.lMinusIcon;
				this.oNode.style.backgroundImage = 'url()';
			}
		}
	}
}

treenode.prototype.collapse = function(){
	if(this.opened){
		this.oNode.oNodeChilds.style.display = 'none';
		this.oNode.oNodeIcon.src = this.icon;
		this.opened = false;
		
		// set toggle icons
		if(this.getNextSibling()){
			this.oNodeImg.src = treeConfig.tPlusIcon;
		}else{
			this.oNodeImg.src = treeConfig.lPlusIcon;
		}
		this.oNode.style.backgroundImage = 'url()';
	}
}

treenode.prototype.expandAll = function(){
	var i;
	this.expand();
	
	for(i=0;i<this.oNode.oNodeChilds.childNodes.length;i++){
		this.oNode.oNodeChilds.childNodes[i].obj.expandAll();
	}
}

treenode.prototype.collapseAll = function(){
	var i;
	this.collapse();
	
	for(i=0;i<this.oNode.oNodeChilds.childNodes.length;i++){
		this.oNode.oNodeChilds.childNodes[i].obj.collapseAll();
	}
}

// expand first node
treeview.prototype.expand = function(){
	if(!this.loading){
		var treenodes = this.oNodeChilds.childNodes;
		if(treenodes.length > 0){
			var firstAvailableNode = treenodes[0];
			firstAvailableNode.obj.expand();
		}
	}else{
		var self = this;
		setTimeout(function(){self.expand()},10);
	}
}