// menu tab
function Khc_Tab(m_id){
	bg_class = "k1"
	var cName = document.getElementById(m_id).className + " " + bg_class
	document.getElementById(m_id).className = cName
	var tList = document.getElementById(m_id).getElementsByTagName("a");
	
	for (i=0;i<tList.length;i++) {
		TabPlay = function() {
			for (y=0;y<tList.length;y++) { 
			tList[y].className = "";
			document.getElementById(m_id + "_sub" + (y+1)).style.display = "none";
			if(this==tList[y]){x=y+1}
			}
			this.className = this.className + "on";
			document.getElementById(m_id + "_sub" + x).style.display = "block";			
			document.getElementById(m_id).className = cName.replace(bg_class,"k" + x);
		}
		tList[i].onclick = TabPlay;
		if(arguments[1]=="Mover"){tList[i].onmouseover = TabPlay;}	}
}

// frame resize
function frameResize(ifrm){
	ifrm.style.height = "";
	setTimeout(function(){
		var ifrmBodyH1 = ifrm.contentWindow.document.body.scrollHeight;
		var ifrmBodyH2 = ifrm.contentWindow.document.documentElement.scrollHeight;
		var ifrmBodyH = (ifrmBodyH1 > ifrmBodyH2) ? ifrmBodyH1 : ifrmBodyH2;
		ifrm.style.height = ifrmBodyH + 0 + "px";
	}, 0);

}

// insert flash
function Khc_Flash(Url, wd, ht, swfId, wm, vars) {// url,width,height,ID,transparent,var
	var TxtSwf = "" ;
	TxtSwf += "<object classid='clsid:D27CDB6E-AE6D-11cf-96B8-444553540000' codebase='http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=8,0,29,0' width='"+ wd +"' height='"+ ht +"' id='"+ swfId +"'>" ;
	TxtSwf += "<param name='movie' value='"+ Url +"'>" ;
	TxtSwf += "<param name='wmode' value='"+ wm +"'>" ;
	TxtSwf += "<param name='FlashVars' value='" + vars + "'>" ;
	TxtSwf += "<param name='allowScriptAccess' value='always'>" ;
	TxtSwf += "<param name='allowFullScreen' value='true'>" ;
	TxtSwf += "<param name='quality' value='high'>" ;
	TxtSwf += "<param name='menu' value='false'>" ;
	TxtSwf += "<embed src='"+ Url +"' width='"+ wd +"' height='"+ ht +"' wmode='"+ wm +"' id='"+ swfId +"' FlashVars='"+ vars +"' allowScriptAccess='always' allowFullScreen='true' quality='high' menu='false' pluginspage='http://www.macromedia.com/go/getflashplayer' type='application/x-shockwave-flash'></embed>" ;
	TxtSwf += "</object>" ;
	document.write (TxtSwf);
}

/*IE6 flicker bug*/
try {document.execCommand('BackgroundImageCache', false, true);} catch(e) {}

// main page tab
function mainTab(id){
	var noticeSave = 0;
	var tab = $('#'+id).find('>.listTab');
	function onSelectTab(){
		var t = $(this);
		var myClass = t.parent('li').attr('class');
		t.parents('.listTab:first').attr('class', 'listTab '+myClass);

		var obj = $('#'+id);
		var objC =obj.find('>.listTab>li');
		var cnt = objC.find('>a').index($(this));

		var oldTab = objC.eq(noticeSave).find('>a');	
		var oldTabImg = oldTab.find('>img').get(0);
		oldTabImg.src = oldTabImg.src.replace('_ov.gif','.gif');
		var newTab = objC.eq(cnt).find('>a');	
		var newTabImg = newTab.find('>img').get(0);
		newTabImg.src = newTabImg.src.replace('.gif','_ov.gif');

		noticeSave = cnt;	
		return false;
	}
	tab.find('>li>a').click(onSelectTab).focus(onSelectTab);
};

