/* flash */
function flash(id,w,h,s,wmode,valuename,values)
{
	var str="", sID="";
	if (id.length > 0) { sID = " id='"+id+"' name='"+id+"'"; }
	str += "<object "+sID+" classid='clsid:D27CDB6E-AE6D-11cf-96B8";
	str += "-444553540000'";
	str += " codebase='http://download.macromedia.com/pub/shockwave/cabs";
	str += "/flash/swflash.cab#version=6,0,29,0'";
	str += " width='"+w+"' height='"+h+"'>";
	str += "<param name='movie' value='"+s+"'>";
	str += "<param name='quality' value='high'>";
	str += "<param name='wmode' value='"+wmode+"'>";
	str += "<param name='"+ valuename +"' value='"+ values +"'>";
	str += "<embed "+sID+" src='"+s+"' quality='high' wmode='"+wmode+"'";
	str += " pluginspage='http://www.macromedia.com/go/getflashplayer'";
	str += " type='application/x-shockwave-flash'";
	str += " width='"+w+"' height='"+h+"'></embed>";
	str += "</object>";
	document.write(str);
}

/* css전혀 없으면 */
function styleLinkCheck(){
	var ss = document.styleSheets[0];
	if(ss) return true;
	else return false;
}

// tabList
function tabList(ele, active){
	if(styleLinkCheck() === false) return;
	
	var ele = document.getElementById(ele);
	if(active === undefined) active = 0;			
		
	// tabtit를 포함하는 제목 노드들 수집 
	var btn = ele.getElementsByTagName("*");
	for(var i=0; i<btn.length; i++){
		if(btn[i].className.indexOf('tabtit') != -1){
			btn = btn[i].nodeName;
			btn = ele.getElementsByTagName(btn);
			break;
		}
	}
	
	// 타이틀의 타겟 레이어 이름중 숫자만 뺀 영문만 tab1 중 tab만
	var layerName = btn[0].getElementsByTagName("A")[0].href.split("#")[1];
	layerName = layerName.slice(0, layerName.length-1);
	
	for(var i=0; i<btn.length; i++){
		ele["target" + i] = document.getElementById(layerName + (i+1)); // 노드저장 예) tab1, tab2, tab3
		ele["a" + i] = btn[i].getElementsByTagName("A")[0]; // 탭링크
		ele["img" + i] = btn[i].getElementsByTagName("IMG")[0]; // 이미지노드 저장
		btn[i].style.position = "absolute"; // 제목레이어 적용
		ele.getElementsByTagName("P")[i].style.position = "absolute"; // 더보기 레이어
		ele.getElementsByTagName("P")[i].style.marginTop = 0;
	}
	
	/* 초기세팅 */
	var oldActive = active;
	for(var i=0; i<btn.length; i++){
		ele["a" + i].cnt = i;
		ele["a" + i].onclick = ele["a" + i].onfocus = ele["a" + i].onfocus = function menuActive(){
			ele["target" + oldActive].style.display = "none";
			if(ele["img" + oldActive])
				ele["img" + oldActive].src = ele["img" + oldActive].src.replace("_on", "_off");
			else
				addClass2(btn[oldActive], "off");
			ele["target" + this.cnt].style.display = "block";
			
			if(ele["img" + this.cnt])
				ele["img" + this.cnt].src = ele["img" + this.cnt].src.replace("_off", "_on");
			else
				removeClass2(btn[this.cnt], "off");
			oldActive = this.cnt;
			return false;
		}
		
		if(active == i) continue; // 초기 활성화
		ele["target" + i].style.display = "none";
		if(ele["img" + i])
			ele["img" + i].src = ele["img" + i].src.replace("_on", "_off");
		else
			addClass2(btn[i], "off");
	}
}

// hasClass
function hasClass(element,value) {
	var re = new RegExp("(^|\\s)" + value + "(\\s|$)");
	return re.test(element.className);
}

// addClass
function addClass2(element,value) {
	if (!element.className) {
			element.className = value;
	}else{
		var new_class_name = element.className;
		if (!hasClass(element,value)) {
			element.className += " " + value;
		}
	}
}

// removeClass
function removeClass2(element,value) {
	if (element.className && hasClass(element,value)) {
		var re = new RegExp("(^|\\s)" + value);
		element.className = element.className.replace(re,"");
	}
}

