																										// JavaScript Document
(function (){
	var bar = {
		toolsBar:function(node,barData,clickFun){
			var barData = barData || {};
			bar.clickFun = clickFun || null;
			for(var i in barData){
				bar.createRoot(node,barData[i]);
			}
		},
		createRoot:function (node,barData){//创建跟项目
			node.dom.innerHTML = '<input type="hidden" name="'+barData.idName+'" id="'+barData.idName+'" value="" />';
			var li = document.createElement('LI');
			var rootSpan = document.createElement('SPAN');
			li.innerHTML = barData.text;
			li.id = barData.url;
			node.dom.appendChild(li);	
			var child = typeof barData.child; 
			clw(li).setStyle({"position":"relative", "margin-top":"0px"});
			if(child.toUpperCase() == 'OBJECT'){//如果有子项
				bar.createSubItem(li,barData,true);
			}else{
				clw(li).addClassName('bar-root-li-node');
				clw(li).addEvent('click',function(e){bar.clickItem(barData.text,barData.idName,barData.valueId,barData.url,barData.leftMenuUrl,this,true,barData.handl,barData.searchType,e)});//给工具条添加点击事件
			}	
		},																																																	
		createSubItem : function(node,thebarData,isRoot,num){
			var ul = document.createElement('UL');
			var j = 0;
			var t = 0;
			var barData = thebarData.child;
			for(var i in barData){
				if(t==0){
					t++;
					if(isRoot){
						clw(node).addClassName('bar-root-li-has-sub');
						var top = parseInt(clw(node).getStyle('height').value()) || node.offsetHeight || 20;//取标签高度
						var left = 0;
					}else{
						clw(node).addClassName('bar-item-li-has-sub');
						var top = parseInt(clw(node).getStyle('height').value()) || node.offsetHeight || 20;//取标签高度
						top = top * num;
						var left = parseInt(clw(node).getStyle('width').value()) || node.offsetWidth || 80; //取标签宽度
					}
					node.appendChild(ul);
					top = top || 0;
					left = left || 0;
					clw(ul).addClassName('bar-item-ul').setStyle({"position":"absolute","margin":"0 0 0 0",'left':left+'px','top':top+'px'});
					clw(node).addEvent('mousemove',bar.showSub);//给工具条添加鼠标经过事件
					clw(node).addEvent('mouseout',bar.hiddenSub);
				}
				bar.createItem(ul,barData[i],j);
				j++;
			}
			/*if(j == 0){
				var itemStyle = isRoot ? 'bar-root-li-node' : 'bar-item-li';
				clw(node).addClassName(itemStyle);
				clw(node).addEvent('click',function(){bar.clickItem(thebarData.text,thebarData.idName,thebarData.valueId,thebarData.url,thebarData.leftMenuUrl,this,isRoot,thebarData.handl,thebarData.searchType)});//给工具条添加点击事件
			}*/
			
		},
		createItem:function(node,barData,num){//创建下一级列表
			var li = document.createElement('LI');
			li.innerHTML = '&nbsp;&nbsp;'+barData.text;
			node.appendChild(li);
			var childType = '';
			var childType = typeof barData.child; 
			clw(li).addClassName('bar-item-li');
		
			clw(li).addEvent('click',function(e){bar.clickItem(barData.text,barData.idName,barData.valueId,barData.url,barData.leftMenuUrl,this,false,barData.handl,barData.searchType,e);});//给工具条添加点击事件
			if(childType.toUpperCase() == 'OBJECT'){//如果有子项
				bar.createSubItem(li,barData,false,num);
			}
		},
		showSub:function(event){
			clw(this).getChild('first').dom.className = '';
			clw(this).getChild('first').addClassName('bar-item-ul-show');
		},
		hiddenSub:function(event){
			clw(this).getChild('first').dom.className = '';
			clw(this).getChild('first').addClassName('bar-item-ul');
		},
		clickItem:function(text,valueid,values,url,leftMenuUrl,obj,isRoot,handl,searchType,e){
			clw().stopPropagation(e);
			if(handl){clw(valueid).dom.value=values;
				//clw(url).dom.firstChild.nodeValue = text;
				handl.call(this,searchType,text,url);
			}else{
				clw(valueid).dom.value=values;
				clw(url).dom.firstChild.nodeValue = text.substr(0,6);
			}
			
		}
	}
	var funValue = ['toolsBar'];
	clw().batchAddFunction(bar,funValue);
})()
