// JavaScript Document
/*
===gotCode 2004-11-17===
===for web dropMenu_cross===
*/
if( typeof(has_global_js) == "undefined" ){
	UI_effect = false
}
//===建立菜单===
function build_lv2Menu( which ,array ,filter ){

	var prtObj 	= which														
		
	while( prtObj.parentNode.nodeName != "BODY" ){							
		prtObj = prtObj.parentNode
	}
	if( prtObj 	== which ){													//判断是否已经是最高级别
		iTop	= which.offsetTop + which.offsetHeight + 0	
		iLeft	= which.offsetLeft + 0		
	}else{
		iTop	= which.offsetTop  + which.offsetHeight + prtObj.offsetTop + 0
		iLeft	= which.offsetLeft + prtObj.offsetLeft + 0
	}
	if( typeof(has_global_js) == "undefined" ){							
		eval('function toCntColor( str ,type ,addmore ){if(type==1){return "#ffffff"}else{return "#333366"}}')		
	}
	
	var width 			= which.offsetWidth		//默认宽度
	var buttonColor 	= "#ccccff"				//默认颜色	
	var background		= null					//默认主层背景		
	var color			= null					//默认字体颜色	
	var showstyle		= null					//默认显示风格		
	
	if( filter != null ){	
		filter	= filter + ","
		filters = filter.split(",")	
		if( filters.length > 1 ){
			for( var i = 0 ; i < filters.length - 1; i ++ ){	
				newVar = filters[i].split(":")
				if( newVar.length > 1 ){
					eval(newVar[0] + '="' + newVar[1] + '"')
				}
			}
		}
	}
	if( background == null ){				//默认主层背景	
		background	= toCntColor(buttonColor)
		background	= toCntColor(background,1)
	}
	if( color == null ){						//默认字体颜色		
		color	= toCntColor(buttonColor,2,3)	
	}
	if( showstyle == null ){					//默认显示风格	
		showstyle	= "Left"	
	}else if( showstyle == 1 ){
		showstyle	= "Rigth"
	}else{
		showstyle	= "Bottom"
	}
	
		which.style.cursor 		= "default"			
		which.style.font 		= "9pt Arial"				
		which.style.overbgcolor = background									
		which.style.overcolor 	= toCntColor(background,2,3)	
		which.onmouseover		= function(){showMenu(which);}
		
	var height	= array.length * 25 + array.length + 7		
	
	var oHtml	= '<div id="' + which.id + '_menuLV2"'+	
					' style="'+
						'position:absolute;'	+
						'z-index:10;'			+
						'top:' 		+ iTop 		+ ';'		+						//坐标Y
						'left:'		+ iLeft		+ ';'		+						//坐标X
						'width:'	+ width		+ ';'		+
						'height:'	+ height	+ ';'		+
						'padding:2px 1px 3px 1px;'	+
						'white-space:nowrap;'		+
						'background:'+ background+ ';'	+
						'color:'	+ color		+ ';'		+
						'border:1px solid #aaaacc;'	+
						'display:none;'				+
						'count:0;'					+
						'ctrlTimeout:null;'			+
						'status:closed;'			+
					'" >\n'
						
	for( var i = 0 ; i < array.length ; i ++ ){							//建立菜单
		if( i % 2 == 0 ){
			iLeft = -10
		}else{
			iLeft = 10
		}
		
		bg_over = toCntColor(buttonColor,1,-1)
		fg_over = toCntColor(buttonColor,2)
		boder_hilite = toCntColor(bg_over,1)
		boder_prlite = toCntColor(fg_over,2)
		borderColor  = boder_prlite + " " + 
					   boder_hilite + " " + 
					   boder_hilite + " " + 
					   boder_prlite 
		
		if( array[i]["id"] != null ){
			menuID = array[i]["id"]
		}else{
			menuID =  which.id + '_menuLV2_' + i 
		}
		oHtml +='<div id="' + menuID + '"'+	
					' style="'+
						'height:25px;'				+
						'width:100%;'				+
						'padding:6px 0px 0px 8px;'	+
						'font:10pt;'					+
						'border:0px solid '			+
						'white-space:nowrap;'		+
						'background:'+	buttonColor	+	';'		+
						'cursor:hand;'				+
						'display:none;'				+
						'filter:alpha(opacity=0);'	+
						'margin-top:1px;'			+
						'alpha:0;'					+
						'iLeft:'	+	iLeft		+	';'		+
						'iMark:'	+	iLeft		+	';'		+
						'showstyle:'+ showstyle		+ 	';'		+
					'"'+
					' onmousedown="'+
						'window.location.href=\'' 	+ array[i]["url"].replace(/\'|\"/g,"\\'") 	+ '\';'	+	//行为
					'"'+	
					' onmouseover="'+
						'this.style.background=\''	+ bg_over	+ '\';'	+
						'this.style.color=\''		+ fg_over	+ '\';'	+
						'this.style.borderColor=\''	+borderColor+ '\';'	+
						'this.style.borderWidth=\'1px 1px 1px 1px\';'	+
						'this.style.borderStyle=\'solid\';'+
					'"'+
					' onmouseout="'+
						'this.style.background=\''	+ buttonColor+ '\';'	+
						'this.style.color=\''		+ color		+ '\';'	+
						'this.style.border=\'0px solid white\';'		+
						';'+
					'"'+
				'>\n' +
					array[i]["name"] +										//菜单名
				'</div>\n'
	}
	
	oHtml += "</div>"
	document.write(oHtml)
}


//===显示菜单===
var lastMenu		= null									//上一次菜单的对象

function show_lv2Menu( which ){
	clearTimeout(ctrlTs)	
	
	var mainObj = eval(which.id + '_menuLV2')
	var divObj  = mainObj.all.tags('div')
	var _count  = mainObj.style.count	
	
	if( mainObj.style.status == "opened" ){					//判断是否处于打开状态					
		return		
	}
		
	if( mainObj.style.ctrlTimeout == "stop" ){			
		hideMenu(mainObj)					
		clearTimeout(ctrlTs)	
		return				
	}	
  
	mainObj.style.zIndex = 11									//使要显示的层置顶
	
	if( lastMenu != null && lastMenu != mainObj){				//判断上一次菜单是否存并且此菜单不是自己
		lastMenu.style.zIndex = 10	
	}
	if( lastMenu != null && lastMenu != mainObj){				
		lastMenu.style.ctrlTimeout = "stop"
		if( lastMenu.style.status == "opened" ){				
			hideMenu(lastMenu)	
		}			
		lastMenu.style.status = "closed"						//使上一次的菜单状态为关闭	
	}
	if( lastMenu != mainObj ){
		mainObj.style.display 	= ""							//使菜单可见
		if( UI_effect ){
			which.style.background 	= which.style.overbgcolor
			which.style.color 		= toCntColor(which.style.overcolor,1,6)	
			which.style.border 		= "1px inset buttonface"
			which.style.filter		= "progid:DXImageTransform.Microsoft.Gradient(gradientType=0,startColorStr="+toCntColor(which.style.overbgcolor,2)+",endColorStr="+toCntColor(which.style.overbgcolor,1,-6)+")"
			menuStrap.style.backgroundColor	= toCntColor(which.style.overcolor,2,8)
		}
		if( typeof(has_global_js)!= "undefined" ){
			giveItShaow( mainObj , shadowDiv ,"show" )
			giveItEffect(mainObj,"show","self")
		}
		
		lastMenu = mainObj	
			
	}	
  		
		uID	= divObj[_count]		
		uID.style.display 		= ""
										
	if( mainObj.style.status == "closed" ){	
		show_lv2Menu_filter( uID )						
	}
		
		_count ++			
		mainObj.style.count = _count	
		
	if( _count == divObj.length ){	
		mainObj.style.count = 0		
		mainObj.style.status = "opened"
		clearTimeout(ctrlTs)	
		return				
	}		
	
	var ctrlTs	= setTimeout("show_lv2Menu("+(which.id)+")",25)		
	
}

//===显示菜单效果===
function show_lv2Menu_filter( which ){
	clearTimeout(ctrlT)										
	if( which.style.ctrlTimeout == "stop" ){				
		clearTimeout(ctrlT)		
		return					
	}

	which.style.alpha =(eval(which.style.alpha) + 5)
	
	var mark_iLeft = which.style.iMark	
	
	if( eval(which.style.iMark) < 0 ){
		which.style.iLeft =(eval(which.style.iLeft) + 0.5)	
		cType = which.style.showstyle
	}else{
		which.style.iLeft =(eval(which.style.iLeft) - 0.5)
		cType = "Left"
	}
	
	which.style.filter = "alpha(opacity="+which.style.alpha+")"
	eval('which.style.margin'+cType+' = which.style.iLeft')
	
	if( eval(which.style.alpha) == 100 ){
		which.style.alpha  = 0	
		which.style.iLeft  = mark_iLeft
		which.style.filter = "none"	
		clearTimeout(ctrlT)							
		return			
	}
	
	var ctrlT	= setTimeout("show_lv2Menu_filter("+(which.uniqueID)+")",10)
}

//===隐藏菜单===
function hide_lv2Menu( which ){
	if( which != null){
		var mainObj= which										//要隐藏的对象
		var divObj = mainObj.all.tags('div')
	
		for( var i = 0 ; i < divObj.length ; i ++ ){	
			uID	= divObj[i]
			uID.style.display = "none"
		}
		
		mainObj.style.status 		= "closed"
		mainObj.style.ctrlTimeout 	= "null"
		mainObj.style.display 		= "none"
		mainObj.style.count 		= 0	
		
		eval(which.id.split("_")[0]).style.background 	= "#efefef"	
		eval(which.id.split("_")[0]).style.color 		= "black"	
		eval(which.id.split("_")[0]).style.border 		= "1px solid #efefef"	
		eval(which.id.split("_")[0]).style.filter		= "none"
	}
}


function showMenu(which){
	show_lv2Menu(which)
 
}	
function hideMenu(which){
	hide_lv2Menu( which )
}

function bodyOnload(){	
	hideMenu(lastMenu);
	lastMenu = null
	if( typeof(has_global_js)!= "undefined" ){	
		giveItShaow(lastMenu,shadowDiv,'hide');
		giveItEffect('','hide')	
	}	
}
window.onload = function(){
	document.body.onclick = bodyOnload	
}	