function rotatecontents(objectid){
    
    this.pagingobject=null;
    this.pagingstart='';
    this.pagingdelimiter='/';
    this.pagingend='';
    this.rotatemethod=null;
    this.maxzindex=1;
    this.speed=5;
    this.autoplay=true;
    this.autoplaytime=5;
 
    this.buttonobject=null;
    this.buttontype='text';
    this.buttononclassname='on';
    this.buttononimagename='';

    
    var object=document.getElementById(objectid);
    var items=new Array(),itemsnum,titles=new Array();
    var btns=new Array(),btnsmover=new Array(),btnsmout=new Array();
    var speed,timer,nowno=0,canimove=true;
    var isie=(navigator.userAgent.toLowerCase().indexOf('msie')!=-1)? true : false;
 
    this.initialize=function(){
        var isfirst=true,removeobjs=new Array(),childs=object.childNodes;
        for(var i=0,j=-1,max=childs.length; i<max; i++){
            if(childs[i].nodeType==1){
                j++;
                if(!isfirst) childs[i].style.display='none';
                items.push(childs[i]);
                if(this.rotatemethod=='overlap' || this.rotatemethod=='slide' || this.rotatemethod=='fadein' || this.rotatemethod=='vertical'){
                    speed=this.speed;
                    object.style.position='relative';
                    with(childs[i].style){
                        position='absolute';
                        left='0px';
                        top='0px';
                        width=object.offsetWidth+'px';
						//2009-08-25
                        height=object.offsetHeight+'px';
                        
                    }
                    if(this.rotatemethod=='fadein'){
                        setopacity(childs[i],(isfirst)? 100 : 0);
                    }
                }
                if(isfirst) isfirst=false;
            }
        }
        itemsnum=items.length;
        if(removeobjs[0]){
            for(var i=0,max=removeobjs.length; i<max; i++) object.removeChild(removeobjs[i]);
        }
 
        if(this.pagingobject) this.pagingobject=document.getElementById(this.pagingobject);
        this.settitlenpaging(nowno);
        object.style.width=object.offsetWidth+'px';
        //alert(object.style.width);
		object.style.height=object.offsetHeight+'px';
        object.style.overflow='hidden';
        object.onmouseover =function(){
            clearTimeout(eval(objectid).autoplaytimer);
        }
        object.onmouseout=function(){
            eval(objectid).autoplayaction();
        }
        if(this.buttonobject){
            this.buttonobject=document.getElementById(this.buttonobject);
            var childs=this.buttonobject.childNodes;
            for(var i=0,j=0,max=childs.length; i<max; i++){
                if(childs[i].nodeType==1){
                    childs[i].myno=j;
                    if(childs[i].onmouseover) btnsmover.push(childs[i].onmouseover);
                    if(childs[i].onmouseout) btnsmout.push(childs[i].onmouseout);
                    btns.push(childs[i]);
                    j++;
                }
            }
            if(items.length!=btns.length) this.buttonobject=null;
            else this.setbtns();
        }
        this.autoplayaction();
    }
 
    this.settitlenpaging=function(no){
       
        if(this.pagingobject) this.pagingobject.innerHTML=this.pagingstart+(no+1)+this.pagingdelimiter+itemsnum+this.pagingend;
    }
 
    this.setzindex=function(no){
        for(var i=0; i<itemsnum; i++){
            if(i==no){
                items[i].style.zIndex=this.maxzindex+3;
                items[i].style.display='';
            }else if(i==nowno){
                items[i].style.zIndex=this.maxzindex+2;
            }else{
                items[i].style.zIndex=this.maxzindex+1;
                items[i].style.display='none';
            }
        }
    }
 
    this.setbtns=function(no){
        if(!no && no!==0) no=nowno;
        for(var i=0; i<itemsnum; i++){
            if(i==no){
                this.setbtnon(btns[i]);
                btns[i].onmouseover=null;
                btns[i].onmouseout=null;
            }else{
                this.setbtnoff(btns[i]);
                btns[i].onmouseover=function(){
                    eval(objectid).setbtnon(this);
                    if(btnsmover[this.myno]) btnsmover[this.myno]();
                }
                btns[i].onmouseout=function(){
                    eval(objectid).setbtnoff(this);
                    if(btnsmout[this.myno]) btnsmout[this.myno]();
                }
            }
        }
    }
 
    this.setbtnon=function(target){
        var classes,exist=false;
        if(this.buttontype=='image'){
            var btnimg=target.getElementsByTagName('img')[0];
            var btnimgexp=btnimg.src.substring(btnimg.src.lastIndexOf('.'));
            if(btnimg.src.indexOf(this.buttononimagename+btnimgexp)==-1) btnimg.src=btnimg.src.replace(btnimgexp,this.buttononimagename+btnimgexp);
        }
        classes=target.className.split(' ');
        for(var i=0; i<classes.length; i++) if(classes[i]==this.buttononclassname) exist=true;
        if(!exist) target.className=target.className+' '+this.buttononclassname;
    }
 
    this.setbtnoff=function(target){
        var classes;
        if(this.buttontype=='image'){
            var btnimg=target.getElementsByTagName('img')[0];
            var btnimgexp=btnimg.src.substring(btnimg.src.lastIndexOf('.'));
            if(btnimg.src.indexOf(this.buttononimagename+btnimgexp)!=-1) btnimg.src=btnimg.src.replace(this.buttononimagename+btnimgexp,btnimgexp);
        }
        if(target.className.indexOf(this.buttononclassname)!=-1){
            if(target.className.indexOf(' ')==-1) target.className=target.className.replace(this.buttononclassname,'');
            else{
                classes=target.className.split(' ');
                for(var i=0; i<classes.length; i++) if(classes[i]==this.buttononclassname) classes[i]='';
                target.className=classes.join(' ');
            }
        }
    }
 
    this.change=function(no){
        no=no-1;
        if(no!=nowno){
            if(this.rotatemethod=='overlap') this.moveaction('overlap',no,(no<nowno)? 'prev' : 'next');
            else if(this.rotatemethod=='slide') this.moveaction('slide',no,(no<nowno)? 'prev' : 'next');
            else if(this.rotatemethod=='vertical') this.moveaction('vertical',no,(no<nowno)? 'prev' : 'next');
            else if(this.rotatemethod=='fadein') this.fadeinaction(no);
            else this.hideitem(no);
            this.settitlenpaging(no);
            if(this.buttonobject) this.setbtns(no);
        }
    }

	this.stop = function() {
		clearTimeout(eval(objectid).autoplaytimer);
		this.hideitem;
	};

	this.play = function() {
		if(!this.autoplay) return;
        this.autoplaytimer=setTimeout(objectid+'.next()',this.autoplaytime*1000);
	};

   this.prev=function(){
        var prevno=(nowno==0)? itemsnum-1 : nowno-1;
        if(this.rotatemethod=='overlap') this.moveaction('overlap',prevno,'prev');
        else if(this.rotatemethod=='slide') this.moveaction('slide',prevno,'prev');
        else if(this.rotatemethod=='vertical') this.moveaction('vertical',prevno,'prev');
        else if(this.rotatemethod=='fadein') this.fadeinaction(prevno);
        else this.hideitem(prevno);
        this.settitlenpaging(prevno);
    }
 
    this.next=function(){
        var nextno=(nowno==(itemsnum-1))? 0 : nowno+1;
        if(this.rotatemethod=='overlap') this.moveaction('overlap',nextno,'next');
        else if(this.rotatemethod=='slide') this.moveaction('slide',nextno,'next');
        else if(this.rotatemethod=='vertical') this.moveaction('vertical',nextno,'next');
        else if(this.rotatemethod=='fadein') this.fadeinaction(nextno);
        else this.hideitem(nextno);
        this.settitlenpaging(nextno);
        if(this.buttonobject) this.setbtns(nextno);
    }
 
    this.autoplaytimer=null;
    this.autoplayaction=function(){
        if(!this.autoplay) return;
        this.autoplaytimer=setTimeout(objectid+'.next()',this.autoplaytime*1000);
    }
 
    this.hideitem=function(no){
        clearTimeout(this.autoplaytimer);
        for(var i=0; i<itemsnum; i++) items[i].style.display=(i==no)? '' : 'none';
        this.autoplayaction();
        nowno=no;
    }
 
    var getleft=function(no){
        return parseInt(items[no].style.left);
    }
    var setleft=function(no,value){
        items[no].style.left=value+'px';
    }

	var gettop=function(no){
        return parseInt(items[no].style.top);
    }
	var settop=function(no,value){
        items[no].style.top=value+'px';
    }
 
    this.moveaction=function(method,no,direction){
        clearTimeout(this.autoplaytimer);
        if(canimove){
            canimove=false;

            if(method=='slide') setleft(no,(direction=='prev')? -(object.offsetWidth) : object.offsetWidth);
            if(method=='vertical') settop(no,(direction=='prev')? -(object.offsetHeight) : object.offsetHeight);
            
            this.setzindex(no);
            var nowv,now,snow,to=0,mv=0;
            var action=function(){
                clearTimeout(timer);
                now=getleft(no);
                nowv=gettop(no);

                if(method=='slide') snow=getleft(nowno);
				if(method=='vertical') snow=gettop(nowno);
                
                if(now!=to){
                    mv=(now-to)/speed;
                    setleft(no,(direction=='prev')? Math.ceil(now-mv) : Math.floor(now-mv));                  
                    if(method=='slide') setleft(nowno,(direction=='prev')? Math.ceil(snow-mv) : Math.floor(snow-mv));                   
                    setTimeout(action,10);
                }else if (nowv!=to)
                {
					mv=(nowv-to)/speed;
                    settop(no,(direction=='prev')? Math.ceil(nowv-mv) : Math.floor(nowv-mv));           
                    if(method=='vertical') settop(nowno,(direction=='prev')? Math.ceil(snow-mv) : Math.floor(snow-mv));
                    setTimeout(action,10);
                }
				else{
                    eval(objectid+'.autoplayaction()');
                    clearTimeout(timer);
                    canimove=true;
                    nowno=no;
                }
            }
            action();
        }
    }
 
    var getopacity=function(target){
        return (isie)? parseInt(target.style.filter.match(/alpha\(opacity=([0-9]+)\)/)[1]) : target.style.opacity*100;
    }
 
    var setopacity=function(target,value){
        if(isie) target.style.filter='alpha(opacity='+value+')';
        else target.style.opacity=value/100;
    }
 
    this.fadeinaction=function(no){
        clearTimeout(this.autoplaytimer);
        if(canimove){
            canimove=false;
            setopacity(items[no],0);
            this.setzindex(no);
            var nowo,to=0;
            var action=function(){
                clearTimeout(timer);
                nowo=getopacity(items[no]);
                if(nowo!=100){
                    setopacity(items[no],Math.ceil(nowo+(100-nowo)/speed));
                    setTimeout(action,10);
                }else{
                    eval(objectid+'.autoplayaction()');
                    clearTimeout(timer);
                    canimove=true;
                    nowno=no;
                }
            }
            action();
        }
    }
 
}

