// JavaScript Document

var currentFontSize = 3;
function zoomUtil(state, e){
		//alert('d')
	var idx;
	var arrFontSize = new Array();

	arrFontSize[0] = "65%";
	arrFontSize[1] = "75%";
	arrFontSize[2] = "85%";
	arrFontSize[3] = "100%";
	arrFontSize[4] = "110%";
	arrFontSize[5] = "120%";
	arrFontSize[6] = "130%";

	var e = e || window.event;
	if (e) {
		if (state == "in") {
			if (currentFontSize < 6 ) {
				idx = currentFontSize + 1;
				currentFontSize = idx;
			}else{
				idx = 6;
				currentFontSize = idx;
			}
		} else if (state == "default") {
			idx = 3;
			currentFontSize = idx;
		} else if (state == "out") {
			if ( currentFontSize >= 1) {
				idx = currentFontSize - 1;
				currentFontSize = idx;
			}else{
				idx = 0;
				currentFontSize = idx;
			}
		}
	}
	document.body.style.zoom = arrFontSize[idx];
	document.getElementById('wrap').style.zoom = arrFontSize[idx];
	document.getElementById('footerWrap').style.zoom = arrFontSize[idx];
	//document.getElementById('wrap').style.zoom = arrFontSize[idx];
	document.body.style.zoom = arrFontSize[idx];
	return false;
}


var pageNum, pageNum2, pageNum3;

function searchEl(){
	var menuID = KR('l'+menuId);
	var serchFun = function(obj){
		num = 0;
		while ( obj != null ){
			if( obj.nodeType == 1 )
				 num++
			obj = obj.previousSibling;
		};
		return num;
	}
	if(!menuID){
		subNum = parseInt(subNum);
	}else if(menuID.parent().id == "lnb"){
		pageNum = serchFun(menuID);
		subNum = parseInt(subNum);
	}else{
		pageNum2 = serchFun(menuID);
		menuID = menuID.parent(2)
		pageNum = serchFun(menuID);
		subNum = parseInt(subNum);
		//alert("pageNum = " + pageNum + ",pageNum2 = " + pageNum2)
	}
}

function gnbNavi(){
	var GNB = KR('gnb');
	if(!GNB) return false;
	var one = GNB.child();
	var acTime = 1000;

	GNB.onmouseover = function(){
		clearTimeout(GNB.act)
		this.state = true;
		this.onmouseout = function(){
			this.state = false;
			start();
		}
	}
	//  img rollover
	// gnb Function
	for(i=0;i<one.length; i++){
		var btn = one[i].first('a');
		btn.n = i;
		btn.onmouseover = btn.onfocus = function(){
			clear();
			var img_1 = this.first('img');
			img_1.src = img_1.src.replace("_off","_on");
			one[this.n].first('div').show();
		}

		if(!one[i].first('ul')) continue;
		var two = one[i].first('ul').child();
		for(j=0;j<two.length; j++){
			var btn2 = two[j].first('a');
			btn2.onmouseover = function(){
				clearTimeout(GNB.act)
				var img = this.first('img'),twoAct = false;
				if(this.className.indexOf('on')>=0) twoAct = true;
				else{
					if(img)
						img.src = img.src.replace('_off','_on');
					this.parent().addClass('on');
				}
				GNB.state = true;
				this.onmouseout = function(){
					if(!twoAct)
						if(img)
							img.src = img.src.replace('_on','_off');
					this.parent().removeClass('on')
					start();
					GNB.state = false;
				}
			}
			btn2.onfocus = function(){
				clearTimeout(GNB.act)
				var img = this.first('img'), twoAct = false;;
				//if(img.src.indexOf('_on')>0) twoAct = true;
				//img.src = img.src.replace('_off','_on');
				GNB.state = true;
				this.onblur = function(){
					if(!twoAct)
					//img.src = img.src.replace('_on','_off');
					start();
					GNB.state = false;
				}
			}
		}
	}
	var start = function(){
		GNB.act = setTimeout(function(){
			if(!GNB.state) active();
		},acTime)
	}
	var clear = function(){
		for (i=0; i<one.length ; i++ ){
			var img_1 = one[i].first('img');
			one[i].first('div').hide();
			if(img_1)
				img_1.src = img_1.src.replace("_on","_off")
		}
	}
	var active = function(){
		clear();
		if(subNum && one[subNum-1]){
			var img_1 = one[subNum-1].first('img');
			img_1.src = img_1.src.replace("_off","_on");
			one[subNum-1].first('div').show();
			if(!one[subNum-1]) return false;
			var two = one[subNum-1].first('ul').child();
			if(pageNum && two[pageNum-1]){
				two[pageNum-1].first('a').className = "on";
			//	var twoIMG = two[pageNum-1].first('img');
			//	twoIMG.src = twoIMG.src.replace("_off","_on")
			}
		}
	}
	active();
}

