// JavaScript Document

/*	글자확대축소 */
var currentFontSize = 3;
function zoomUtil(state, e){
	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 = 1;
			currentFontSize = idx;
		} else if (state == "out") {
			if ( currentFontSize >= 1) {
				idx = currentFontSize - 1;
				currentFontSize = idx;
			}else{
				idx = 0;
				currentFontSize = idx;
			}
		}
	}
	document.getElementById('wrap').style.zoom = arrFontSize[idx];
	document.body.style.zoom = arrFontSize[idx];
	return false;
}


function gnb(){
	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');
		var two = one[i].first('ul').child();
		btn.onmouseover = btn.onfocus = function(){
			clear();
			var img_1 = this.first('img');
			img_1.src = img_1.src.replace("_off","_on");
			this.parentName('li').addClass('on');
		}
		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(img.src.indexOf('_on')>0) twoAct = true;
				img.src = img.src.replace('_off','_on');
				GNB.state = true;
				this.onmouseout = function(){
					if(!twoAct)
					img.src = img.src.replace('_on','_off');
					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++ ){
			one[i].removeClass(' on');
			var img_1 = one[i].first('img');
			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].addClass('on');
			if(!one[subNum-1]) return false;
			var two = one[subNum-1].first('ul').child()
			if(pageNum && two[pageNum-1]){
				two[pageNum-1].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;
		if(!lnb.first('img')) return false;
		try{
			(function(){
				var ID = document.getElementById(menuId);
				var num = ID.getAttribute('menuNum').split('_');
				pageNum = num[0]
				pageNum2 = num[1];
			})();
		}catch(e){}
		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();
				var img_1 = one[this.count].first('img');
				if(img_1)
					img_1.src = img_1.src.replace("_off","_on")
				if(one[this.count].first('ul')){
					one[this.count].first('ul').show();
					return false;
				}
			}
			if(one[i].first('ul')){
				var sA = one[i].first('ul').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++ ){
					if(one[i].first('ul') != null ) one[i].first('ul').hide();
					var img_1 = one[i].first('img');
					if(img_1)
						img_1.src = img_1.src.replace("_on","_off")
			}
		}
		var active = function(){
			clear();
			if(pageNum && one[pageNum-1]){
				var img_1 = one[pageNum-1].first('img');
				img_1.src = img_1.src.replace("_off","_on")

				if(!one[pageNum-1].first('ul')) return false;
				one[pageNum-1].first('ul').show();
				var two =  one[pageNum-1].first('ul').child()
				if(pageNum2 && two[pageNum2-1]){
					two[pageNum2-1].className = "on";
				}
			}
		}
		active();
	}
	gnb();
}
function onLoadFunc(){
	lnb();
}

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<tabA.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++ )
			{
				tabA[j].first('img').src = tabA[j].first('img').src.replace('_on.gif','_off.gif')
				tabLIst[j].style.display = 'none'
			}
			tabIMG.src = tabIMG.src.replace('_off.gif','_on.gif')
			tabLIst[this.count].style.display = '';
			return false;
		}
		tabLIst[i].style.display = 'none';
	}
	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 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.getElments('dd');
	var faqDt = faq.getElments('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.getElments('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).getElments('object')
				
			for(i=0;i<obj.length; i++){
				obj[i].stop()
			}
			return false;
		}
	}
	cont.hide();
	cont[0].show();
}


/* quick */


var start_pos = 330;
function quick_onLoad(){
	if(!document.getElementById("quick_btn")) return false;
	document.getElementById("quick_btn").style.top = start_pos + "px";
	document.getElementById("quick_btn").style.display = "";
	CheckUIElements();
	return false;
}
function CheckUIElements(){
	var yMenuFrom, yMenuTo, timeoutNextCheck, speed;
	yMenuFrom = parseInt(document.getElementById("quick_btn").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("quick_btn").style.top = (parseInt(document.getElementById("quick_btn").style.top, 10) + speed) + "px";
		timeoutNextCheck = 25;
		setTimeout ("CheckUIElements()", timeoutNextCheck);
		return false;
	}
}
addLoadEvent(quick_onLoad);




