

treenode.prototype.toggle = function(){
	if(this.opened){
		this.collapse();
	}else{
		this.expand();
	}
	this.eventManager.dispatch('toggle');
}

treenode.prototype.updateChildrenIcon = function (pNode) {
	if(pNode.oNodeCheckbox.state == 1) {
		var children = pNode.oNodeChilds.childNodes;
		for (var i = 0; i < children.length; i++) {
			var child = children[i];
			child.oNodeCheckbox.src = treeConfig.checkboxCheckedFullIcon;
			child.oNodeCheckbox.state = 1;
		}
	}
}

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.oNodeChilds.style.clip = 'rect(0px 50px 50px 0px)';
		//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()';
			}
			
		}
	}
	this.eventManager.dispatch('expand');
}

treenode.prototype.collapse = function(){
	if(this.opened){
		this.oNode.oNodeChilds.style.display = 'none';
		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()';
	}
	this.eventManager.dispatch('collapse');
}

treenode.prototype.expandAll = function(){
	this.expand();
	for(var i=0;i<this.oNode.oNodeChilds.childNodes.length;i++){
		this.oNode.oNodeChilds.childNodes[i].obj.expandAll();
	}
	this.eventManager.dispatch('expandAll');
}

treenode.prototype.collapseAll = function(){
	this.collapse();
	for(var i=0;i<this.oNode.oNodeChilds.childNodes.length;i++){
		this.oNode.oNodeChilds.childNodes[i].obj.collapseAll();
	}
	this.eventManager.dispatch('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;
		this.eventManager.addListener("onload",function(){self.expand()});
	}
	this.eventManager.dispatch('expand');
}