function lnb(){
	if(subNum != "other") {
		var lnb = KR('lnb'); // ul
		if(!lnb) return false;
		searchEl();
		var one = lnb.child();  // LI 'S
		for (i=0; i<one.length ; i++ )
		{
			one[i].first('a').count = i
			one[i].first('a').onclick = function (){
				clear();
				this.className = "lnb_dept on"
				if(one[this.count].first('ol')){
					one[this.count].first('ol').show();
					return false;
				}
			}
			if(one[i].first('ol')){
				var sA = one[i].first('ol').getElementsByTagName('a')
				for (j=0; j<sA.length ; j++ ){
					sA[j].onmouseover = function(){
						var Li = KR(this).parentName('li');
						if(Li.className == "on") return false;
						Li.className = "on";
						this.onmouseout = function(){
							Li.className = "";
						}
					}
				}
			}
		}

		var clear = function(){
			for (i=0; i<one.length ; i++ ){
				one[i].first('a').className = "lnb_dept";
				if(one[i].first('ol') != null ){
					one[i].first('ol').hide();
					var two =  one[i].first('ol').child();
					for (j=0; j<two.length ; j++ ){
						var link = two[j].first('a');
						//link.className = "";
					}
				}
			}
		}

		var active = function(){
			clear();
			if(pageNum && one[pageNum-1]){
				one[pageNum-1].first('a').className = "lnb_dept on"
				if(!one[pageNum-1].first('ol')) return false;
				one[pageNum-1].first('ol').show();
				one[pageNum-1].first('ol').className = "on";
				var two =  one[pageNum-1].first('ol').child()
				if(pageNum2 && two[pageNum2-1]){
					two[pageNum2-1].first('a').className = " on";
				}
			}
		}
		active();
	}
	gnbNavi();
}
function onLoadFunc(){
	lnb();
	if(KR('fileContainer')){
		KR('fileContainer').setOpacity(1)
		KR('fileContainer').style.cursor ="pointer"
	}
}

addLoadEvent(onLoadFunc)

function popMid(url,id,wid,hei,scroll) {
	var le = (screen.width-wid)/2;
	var to = (screen.height-hei)/2;
	var openwin = window.open(url,id,"'" + "toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=" + scroll + ",resizable=yes,width=" + wid + " ,height=" + hei + ",left=" + le + ",top=" + to + "'");
	return false;
}

function popPos(url,id,wid,hei,le,to,scroll) {
	var openwin = window.open(url,id,"'" + "toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=" + scroll + ",resizable=yes,width=" + wid + " ,height=" + hei + ",left=" + le + ",top=" + to + "'");
	return false;
}


function selectLink(ID){
	var Sel = KR(ID);
	var btn = KR('selectBtn');
	btn.onclick = function(){
		location.href = Sel.value;
		return false;
	}
}


function tabFuncClass(tabID,contID){
	var tabA = KR(tabID).child();
	for (i=0; i<tabA.length; i++)
	{
		tabA[i].count = i
		tabA[i].onclick  = function (){
			for (j=0; j<tabA.length; j++ )
			{
				KR(tabA[j]).first().className = "";
				KR(contID+(j+1)).style.display = 'none';
			}
			KR(tabA[this.count]).first().className = "on";
			KR(contID+(this.count+1)).style.display = '';
			return false;
		}
	}
}

