// JavaScript Document

// window.onload Event
function addLoadEvent(func){
	var oldonload = window.onload;
	
	if(typeof window.onload != 'function'){
		window.onload = func;
		
	}else{
		window.onload = function(){
			oldonload();
			func();
		}
	}
}

//var source_li = document.getElementById("promotion_rollingImg").getElementsByTagName("iframe")[0].contentWindow.document.getElementsByTagName('li');
var promv_count = 701;
var zoom_check = false;
var func_promv_rolling = null;
var func_promv_imgZoom = null;
var mv_value = 0;
var rolling_time = 3000; // 

function promv_imgRolling(){
	var source_li = document.getElementById("promotion_rollingImg").getElementsByTagName("li");
	var source_btn = document.getElementById("promotion_btn").getElementsByTagName("img");
	//var source_btn = document.getElementById("promotion_btn").getElementsByTagName("iframe");
	
	for(i=0; i<source_li.length; i++){
		source_li[i].style.display = "none";
	}
	for(i=0; i<source_btn.length; i++){
		source_btn[i].src = source_btn[i].src.replace("o.gif", "n.gif");
	}
	
	var chg_imgNum = promv_count % source_li.length;
	source_li[chg_imgNum].style.display = "block";
	source_btn[chg_imgNum].src = source_btn[chg_imgNum].src.replace("n.gif", "o.gif");

	promv_count++;
}

function promv_rolling_start(){
	if(!document.getElementById("promotion_rollingImg")) return false;
	if(!document.getElementById("promotion_btn")) return false;

	/* img wrap_height setting */
	document.getElementById("promotion_rollingImg").style.height = "130px";

	//var source_img = document.getElementById("promotion_rollingImg").getElementsByTagName("img");
	var source_img = document.getElementById("promotion_rollingImg").getElementsByTagName("iframe");
	var source_btnWrap = document.getElementById("promotion");
	var source_btn = document.getElementById("promotion_btn").getElementsByTagName("img");
	
	for(i=0; i<source_img.length; i++){
		source_img[i].onmouseover = function(){
			window.clearInterval(func_promv_rolling);
			window.clearInterval(func_promv_imgZoom);
			zoom_check = true;
			func_promv_imgZoom = window.setInterval(promv_imgZoom, 1);
		} // end of over
		
		source_img[i].onmouseout = function(){
			zoom_check = false;
		} // end of out
		source_btnWrap.onmouseover = function(){
			zoom_check = true;
		}
		source_btnWrap.onmouseout = function(){
			zoom_check = false;
		}

		source_btn[i].count = i;
		source_btn[i].onclick = function(){
			window.clearInterval(func_promv_rolling);
			func_promv_rolling = null;
			promv_count = this.count;
			promv_imgRolling();
			func_promv_rolling = setInterval(promv_imgRolling, rolling_time);
		} // end of out
	}
	
	func_promv_rolling = setInterval(promv_imgRolling, rolling_time);
}
addLoadEvent(promv_rolling_start);


function infoTab(){
	if(!document.getElementById("infoTab")) return false;
	
	var layer_array = new Array();
	layer_array[0] = "infoList01";
	layer_array[1] = "infoList02";
	
	var source = document.getElementById("infoTab").getElementsByTagName("img");
	
	for(i=0; i<source.length; i++){
		source[i].count = i;
		source[i].onclick = function(){
			for(j=0; j<source.length; j++){
				source[j].src = source[j].src.replace("o.gif", "n.gif");
				document.getElementById(layer_array[j]).style.display = "none";
			}
			this.src = this.src.replace("n.gif", "o.gif");
			document.getElementById(layer_array[this.count]).style.display = "block";
		} // end of onclick
	}
}
addLoadEvent(infoTab);


function eventTab(){
	if(!document.getElementById("eventTab")) return false;
	
	var layer_array = new Array();
	layer_array[0] = "eventTab_data01";
	layer_array[1] = "eventTab_data02";
	
	var source = document.getElementById("eventTab").getElementsByTagName("img");
	
	for(i=0; i<source.length; i++){
		source[i].count = i;
		source[i].onclick = function(){
			for(j=0; j<source.length; j++){
				source[j].src = source[j].src.replace("o.gif", "n.gif");
				document.getElementById(layer_array[j]).style.display = "none";
			}
			this.src = this.src.replace("n.gif", "o.gif");
			document.getElementById(layer_array[this.count]).style.display = "block";
		} // end of onclick
	}
}
addLoadEvent(eventTab);