// listRotation
function listRotation(obj){
	var wrap = document.getElementById(obj);
	var btn = getElementsByClass(wrap, '*', 'rolling-button');
	var list = getElementsByClass(wrap, '*', 'rolling-bnnr');
	
	var active;
	var oldActive;
	var timer = null;
	var _root = this;
	var autoFlag = true;

	var speed = obj.speed || 3000;

	for(var i=0; i<btn.length; i++){
		var Li = list[i];
		if(i!=0) Li.style.display = "none";
		
		oldActive = active = btn[0];
		addClass(oldActive, "current");
		
		var alink = Li.getElementsByTagName("A");
		for(var j=0; j<alink.length; j++){
			var a = alink[j];
			a.onmouseover = a.onfocus = function(){ _root.rollingStop(); }
			a.onmouseout = a.onblur = function(){ _root.rollingStart(); }
		}
		
		var b = btn[i];
		b.cnt = i;
		b.targetEle = Li;
		b.onclick = function(){
			_root.rollingStop();
			active = this;
			_root.change();			
			return false;
		}
		b.onmouseover = b.onfocus = function(){ _root.rollingStop(); }
		b.onmouseout = b.onblur = function(){ _root.rollingStart(); }
	}

	// 활성화된 배너로 바꿀때
	this.change = function(){
		if(oldActive == active) return; // 화성화된 버튼을 클릭시 return
		
		if(oldActive){
			removeClass(oldActive, "current");
			oldActive.targetEle.style.display = "none";
		}
		addClass(active, "current");
		active.targetEle.style.display = "block";
		
		oldActive = active;
	}
	
	// 배너롤링 동작
	this.rollingStart = function(){
		clearInterval(timer);
		if(autoFlag) timer = setInterval(function(){ _root.rolling(); }, speed);
	}
	this.rollingStop = function(){ clearInterval(timer); }
	this.rolling = function(){
		oldActive = active;
		
		var loop = active.cnt+1;
		if(loop >= btn.length) loop = 0;	

		active = btn[loop];
		_root.change();		
	}
	
	// 배너바꾸기 동작 시작
	_root.rollingStart();
}

// 배너슬라이드
function bnnrslide2(obj){
	var _root = this;
	var sFlag = true;
	var dir = "right"
	var ele = document.getElementById(obj.wrap);
	var ul = getElementsByClass(ele, "UL", "rolling-list")[0];
	var bnnr = getElementsByClass(ele, "*", "rolling-bnnr");
	bnnr.w = bnnr[0].offsetWidth;

	ul.parentNode.style.overflow = "hidden";
	if( bnnr.length <= obj.limitCnt ) return false;
	
	// getStyle
	this.getStyle = function(el, what){
		var target = el;
		var value = "";
		if(target.currentStyle) value = target.currentStyle[what];
		else if(window.getComputedStyle) value = window.getComputedStyle(target,null)[what];
		return parseFloat(value);
	}

	insertBefore(bnnr[bnnr.length-1], bnnr[0]);	
	bnnr.unshift(bnnr[bnnr.length-1]);
	bnnr.pop();
	
	var axis = -bnnr[0].offsetWidth;
	ul.style.left = axis+"px";

	var btnl = getElementsByClass(ele, "BUTTON", "rolling-btnl")[0];
	var btnr = getElementsByClass(ele, "BUTTON", "rolling-btnr")[0];
	btnl.onclick = function(){ clearInterval(loopTimer); _root.leftFunc(); }
	btnl.onmouseover = function(){ clearInterval(loopTimer); }
	btnl.onmouseout = function(){ _root.loop(); }
	
	btnr.onclick = function(){ clearInterval(loopTimer); _root.rightFunc(); }
	btnr.onmouseover = function(){ clearInterval(loopTimer) }
	btnr.onmouseout = function(){ _root.loop() }
	
	var alinks = ul.getElementsByTagName("IMG");
	for(var i=0; i<alinks.length; i++){
		var alink = alinks[i];
		alink.onmouseover = function(){ clearInterval(loopTimer) }
		alink.onmouseout = function(){ _root.loop() }
	}
		
	this.leftFunc = function(){
		if(!sFlag) return false;
		sFlag = false;
		dir = "left"
		
		insertBefore(bnnr[bnnr.length-1], bnnr[0]);
		bnnr.unshift(bnnr[bnnr.length-1]);
		bnnr.pop();

		ul.style.left = axis+"px";
		_root.action(axis*2, axis);
	}
	this.rightFunc = function(){
		if(!sFlag) return false;
		sFlag = false;
		dir = "right"

		insertAfter(bnnr[0], bnnr[bnnr.length-1]);		
		bnnr.push(bnnr[0]);
		bnnr.shift();

		ul.style.left = axis+"px";
		_root.action(axis*2, axis);
	}

	var timer;
	this.action = function(from, to){
		timer = setInterval(function(){
			var speed = (to-from)*0.2;
			speed = (dir=="right") ? Math.floor(speed) : Math.ceil(speed);
			from = _root.getStyle(ul, "left");
			
			if( to==from || Math.abs(from)==1 ){
				clearInterval(timer);
				ul.style.left = to+"px";
				sFlag = true;
				return;
			}
			ul.style.left = from+speed+"px";
		}, 25);
	}
	
	var loopTimer;
	this.loop = function(){
		loopTimer = setInterval(function(){
			dir == "left" ? _root.leftFunc() : _root.rightFunc();
		}, 2000);
	}
	_root.loop();
}