function tabFuncImg(tabID,contID){
	var tabA = KR(tabID).child();
	for (i=0; i<tabA.length; i++)
	{
		tabA[i].count = i
		tabA[i].onclick  = function (){
			for (j=0; j<tabA.length; j++ )
			{
				var img = KR(tabA[j]).first();
				img.src = img.src.replace('_on','_off')
				KR(contID+(j+1)).style.display = 'none';
			}
			KR(tabA[this.count]).first().src = KR(tabA[this.count]).first().src.replace('_off','_on')
			KR(contID+(this.count+1)).style.display = '';
			return false;
		}
	}
}

function tabFuncA(box,className,nodeName){
	var Box = KR(box);
	var tabA = Box.childsFirst('a');
	var tabLIst = Box.getElementsByClassName(className,nodeName);
	for (i=0; i<tabLIst.length; i++)
	{
		var btn = tabA[i];
		btn.count = i;
		btn.onclick = btn.onfocus = function (){
			var tabIMG  = this.first('img');
			for (j=0; j<tabA.length; j++ )
			{
				try{ tabA[j].first('img').src = tabA[j].first('img').src.replace('_on.gif','_off.gif')
				}catch(e){ tabA[j].className = tabA[j].className.replace('on','off')}
				tabLIst[j].style.display = 'none'
			}
			try{ tabIMG.src = tabIMG.src.replace('_off.gif','_on.gif')
			}catch(e){ this.className = this.className.replace('off','on')}
			tabLIst[this.count].style.display = '';
			return false;
		}
		if(tabLIst[i])
		tabLIst[i].style.display = 'none';
	}
	if(tabLIst[0])
	tabLIst[0].style.display = '';
	var tabIMG = tabA[0].first('img')
	tabIMG.src = tabIMG.src.replace('_off.gif','_on.gif')
}

function tabFuncB(box,className,nodeName){

	var Box = KR(box);
	var tabA = Box.childsFirst('a');
	var tabLIst = Box.getElementsByClassName(className,nodeName);
	for (i=0; i<tabLIst.length; i++)
	{
		var btn = tabA[i];
		btn.count = i;
		btn.onclick = btn.onfocus = function (){
			var tabIMG  = this.first('img');

			for (j=0; j<tabA.length; j++ )
			{
				try{ tabA[j].first('img').src = tabA[j].first('img').src.replace('_on.gif','_off.gif')
				}catch(e){ tabA[j].className = tabA[j].className.replace('on','off')}
				tabLIst[j].style.display = 'none'
			}
			try{ tabIMG.src = tabIMG.src.replace('_off.gif','_on.gif')
			}catch(e){ this.className = this.className.replace('off','on')}
			tabLIst[this.count].style.display = '';
			return false;
		}
		try{ tabA[i].first('img').src = tabA[i].first('img').src.replace('_on.gif','_off.gif')
		}catch(e){ tabA[i].className = tabA[i].className.replace('on','off')}
		tabLIst[i].style.display = 'none';
	}
	try{
		if(box =="cateTab_1"){
			tabA[1].first('img').src = tabA[1].first('img').src.replace('_off.gif','_on.gif')
		}else if(box =="cateTab_2"){
			tabA[2].first('img').src = tabA[2].first('img').src.replace('_off.gif','_on.gif')
		}else if(box =="cateTab_3"){
			tabA[4].first('img').src = tabA[4].first('img').src.replace('_off.gif','_on.gif')
		}else{
			tabA[0].first('img').src = tabA[0].first('img').src.replace('_off.gif','_on.gif')
		}


	}catch(e){ tabA[1].className = tabA[0].className.replace('off','on')}

		if(box =="cateTab_1"){
			tabLIst[1].style.display = '';
		}else if(box =="cateTab_2"){
			tabLIst[2].style.display = '';
		}else if(box =="cateTab_3"){
			tabLIst[4].style.display = '';
		}else{
			tabLIst[0].style.display = '';
		}

}