function serviceTab(){
	if(!document.getElementById("serviceTab")) return false;
	
	var layer_array = new Array();
	layer_array[0] = "serviceTab_data01";
	layer_array[1] = "serviceTab_data02";
	
	var source = document.getElementById("serviceTab").getElementsByTagName("img");
	
	for(i=0; i<source.length; i++){
		source[i].count = i;
		source[i].onclick = function(){
			for(j=0; j<source.length; j++){
				source[j].src = source[j].src.replace("o.gif", "n.gif");
				document.getElementById(layer_array[j]).style.display = "none";
			}
			this.src = this.src.replace("n.gif", "o.gif");
			document.getElementById(layer_array[this.count]).style.display = "block";
		} // end of onclick
	}
}
addLoadEvent(serviceTab);


var ebsService_all_number = 0;
function ebsService_all(){
	if(!document.getElementById("ebsService_all_block")) return false;
	if(!document.getElementById("ebsService_all_hidden")) return false;
	if(!document.getElementById("ebsService_allLry")) return false;
	
	var btn_open = document.getElementById("ebsService_all_block");
	var btn_close = document.getElementById("ebsService_all_hidden");
	var lry = document.getElementById("ebsService_allLry");

	btn_open.onclick = function(){
		if (ebsService_all_number == 1)
		{	
			ebsService_all_number = 0;
			lry.style.display = "none";
			return false;
		}
		else{
		lry.style.display = "block";
		ebsService_all_number = 1;
		return false;
		}
	}
	btn_close.onclick = function(){
		lry.style.display = "none";
		return false;
	}
}
addLoadEvent(ebsService_all);

var expansion_bd = false;
var func_expansion_bd_motion = null;

function expansion_bd_motion(){
	var target_lry = document.getElementById("expansion_bd");
	var target = 0;
	var alpha = 70;

	if(parseInt(target_lry.style.left, 10) > alpha){
		alpha = parseInt(target_lry.style.left, 10);
	}
		
	if(expansion_bd == true){
		target = 100;
		target = 0.4*(parseInt(target_lry.style.left, 10) - target);
		
		target_lry.style.left = (parseInt(target_lry.style.left, 10) - Math.floor(target)) + "px";
		
		target_lry.style.filter = "alpha(opacity="+alpha+")";
		target_lry.style.MozOpacity = "."+alpha;

		if(parseInt(target_lry.style.left, 10) == 100){
			clearInterval(func_expansion_bd_motion);
		}
		
	}else{
		target = 0;
		target = 0.4*(parseInt(target_lry.style.left, 10) - target);
		target_lry.style.left = (parseInt(target_lry.style.left, 10) - Math.ceil(target)) + "px";

		target_lry.style.filter = "alpha(opacity="+parseInt(target_lry.style.left, 10)+")";
		target_lry.style.MozOpacity = "."+parseInt(target_lry.style.left, 10);
		
		if(parseInt(target_lry.style.left, 10) == target){
			target_lry.style.display = "none";
			clearInterval(func_expansion_bd_motion);
		}
	}
}

var btn_num = 0;
function expansion_bd1(){
	if(!document.getElementById("bd_visiAllBtn")) return false;
	if(!document.getElementById("bd_visiAllHide")) return false;
	if(!document.getElementById("expansion_bd")) return false;
	
	var btn_open = document.getElementById("bd_visiAllBtn");
	var btn_close = document.getElementById("bd_visiAllHide");
	var lry = document.getElementById("expansion_bd");
	
		btn_open.onclick = function(){
			if (btn_num == 1)
			{	
				
				btn_num = 0;
				clearInterval(func_expansion_bd_motion);
			
				btn_open.style.background = "url(http://image.ebs.co.kr/portal/portal_main/ebsService_all_btn.gif) 0 0 no-repeat";
				
				expansion_bd = false;
				func_expansion_bd_motion = setInterval(expansion_bd_motion, 30);
				return false;
			}
			else{
				btn_num = 1;
				if(parseInt(lry.style.left, 10) != 0) return false;
				//clearInterval(func_expansion_bd_motion);
				
				btn_open.style.background = "url(http://image.ebs.co.kr/portal/portal_main/ebsService_all_btnClose.gif) 0 0 no-repeat";
				btn_open.blur();
				
				lry.style.filter = "alpha(opacity=40)";
				lry.style.MozOpacity = .0;
				lry.style.display = "block";
				
				
				expansion_bd = true;
				func_expansion_bd_motion = setInterval(expansion_bd_motion, 30);
				return false;
			}
		}
		btn_close.onclick = function(){
			clearInterval(func_expansion_bd_motion);
			
			btn_open.style.background = "url(http://image.ebs.co.kr/portal/portal_main/ebsService_all_btn.gif) 0 0 no-repeat";
			
			expansion_bd = false;
			func_expansion_bd_motion = setInterval(expansion_bd_motion, 30);
			return false;
			btn_num = 0;
		}
}
addLoadEvent(expansion_bd1);


