//Javascript Document
//<![CDATA[
$=function(id){
	return document.getElementById(id);
}
function show(obj){
	objDis = $(obj).style.display;
	sHeight = $(obj).scrollHeight;
	var altText="";
	var picName="";
	if (objDis=="" || objDis=="block"){
		$(obj).style.display = "none";
		altText="展开";
		picName="max";
		resizeMenuTop($(obj).parentNode,sHeight,1)
	}else{
		$(obj).style.display = "block";
		sHeight = $(obj).scrollHeight;
		altText="收缩";
		picName="min";
		resizeMenuTop($(obj).parentNode,sHeight,2)
	}
	$(obj).parentNode.getElementsByTagName("div")[0].getElementsByTagName("span")[1].innerHTML="<img src=\"images/left_icon_" + picName +".gif\" width=\"12\" height=\"12\" alt=\""+ altText +"\" onclick=\"show('"+ obj +"')\" />"

}
//Resize Div Top
function resizeMenuTop(parentObj,sHeight,stat){
	
	for(i=0;i<menuBox.childs.length;i++){if(menuBox.childs[i].obj == parentObj) posNum = i;	}
	if(stat==1){
		$("left_menu_box").style.height=parseInt($("left_menu_box").style.height)-sHeight+"px";
		for(i=0;i<menuBox.childs.length;i++){
			if(i>posNum) 
				menuBox.childs[i].obj.style.top = parseInt(menuBox.childs[i].obj.style.top)-sHeight+"px";
		}
	}
	else{
		$("left_menu_box").style.height=parseInt($("left_menu_box").style.height)+sHeight+"px";
		for(i=0;i<menuBox.childs.length;i++){if(menuBox.childs[i].obj == parentObj)	posNum = i;}
		for(i=0;i<menuBox.childs.length;i++){if(i>posNum) menuBox.childs[i].obj.style.top = parseInt(menuBox.childs[i].obj.style.top)+sHeight+"px";
		}
	}
}

//Create MenuObj
function MenuObj(obj,indexNum){this.obj = obj;this.indexNum = indexNum;}
function MenuBox(obj){this.obj;this.childs = new Array();}
MenuBox.prototype.add = function(obj,indexNum){this.childs[this.childs.length] = new MenuObj(obj,indexNum)}

//Init Menu
var speed=8;
function initMenu(){
	initHeight =5;
	$("left_menu_box").style.height="910px";
	MenuIndexNum = readCookie("Hc360Menu");
	//alert(MenuIndexNum)
	if(MenuIndexNum!=null){
		MenuIndexStr = MenuIndexNum.split("$");
		var MenuStr="";
		for(i=0;i<MenuIndexStr.length;i++){
			if(MenuIndexStr[i]==1) MenuStr +=  "<div id=menu_list_1>" + $("menu_list_1").innerHTML + "</div>";
			if(MenuIndexStr[i]==2) MenuStr +=  "<div id=menu_list_2>" + $("menu_list_2").innerHTML + "</div>";
			if(MenuIndexStr[i]==3) MenuStr +=  "<div id=menu_list_3>" + $("menu_list_3").innerHTML + "</div>";
			if(MenuIndexStr[i]==4) MenuStr +=  "<div id=menu_list_4>" + $("menu_list_4").innerHTML + "</div>";
                        if(MenuIndexStr[i]==5) MenuStr +=  "<div id=menu_list_5>" + $("menu_list_5").innerHTML + "</div>";
                        if(MenuIndexStr[i]==6) MenuStr +=  "<div id=menu_list_6>" + $("menu_list_6").innerHTML + "</div>";
		}
	
		for(i=0;i<MenuIndexStr.length;i++){
			if(MenuIndexStr[i]==1) menuBox.add($("menu_list_1"),1);
			if(MenuIndexStr[i]==2) menuBox.add($("menu_list_2"),2);
			if(MenuIndexStr[i]==3) menuBox.add($("menu_list_3"),3);
			if(MenuIndexStr[i]==4) menuBox.add($("menu_list_4"),4);
                        if(MenuIndexStr[i]==5) menuBox.add($("menu_list_5"),5);
                        if(MenuIndexStr[i]==6) menuBox.add($("menu_list_6"),6);
		}
		for(i=0;i<menuBox.childs.length;i++){	
			with(menuBox.childs[i].obj.style){position = "absolute";top =initHeight + "px";}		
			initHeight = initHeight + menuBox.childs[i].obj.scrollHeight;
		}
		
	}else{
		for(p=1;p<=6;p++){var menu = eval("$('menu_list_" + p + "')");menuBox.add(menu,p);}
		for(i=0;i<menuBox.childs.length;i++){
			with(menuBox.childs[i].obj.style){position = "absolute";top =initHeight + "px";}		
			initHeight = initHeight + menuBox.childs[i].obj.scrollHeight ;
		}
	}
	
		menuBox.childs[0].obj.getElementsByTagName("div")[0].getElementsByTagName("span")[0].innerHTML="";
	
	
}