// getCookie
function getCookie(name){
	var allCookies = decodeURIComponent(document.cookie);
	var strCnt = name.length;
	var pos = allCookies.indexOf(name+"=");
	if(pos == -1) return undefined;

	var start = pos + strCnt+1;
	var end = allCookies.indexOf(";", start);
	if(end == -1) end = allCookies.length;
	var value = allCookies.substring(start, end);
	return value = decodeURIComponent(value);
}

// setCookie
function setCookie(name,value,max_age,cPath,cDomain){
	var pathStr = (cPath) ? "; path=" + cPath : "";
	var domainStr = (cDomain) ? "; domain=" + cDomain : "";
	document.cookie = encodeURIComponent(name) + "=" + encodeURIComponent(value) +
							 pathStr + domainStr + "; max-age=" + (60*60*24*max_age);
}

function setCookieNew(name,value,max_age){
	var today = new Date();
	var makeDay = max_age;
	today.setDate( today.getDate() + parseInt( makeDay ) );
	document.cookie = name + "=" + value + "; path=/; expires=" + today.toGMTString() + ";"


}




function C5_detailView(obj){
	var link = KR('page5_3_Cont').getElementsByClassName('popupLink','a');
	for(i=0;i<link.length;i++)
		link[i].onclick = function(){
			var imgsrc = this.first('img').src.replace('.jpg','_big.jpg');
			popMid('page5_pop.jsp?decorator=popup&img='+imgsrc,'bigView','505','405','no');
			return false;
		}
}

/* faq */
function faqList(id){
	var faq = KR(id);
	var faqDD = faq.getElements('dd');
	var faqDt = faq.getElements('dt');
	var btns = faqDt.first('a')
	this.clickEvt= function(){
		for(i=0;i<btns.length;i++){
			btns[i].count  = i;
			btns[i].onclick = function(){
				if(faqDt[this.count].className == "on"){
					faqDt[this.count].className = "";
					faqDD[this.count].hide();
					return false;
				}else{
					for(j=0;j<btns.length;j++){
							faqDD[j].hide();
							faqDt[j].className = "";
					}
					faqDD[this.count].show();
					faqDt[this.count].className = "on";
					return false;
				}
			}
		}
	}
	faqDD.hide()
	this.clickEvt();
}


///ggnet/c5/develop/page10_3.jsp ** Layer open script **
function cityLayerOpen(){
	var areas = KR('map0011').getElementsByClassName('layerOpen','area');
	var layers = KR('cityLayerBox').child();
	for(i=0;i<areas.length;i++){
		areas[i].count = layers[i].count = i;
		areas[i].onmouseover=function(){
				var size = this.coords.split(',')
				layers[this.count].setPosition(size[0]-40,size[1]-400)
				layers[this.count].show();
				this.onmouseout = function(){
					layers[this.count].hide();
				}
		}
		layers[i].onmouseover=function(){
				layers[this.count].show();
				this.onmouseout = function(){
					layers[this.count].hide();
				}
		}
	}
}


// /ggnet/c5/economy/page1_1_3.jsp  table layer view
function brief(){
	var brief = KR('brief');
	var dls = brief.getElements('dl');
	var dds = dls.first('dd');
	dds.hide();
	for(i=0;i<dls.length;i++){
		var a = dls[i].first('a');
		a.count = i;
		a.onmouseover = a.onfocus = function(){
			dds[this.count].show();
			this.onmouseout = this.onblur = function(){
				dds[this.count].hide();
			}
		}
	}
}
function setDefineOn(){}
function setDefineOff(){}


function selectClick(){
	var selectBox = KR('selectClick');
	var option = selectBox.child();
	var arr = [];
	for(i=0;i<option.length;i++){
		arr[i] = option[i].value;
		KR(arr[i]).hide();
	}
		KR(selectBox.value).show();
}


/*
standby
readyState
selectionEnd
previewMode
activeMovie
*/