// mouse over Event
function mouseOver(id){
	var objC = $("#"+id);

	objC.find("a").bind("mouseover",function(){
		var cnt = objC.find("a").index($(this));		
		var newTab = objC.find("a").eq(cnt);	
		var newTabImg = newTab.find(">img").get(0);
		newTabImg.src = newTabImg.src.replace(".gif","_ov.gif");	
	});
	
	objC.find("a").bind("mouseout",function(){
		var cnt = objC.find("a").index($(this));
		var oldTab = objC.find("a").eq(cnt);	
		var oldTabImg = oldTab.find(">img").get(0);
		oldTabImg.src = oldTabImg.src.replace("_ov.gif",".gif");
	});
}


jQuery(function($){
	// 탑메뉴활성화
	var topList = $('#topMenu > li');
	function show_txt(){
		t = $(this);
		t.next('span').show();
	}
	topList.find('>a').click(show_txt).mouseover(show_txt).focus(show_txt);

	function hide_txt(){
		topList.find('span').hide();
	}
	topList.find('>a').mouseleave(hide_txt);

	// 배너선택 빨간박스활성화
	var banList = $('.conBtm > .ban > li');
	function show_qual(){
		t = $(this);
		t.find('>span').show();
	}
	banList.find('>a').mouseover(show_qual).focus(show_qual);

	function hide_qual(){
		banList.find('>a>span').hide();
	}
	banList.find('>a>span').mouseleave(hide_qual);
});


//메인 팝업창 띄우기
function popWindow01() {
	window.open("/05_customerService/popup_inquirie.asp", "popUp", "width=763, height=642, left=100, top=50");
}

function popWindow02() {
	window.open("/05_customerService/popup_contactus.asp", "popUp1", "width=763, height=642, left=100, top=50");
}

function popWindow03() {
	window.open("/03_news/news_popup.asp", "popUp1", "width=500, height=444, left=100, top=50");
}

function flash(s,w,h,type,wm,id,autostart)
{
	var obj = new String;
	var parameter = new String;
	var embed = new String;
	var html = new String;
	var allParameter = new String;
	var clsid = new String;
	var codebase = new String;
	var pluginspage = new String;
	var embedType = new String;
	var src = new String;
	var width = new String;
	var height = new String;

	src = s;
	width = w;
	height = h;

	var typ = type ? type : "f";

	if(typ=="f")
	{
		clsid = "D27CDB6E-AE6D-11cf-96B8-444553540000";
		codebase = "http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,29,0";
		pluginspage = "http://www.macromedia.com/go/getflashplayer";
		embedType = "application/x-shockwave-flash";
	} else if(typ=="m") {//?
		clsid="22D6F312-B0F6-11D0-94AB-0080C74C7E95";
		codebase="http://activex.microsoft.com/activex/controls/mplayer/en/nsmp2inf.cab#Version=5,1,52,701";
		embedType="application/x-oleobject";
		parameter += "<param name='FileName' value='"+ src + "'>\n";
		var auto = autostart ? "1" : "0";
		parameter += "<param name='AutoStart' value='"+auto+"'>\n";
	}
	parameter += "<param name='movie' value='"+ src + "'>\n";
	parameter += "<param name='quality' value='high'>\n";

	parameter += "<param name='allowScriptAccess' value='always'>\n";
	if(wm)
	{
	parameter += "<param name='wmode' value='transparent'>\n";
	}
	if ( clsid )
	{
	obj = "<object id='movs' name='movs' classid=\"clsid:"+ clsid +"\" codebase=\""+ codebase +"\" width='"+ width +"' height='"+ height +"'>\n";
	}
	embed += "<embed src='" + src + "' pluginspage='"+ pluginspage + "' type='"+ embedType + "' width='"+ width + "' height='"+ height +"'"+ allParameter +" allowScriptAccess='always' wmode='transparent'></embed>\n";

	if ( obj )
	{
	embed += "</object>\n";
	}
	html = obj + parameter + embed;
	
	document.write( html );
}