function eduNewsTab(){
	if(!document.getElementById("eduNewsTab")) return false;
	
	var layer_array = new Array();
	layer_array[0] = "eduNewsTab_list01";
	layer_array[1] = "eduNewsTab_list02";
	layer_array[2] = "eduNewsTab_list03";
	
	var source = document.getElementById("eduNewsTab").getElementsByTagName("img");
	
	for(i=0; i<source.length; i++){
		source[i].count = i;
		source[i].onclick = function(){
			for(j=0; j<source.length; j++){
				source[j].parentNode.className = "normal";
				document.getElementById(layer_array[j]).style.display = "none";
			}
			this.parentNode.className = "over";
			document.getElementById(layer_array[this.count]).style.display = "block";
		} // end of onclick
	}
}
addLoadEvent(eduNewsTab);


function main_banner(){
	if(!document.getElementById("portalMain_banner")) return false;
	var active = 33;
	var over_check = false;
	var li_position = [[0, 375, 425], [0, 50, 425], [0, 50, 100]];

	var source_li = document.getElementById("portalMain_banner").getElementsByTagName("li");
	var source_dl = document.getElementById("portalMain_banner").getElementsByTagName("dl");

	// init setting
	for(i=0; i<source_li.length; i++){
		source_li[i].style.left = li_position[0][i] + "px";
		if(i == 2){
			source_li[i].style.width = "425px";
		}else{
			source_li[i].style.width = "50px";
		}
	}
	
	// motion setting
	var func_motion = null;
	function motion(){
		var count = active%3;
	
		for(i=0; i<source_li.length; i++){
			var temp_left = parseInt(source_li[i].style.left, 10);
			if(li_position[count][i] > temp_left){
				source_li[i].style.left = (temp_left + Math.ceil(0.18*Math.abs(li_position[count][i]-temp_left))) + "px";
				source_li[i].style.left = parseInt(source_li[i].style.left, 10) + 1;
			}else{
				source_li[i].style.left = (temp_left - Math.ceil(0.18*(temp_left-li_position[count][i]))) + "px";
			}
			
			var temp_width = parseInt(source_li[i].style.width, 10);
			if(count == i){
				source_li[i].style.width = (temp_width + Math.ceil(0.17*(425 - temp_width))) + "px";
				source_dl[i].style.left = "-50px";
				source_dl[i].style.cursor = "default";
			}else{
				source_li[i].style.width = "50px";
				source_dl[i].style.left = "0px";
				source_dl[i].style.cursor = "pointer";
			}
		} // end of for
	}
	
	var func_motion_direction = null;
	function motion_direction(){
		active++;
	}
	
	func_motion = setInterval(motion, 30);
	func_motion_direction = setInterval(motion_direction, 5000);
	
	for(k=0; k<source_li.length; k++){
		source_li[k].onmouseover = function(){
			clearInterval(func_motion_direction);
		}
		source_li[k].onmouseout = function(){
			clearInterval(func_motion_direction);
			func_motion_direction = setInterval(motion_direction, 3500);
		}
		source_dl[k].activeNum = k;
		source_dl[k].onmousedown = function(){
			clearInterval(func_motion_direction);
			active = this.activeNum;
		}
	} // end of for
}
addLoadEvent(main_banner);



function etcLink_up_down(){
	if(!document.getElementById("etcLink_up_down")) return false;
	
	source = document.getElementById("etcLink_up_down").getElementsByTagName("img");
	
	for(i=0; i<source.length; i++){
		source[i].onmouseover = function(){
			this.src = this.src.replace("normal.gif", "over.gif");
		}
		source[i].onmouseout = function(){
			this.src = this.src.replace("over.gif", "normal.gif");
		}
	}
}
addLoadEvent(etcLink_up_down);

function etcLink_up_down(){
	if(!document.getElementById("etcLink_up_down")) return false;
	
	source = document.getElementById("etcLink_up_down").getElementsByTagName("img");
	
	for(i=0; i<source.length; i++){
		source[i].onmouseover = function(){
			this.src = this.src.replace("normal.gif", "over.gif");
		}
		source[i].onmouseout = function(){
			this.src = this.src.replace("over.gif", "normal.gif");
		}
	}
}
addLoadEvent(etcLink_up_down);


function familySiteBanner(){
	if(!document.getElementById("familySiteBanner")) return false;

	var func_motion = null;
	var source = document.getElementById("familySiteBanner").getElementsByTagName("LI");
	var source_img = document.getElementById("familySiteBanner").getElementsByTagName("img");
	for(i=0; i<source.length; i++){
		source[i].style.left = (140*i)+"px";
	}

	for(i=0; i<source_img.length; i++){
		source_img[i].onmouseover = function(){
			clearInterval(func_motion);
		}
		source_img[i].onmouseout = function(){
			func_motion = setInterval(BannerMotion, 60);
		}
	}
	
	function BannerMotion(){
		var source = document.getElementById("familySiteBanner").getElementsByTagName("LI");
		for(i=0; i<source.length; i++){
			source[i].style.left = (parseInt(source[i].style.left,10)-2)+"px";
			if(parseInt(source[i].style.left) <= -140){
				source[i].style.left = (parseInt(source[i].style.left)+(source.length*140)) + "px";
			}
		}
	}
	
	func_motion = setInterval(BannerMotion, 60);
}
addLoadEvent(familySiteBanner);