function tabMovie(tabID,contID){
	var tabA = KR(tabID).child();
	var cont = KR(contID).child();
	for (i=0; i<tabA.length; i++)
	{
		tabA[i].count = i
		tabA[i].onclick  = function (){
			for (j=0; j<tabA.length; j++ )
			{
				var img = KR(tabA[j]).first();
				//img.src = img.src.replace('_on','_off')
				KR(contID+(j+1)).style.display = 'none';
			}
			//KR(tabA[this.count]).first().src = KR(tabA[this.count]).first().src.replace('_off','_on')
			KR(contID+(this.count+1)).style.display = '';
			var obj  = KR(contID).getElements('object')

			for(i=0;i<obj.length; i++){
				obj[i].stop()
			}
			//return false;
		}
	}
	cont.hide();
	cont[0].show();
}


/* quick */


var start_pos = 140;
function quick_onLoad(){
	if(!document.getElementById("quickMenu")) return false;
	document.getElementById("quickMenu").style.top = start_pos + "px";
	document.getElementById("quickMenu").style.display = "";
	CheckUIElements();
	return false;
}
function CheckUIElements(){
	var yMenuFrom, yMenuTo, timeoutNextCheck, speed;
	yMenuFrom = parseInt(document.getElementById("quickMenu").style.top, 10);
	yMenuTo = start_pos + parseInt(document.documentElement.scrollTop, 10);
	timeoutNextCheck = 400;
	if(yMenuFrom == yMenuTo){
		setTimeout ("CheckUIElements()", timeoutNextCheck);
		return false;
	}else{
		speed = Math.ceil((yMenuTo - yMenuFrom) * 0.1);
		document.getElementById("quickMenu").style.top = (parseInt(document.getElementById("quickMenu").style.top, 10) + speed) + "px";
		timeoutNextCheck = 25;
		setTimeout ("CheckUIElements()", timeoutNextCheck);
		return false;
	}
}
addLoadEvent(quick_onLoad);

function bannerSlide(){
	var btntop = KR('btnLeft');
	var btnRight = KR('btnRight');
	var bannerBody = KR('bannerBody');
	if(!bannerBody) return false;
	var lis = bannerBody.child();
	var func = bannerBody;
		func.stop = true;
	var mvFlag = 1;

	btntop.onclick = function(){
		mvFlag = 1;
		if(func.status) return false;
		clearInterval(func.rolling);
		lis.each(function(o,i){
			jq(o).stop()
			func.action(o,function(){
			})
		})
		func.stop = true;
		return false;
	}
	btnRight.onclick = function(){
		mvFlag = -1;
		if(func.status) return false;
		clearInterval(func.rolling);
		lis.each(function(o,i){
			jq(o).stop()
			func.action(o,function(){
			})
		})
		func.stop = true;
		return false;
	}
	func.init = function(){
		this.hei = lis[0].offsetWidth ;
		this.allHei = this.hei * (lis.length-1) ;
		lis.each(function(o,i){
			 o.style.position = "absolute";
			 o.style.left = func.hei * (i);
		});
	}
	func.action = function (o,fx){
		func.status = true;
		if((mvFlag == 1) && (parseInt(o.style.left) <= -func.hei ) ){
			jq(o).css({
				left:func.allHei
			});
		}else if((mvFlag == -1) && (parseInt(o.style.left) >= func.allHei ) ){
			jq(o).css({
				left:-func.hei
			});
		}

		var left = func.getStyle(o, "left");
		o.xTo = left - (func.hei*mvFlag);
		jq(o).animate({
			left:o.xTo
		},function(){
			func.status = false;
			if(fx){
				eval(fx)()
			}
		});
	}
	func.getStyle = function(ele, what){
		var value = "";
		if(ele.currentStyle){
			value = ele.currentStyle[what];
		}else if(window.getComputedStyle){
			value = window.getComputedStyle(ele,null)[what];
		}
		return parseInt(value, 10);
	}
	func.init();
}

addLoadEvent(bannerSlide);


function faq(){
	var box = jq('#faqCnt');
	if(box.length == 0) return false;
	var child =jq('#faqCnt > div');
	var btn = jq('#faqCnt > h4 a');

	btn.each(function(i){this.n = i}).click(function(){
			child.hide();
			child.eq(this.n).show();
	})
			child.hide();
}
//addLoadEvent(faq);

