﻿
function TreeNode(args){
	this._container = document.createElement("div");
	this._item		= document.createElement("div");
	this._link		= document.createElement("a");
	this._id		= args.id;
	this._text		= args.text || "";
	this._remark	= args.remark || "";
	this._parentlink= args.parentlink || "";
	this._href		= args.href || "javascript:void(0)";
	this._parent	= args.parent;
	this._level		= args.level || 2;
	this._type		= args.type || "branch";
	this._target 	= args.target || "_self";
	//this._indent	= args.indent!=null?args.indent:10;
	
	this._link.id	= this._id;
	this._container.id 	= this._id + "_container";
	//this._container.style.marginLeft = this._indent + "px";
	if(this._type != "leaf"){
		this._subarea	= document.createElement("div");
		this._subarea.id	= this._id + "_subarea";
		if(this._level>1)
			this._subarea.style.display = "none";
	}
	this._link.href   = args.href?(this._href + (this._href.indexOf("?")>0?"&":"?")+"menuname=" + this._parentlink + "_" + this._id):this._href;
	//this._link.href   = args.href?(this._href + (this._href.indexOf("?")>0?"&":"?")+"menuname=" + this._parentlink + "_" + this._id):this._href;
	this._item.style.cssText = "";
	this._link.style.cssText = "";	
	this._link.setAttribute("target",this._target);
	
	
	this._item.setAttribute("state","selected");
	this._item.setAttribute("nclass",args.item_normal);
	this._item.setAttribute("sclass",args.item_select);
	this._item.className = args.item_normal;
	this._itemclass	= {item_normal:args.item_normal,item_select:args.item_select};
	
	this._link.onclick	= function(event){			
			this._itemHandler(event);
			this._item.setAttribute("state","selected");
			if(this._type != "leaf"){
				this._subarea.style.display = this._subarea.style.display==""?"none":"";
				
			}
			this._item.className = this._item.className==this._itemclass.item_normal?this._itemclass.item_select:this._itemclass.item_normal;
			this._itemHandler2();
		}.bind(this);
	this._itemHandler = new Function();
	this._itemHandler2 = new Function();
 	this._link.setAttribute("parentlink",this._parentlink);
	this._link.setAttribute("level",this._level);
	this._link.setAttribute("mtype",this._type);
	this._link.setAttribute("title",this._remark);
	
	
	this._link.insertBefore(document.createTextNode(this._text),null);

	this._item.insertBefore(this._link,null);	

	this._container.insertBefore(this._item,null);
	if(this._type != "leaf"){
		this._container.insertBefore(this._subarea,null);
	}
	this._parent.insertBefore(this._container,null);
	/*
	if(this._level>3){
		this._item.style.marginLeft = _isIE?"5px":"15px";
		this._item.style.width = "150px";
	}
	*/
}