function vod_sumnail(){
	if(!document.getElementById("vod_sumnail")) return false;
	
	var layer_array = new Array();
	layer_array[0] = "vod_sum_img01";
	layer_array[1] = "vod_sum_img02";
	layer_array[2] = "vod_sum_img03";
	
	var source = document.getElementById("vod_sumnail").getElementsByTagName("img");
	
	for(i=0; i<source.length; i++){
		source[i].count = i;
		source[i].onclick = function(){
			for(j=0; j<source.length; j++){
				//source[j].src = source[j].src.replace("o.gif", "n.gif");
				document.getElementById(layer_array[j]).style.display = "none";
			}
			//this.src = this.src.replace("n.gif", "o.gif");
			document.getElementById(layer_array[this.count]).style.display = "block";
		} // end of onclick
	}
}
addLoadEvent(vod_sumnail);


var topLanking5_posY = new Array();
var func_topLanking5_mv = null;
var func_topLanking5_numChange = null;
var topLanking5_posY = [-16, 0, 16, 32, 46, 62, 78, 94, 110, 126];

function topLanking5_mv(){
	var source = document.getElementById("topLanking_main");
	var source_li = document.getElementById("topLanking_main").getElementsByTagName("li");
	
	for(i=0; i<source_li.length; i++){
		source_li[i].targetY = topLanking5_posY[i];
		if(source_li[i].targetY == 126){
			source_li[i].style.top = "126px";
		}else{
			
			target = 0.1*(parseInt(source_li[i].style.top, 10) - source_li[i].targetY);
			source_li[i].style.top = (parseInt(source_li[i].style.top, 10) - Math.ceil(target)) + "px";
		}
	}
}

function topLanking_main(){
	if(!document.getElementById("topLanking_main")) return false;
	if(!document.getElementById("topLanking_main_lyr")) return false;
	
	var source = document.getElementById("topLanking_main");
	var source_li = document.getElementById("topLanking_main").getElementsByTagName("li");
	var source_a = document.getElementById("topLanking_main").getElementsByTagName("a");
	var source_lry = document.getElementById("topLanking_main_lyr");
	
	source.style.display = "none"
	for(i=0; i<source_li.length; i++){
		source_li[i].style.top = (16 * i) + "px";
		source_li[i].style.display = "block";
		source_a[i].onmouseover = function(){
			source_lry.style.display = "block";
			if(document.addEventListener){
				document.addEventListener("mousemove", topLanking_main_ryl_hidden, false);
			}else if(document.attachEvent){
				document.attachEvent("onmousemove", topLanking_main_ryl_hidden, false);
			}else if(document.onclick){
				document.onmousemove = topLanking_main_ryl_hidden;
			}
		}
	}
	source.style.display = "block"
	topLanking_main_mv = setInterval(topLanking5_mv, 30);
	func_topLanking5_numChange = setInterval(topLanking_main_mv_change, 4000)
	
	
}
addLoadEvent(topLanking_main);


function topLanking_main_mv_change(){
	if(!document.getElementById("topLanking_main")) return false;

	topLanking5_posY.unshift(topLanking5_posY[topLanking5_posY.length-1]);
	topLanking5_posY.pop()
}

function topLanking_main_ryl_hidden(nsEvent){
	var source_lry = document.getElementById("topLanking_main_lyr");
	var theEvent = nsEvent ? nsEvent : window.event;
	var theSrc = theEvent.target ? theEvent.target : theEvent.srcElement;
	
	if(theSrc.className == "topLanking_main_lyr" 
	   || (theSrc.nodeName == "A" && theSrc.parentNode.parentNode.parentNode.className == "topLanking_main_lyr")
	   || (theSrc.nodeName == "LI" && theSrc.parentNode.parentNode.className == "topLanking_main_lyr")
	   || (theSrc.nodeName == "UL" && theSrc.parentNode.className == "topLanking_main_lyr")){
		source_lry.style.display = "block";
	}else{
		source_lry.style.display = "none";
	}
}

function search_Frame(){
	var search_frm = document.getElementById("ifrmfor");
	if(eval(search_frm)!= null){
		search_frm.src = "/jsp/portal/search/bestQuery.jsp?page_size=5";
	}
}
addLoadEvent(search_Frame);