//get parent
//move menu up
function moveUp(obj){
	for (i=0;i<menuBox.childs.length;i++ ){
		if(menuBox.childs[i].obj == $(obj)){
			if (i>0){
				posNum = i;
				exchange(getMenuDiv(menuBox.childs[i].indexNum));
			}
		}
	}
}
//get current div
function getMenuDiv(indexNum){
	var MenuArr = new Array();
	for(i=0;i<menuBox.childs.length;i++){
		if(menuBox.childs[i].indexNum == indexNum){
			var PreDiv = getPreMenuDiv(indexNum);
			var PreindexNum = PreDiv.indexNum;
			MenuArr[0] = PreDiv.obj;//pre div
			MenuArr[1] = menuBox.childs[i].obj;//current div
			PreDiv.indexNum = indexNum;
			PreDiv.obj = MenuArr[1];
			menuBox.childs[i].obj = MenuArr[0];
			menuBox.childs[i].indexNum = PreindexNum;
			MenuArr[0].style.zIndex = "0";
			MenuArr[1].style.zIndex = "360";
			break;
		}
	}
	setCookie()
	return MenuArr;
}
//Get Previous Div
function getPreMenuDiv(indexNum){for(i=0;i<menuBox.childs.length;i++){if(menuBox.childs[i].indexNum==indexNum){return menuBox.childs[i-1];}}}
//Exchange
function exchange(MenuArr){moveObj(MenuArr[0],MenuArr[1])}
//Move Obj
var oStart;
var oEnd;
var oStartY;
var oEndY;
function moveObj(oStart1,oEnd1){
	oStart = oStart1;
	oEnd = oEnd1;
	oStartY = parseInt(oEnd.style.top);
	oEndY = parseInt(oStart.style.top);
	oStart.getElementsByTagName("div")[0].style.filter="alpha(opacity=10)";
	//change move menu style
	moveObj1();moveObj2();
}
function moveObj1(){
	yStart = parseInt(oStart.style.top);
	yEnd = oStartY+(oEnd.scrollHeight-oStart.scrollHeight);
	if(yStart<yEnd){
		moveY(oStart,1,speed,yEnd);
		setTimeout("moveObj1()",1);
	}
	if(yStart>yEnd){
		moveY(oStart,2,speed,yEnd);
		setTimeout("moveObj1()",1);
	}
	if(yStart==yEnd){
		//resume move menu style
		if(posNum==1){
		oEnd.getElementsByTagName("div")[0].getElementsByTagName("span")[0].innerHTML="";
		oStart.getElementsByTagName("div")[0].getElementsByTagName("span")[0].innerHTML="<img src=\"images/left_icon_up.gif\" width=\"12\" height=\"12\" alt=\"向上移动\" onclick=\"moveUp('"+oStart.id+"')\" />";
		}
		oStart.getElementsByTagName("div")[0].style.filter="alpha(opacity=100)";
	}
}
function moveObj2(){
	yStart = parseInt(oEnd.style.top);
	
	yEnd = parseInt(oEndY);
	if(yStart<yEnd){
		moveY(oEnd,1,speed,yEnd);
		setTimeout("moveObj2()",1);
	}
	if(yStart>yEnd){
		moveY(oEnd,2,speed,yEnd);
		setTimeout("moveObj2()",1);
	}
	if(yStart==yEnd){
		
	}
}
function moveY(obj,ySpeenType,speed,yEnd){
	if(ySpeenType==1){
		if((parseInt(obj.style.top)+speed)>yEnd){
			obj.style.top = yEnd+"px";
		}else{
			obj.style.top = parseInt(obj.style.top)+speed+"px";
		}
	}
	if(ySpeenType==2){
		if((parseInt(obj.style.top)-speed)<yEnd){
			obj.style.top = yEnd+"px";
		}else{
			obj.style.top = parseInt(obj.style.top)-speed+"px";
		}
	}
}

//Cookie For Menu Obj
//write cookie
function setCookie(){
	cookieStr = "Hc360Menu=";
	for(i=0;i<menuBox.childs.length;i++){
		if(i==0) cookieStr+=menuBox.childs[i].indexNum;	else cookieStr+="$" + menuBox.childs[i].indexNum;
	}
	var exp=new Date((new Date()).getTime() + 30 * 24 * 60 * 60 * 1000);//expires 30 day
	cookieStr = cookieStr + "; expires=" + exp.toGMTString();
	document.cookie = cookieStr;
}
//read cookie
function readCookie(name){
	var cookieArr = document.cookie.split("; ");
	if(document.cookie.indexOf(name)==-1) return null;
		for(i=0;i<cookieArr.length;i++){
			if(cookieArr[i].indexOf(name)!=-1){
				cookieStr = document.cookie.match(new RegExp("(^| )" + name + "=([^;]*)(;|$)"));
				//cookieStr = cookieArr[i].substring(cookieArr[i].indexOf("=")+1)	
				break;
			}
		}	  
	return cookieStr[2];
}
var menuBox = new MenuBox();
//]]>