// LNB
var lnbNavi = function(gnbID,noscript,currentNum){
	var wrapper = document.getElementById(gnbID);
	if (noscript) removeClass(wrapper,noscript);	// 스크립트가 로딩되면 wrapper의 class중 'noscript'를 삭제합니다.

	var menu = getClass('depth1','li',wrapper);
	var menuLink = [];			// 이벤트를 발생시킬 대메뉴의 a들
	var submenu = [];			// 대메뉴의 하위에 위치한 ul들
	var submenuLink = [];		// 서브메뉴의 a들

	var initialize = function(){
		for (var i=0; i<menu.length; i++){
			menuLink[i] = menu[i].getElementsByTagName('a')[0];
			submenu[i] = menu[i].getElementsByTagName('div')[0];	// 서브메뉴는 div
			if(submenu[i] == undefined){
				submenu[i] = null;
			}
			if(submenu[i]) submenu[i].style.display = 'none';	// 서브메뉴 'hidden'초기화

			showCurrentmenu(i);
		}
		if (currentNum) menuLink[currentNum-1].onmouseover();		// 현재 메뉴 활성화
	};
	var showCurrentmenu = function(num){
		menuLink[num].onmouseover = menuLink[num].onfocus = function(){
			for(var i=0; i<menu.length; i++){
				var imgEl = menuLink[i].getElementsByTagName('img')[0];
				if(i == num){
					if (menu[i].className.indexOf('visible') == -1) addClass(menu[i],'visible');		// 활성화 된 메뉴에 class추가
					if (imgEl && imgEl.src.indexOf('_on.gif') == -1) imgEl.src = imgEl.src.replace('_off.gif', '_on.gif');	// 대메뉴 이미지 오버
					if(submenu[i]) {					// 서브메뉴가 있을때만 실행한다.
						submenu[i].style.display = 'block';
						subImgOver(i);					// 서브메뉴의 이미지 오버
					}
				} else {
					removeClass(menu[i],'visible');
					if (imgEl) imgEl.src = imgEl.src.replace('_on.gif', '_off.gif');
					if(submenu[i]) {					// 서브메뉴가 있을때만 실행한다.
						submenu[i].style.display = 'none';
					}
				}
			}
		}
		/* 마우스 아웃시 최초 활성화된 서브메뉴를 자동 보임
		menuLink[num].onmouseout = function(){
			if(currentNum) {
				setTimeout(function(){if (currentNum) menuLink[currentNum-1].onmouseover();},1000);
			}
		}
		*/
	};
	var subImgOver = function(num){
		submenuLink = submenu[num].getElementsByTagName('a');
		for(var i=0; i<submenuLink.length; i++){
			var imgEl = submenuLink[i].getElementsByTagName('img');
			for(var j=0; j<imgEl.length; j++){
				imgEl[j].onmouseover = imgEl[j].onfocus = function(){
					this.src = this.src.replace('_off.gif','_on.gif');
				}
				imgEl[j].onmouseout = imgEl[j].onblur = function(){
					this.src = this.src.replace('_on.gif','_off.gif');
				}
			}
		}
	}
	initialize();
}

// add class
function addClass(element,value) {
	if (!element.className) {
		element.className = value;
	} else {
		newClassName = element.className;
		newClassName += " ";
		newClassName += value;
		element.className = newClassName;
	}
}

// remove class
function removeClass(element,value) {
	if (element.className == value) {
		element.className = "";
	} else if (element.className.indexOf(value) != -1) {
		element.className = element.className.replace(value,"");
	}
}

// get Class
function getClass(classname, tagname, tarID) {
	if (tarID == undefined) tarID = document;
	var element = this.nodeType == 1 ? this : tarID;
	var elements = [], nodes = tagname ? element.getElementsByTagName(tagname) : element.getElementsByTagName('*');	
	for(var i=0; i<nodes.length; i++) {
		var elementClassName = nodes[i].className;
		if (elementClassName.length > 0 && (elementClassName == arguments[0] || new RegExp("(^|\\s)" + arguments[0] + "(\\s|$)").test(elementClassName))) {
			elements.push(nodes[i]);
		}
	}
	return elements;
}

//Element ID 불러쓰기
function dEI(elementID){
	return document.getElementById(elementID);
}

// 이미지 롤오버
function imgRollovermain(imgBoxID){
	var MenuCounts = dEI(imgBoxID).getElementsByTagName("img");

	for (i=0;i<MenuCounts.length;i++) {
		var numImg=MenuCounts.item(i);
		var ImgCheck = numImg.src.substring(numImg.src.length-6,numImg.src.length);
		if (ImgCheck!="_on.gif") {
				numImg.onmouseover = function () {
					this.src = this.src.replace("_off.gif", "_on.gif");
				}
				numImg.onmouseout = function () {
					this.src = this.src.replace("_on.gif", "_off.gif");
				}
			}
	}
}

//popup
function openPop(url,winnm,width,height,etc_options)
{
	var options = "width="+width+",height="+height;
	if(etc_options) options += ","+etc_options;
	var oWindow = window.open(url,winnm,options);
	return oWindow;
}

function centerPop(url,winnm,width,height,etc_options)
{
	var OpenerLeft = (window.screenLeft != undefined) ? window.screenLeft : window.screenX;
	var OpenerTop = (window.screenTop != undefined) ? window.screenTop : window.screenY;
	var brWidth = (window.outerWidth) ? window.outerWidth : document.documentElement.clientWidth;
	var popLeft = OpenerLeft + parseInt((brWidth-width)/2);
	var popTop = parseInt((window.screen.availHeight-height)/2);
	openPop(url,winnm,width,height,'left='+popLeft+',top='+popTop+','+etc_options);
}

// showBx
var showBx = function(id) {
	var id = document.getElementById(id);

	if(id.style.display=="block"){
		id.style.display="none";
	}  else {
		id.style.display="block";
	}
}

// 팝업레이어 
var layOpen = function(id){
	var id=document.getElementById(id);
	id.style.display="block";
} 

var layClose = function(id){
	var id=document.getElementById(id);
	id.style.display="none";
}
