// 메인 네비게이션
function initNavigation(seq) {
	nav = document.getElementById("gnb");
	nav.menu = new Array();
	nav.current = null;
	nav.menuseq = 0;
	navLen = nav.childNodes.length;
	
	allA = nav.getElementsByTagName("a")
	for(k = 0; k < allA.length; k++) {
		allA.item(k).onmouseover = allA.item(k).onfocus = function () {
			nav.isOver = true;
		}
		allA.item(k).onmouseout = allA.item(k).onblur = function () {
			nav.isOver = false;
			setTimeout(function () {
				if (nav.isOver == false) {
					if (nav.menu[seq])
						nav.menu[seq].onmouseover();
					else if(nav.current) {
						menuImg = nav.current.childNodes.item(0);
						if (nav.current.submenu)
							nav.current.submenu.style.display = "none";
						nav.current = null;
					}
				}
			}, 500);
		}
	}

	for (i = 0; i < navLen; i++) {
		navItem = nav.childNodes.item(i);
		if (navItem.tagName != "LI")
			continue;

		navAnchor = navItem.getElementsByTagName("a").item(0);
		navAnchor.submenu = navItem.getElementsByTagName("ul").item(0);
		
		navAnchor.onmouseover = navAnchor.onfocus = function () {
			if (nav.current) {
				menuImg = nav.current.childNodes.item(0);
				if (nav.current.submenu)
					nav.current.submenu.style.display = "none";
				nav.current = null;
			}
			if (nav.current != this) {
				menuImg = this.childNodes.item(0);
				if (this.submenu)
					this.submenu.style.display = "block";
				nav.current = this;
			}
			nav.isOver = true;
		}
		nav.menuseq++;
		nav.menu[nav.menuseq] = navAnchor;
	}
	if (nav.menu[seq])
		nav.menu[seq].onmouseover();
}

// Sub Navigation
function subNavigation(seq) {
	snav = document.getElementById("subNav");
	snav.menu = new Array();
	snav.current = null;
	snav.menuseq = 0;
	snavLen = snav.childNodes.length;
	
	allA = snav.getElementsByTagName("a")
	for(k = 0; k < allA.length; k++) {
		allA.item(k).onmouseover = allA.item(k).onfocus = function () {
			snav.isOver = true;
		}
		allA.item(k).onmouseout = allA.item(k).onblur = function () {
			snav.isOver = false;
			setTimeout(function () {
				if (snav.isOver == false) {
					if (snav.menu[seq])
						snav.menu[seq].onmouseover();
					else if(snav.current) {
						menuImg = snav.current.childNodes.item(0);
						menuImg.src = menuImg.src.replace("_on.gif", ".gif");
						if (snav.current.submenu)
							snav.current.submenu.style.display = "block";
						snav.current = null;
					}
				}
			}, 10);
		}
	}

	for (i = 0; i < snavLen; i++) {
		snavItem = snav.childNodes.item(i);
		if (snavItem.tagName != "LI")
			continue;

		snavAnchor = snavItem.getElementsByTagName("a").item(0);
		snavAnchor.submenu = snavItem.getElementsByTagName("ul").item(0);
		
		snavAnchor.onmouseover = snavAnchor.onfocus = function () {
			if (snav.current) {
				menuImg = snav.current.childNodes.item(0);
				menuImg.src = menuImg.src.replace("_on.gif", ".gif");
				if (snav.current.submenu)
					snav.current.submenu.style.display = "block";
				snav.current = null;
			}
			if (snav.current != this) {
				menuImg = this.childNodes.item(0);
				menuImg.src = menuImg.src.replace(".gif", "_on.gif");
				if (this.submenu)
					this.submenu.style.display = "block";
				snav.current = this;
			}
			snav.isOver = true;
		}
		snav.menuseq++;
		snav.menu[snav.menuseq] = snavAnchor;
	}
	if (snav.menu[seq])
		snav.menu[seq].onmouseover();
}

// Tab Content
function initTabMenu(tabContainerID) {
	var tabContainer = document.getElementById(tabContainerID);
	var tabAnchor = tabContainer.getElementsByTagName("a");
	var i = 0;

	for(i=0; i<tabAnchor.length; i++) {
		if (tabAnchor.item(i).className == "tab")
			thismenu = tabAnchor.item(i);
		else
			continue;

		thismenu.container = tabContainer;
		thismenu.targetEl = document.getElementById(tabAnchor.item(i).href.split("#")[1]);
		thismenu.targetEl.style.display = "none";
		thismenu.imgEl = thismenu.getElementsByTagName("img").item(0);
		if (thismenu.imgEl) {
			thismenu.onclick = function () {
				//this.onclick();
			}
		}
		thismenu.onclick = tabMenuClick;
		thismenu.onfocus = tabMenuClick;
		
		if (!thismenu.container.first)
			thismenu.container.first = thismenu;
	}
	tabContainer.first.onclick();
}

function tabMenuClick() {
	currentmenu = this.container.current;
	if (currentmenu != this) {
		if (currentmenu) {
			currentmenu.targetEl.style.display = "none";
			if (currentmenu.imgEl) {
				currentmenu.imgEl.src = currentmenu.imgEl.src.replace("_on.gif", ".gif");
			} else {
				currentmenu.className = currentmenu.className.replace("tab on", "tab");
			}
		}

		this.targetEl.style.display = "block";
		if (this.imgEl) {
			this.imgEl.src = this.imgEl.src.replace(".gif", "_on.gif");
		} else {
			this.className += " on";
		}
		this.container.current = this;
	}
	return false;
}

// 팝업
function pop(url,name,w,h){ window.open(url,name,'width='+w+',height='+h+',scrollbars=no,status=1'); } //Popup(스크롤바없음)
function pops(url,name,w,h){ window.open(url,name,'width='+w+',height='+h+',scrollbars=yes'); } //Popup(스크롤바있음)
function newwin(url){ window.open(url,'new','location=1,directories=1,resizable=1,status=1,toolbar=1,menubar=1,scrollbars=1') } //NewPopup(스크롤바없음)

//빠른서비스
QuickMenu = function(element, startPoint, endPoint) {
	var STATICMENU = element;
	var stmnScrollSpeed = 1;
	var stmnTimer;
	
	RefreshStaticMenu = function ()
	{
		var stmnStartPoint = parseInt(STATICMENU.style.top, 10);
		var stmnEndPoint = parseInt(document.documentElement.scrollTop, 10)+endPoint;
		var stmnRefreshTimer = 1;
		
		if ( stmnStartPoint != stmnEndPoint ) {
				stmnScrollAmount = Math.ceil( Math.abs( stmnEndPoint - stmnStartPoint ) / 17 );
				STATICMENU.style.top = parseInt(STATICMENU.style.top, 10) + ( ( stmnEndPoint<stmnStartPoint ) ? -stmnScrollAmount : stmnScrollAmount ) + "px";
				stmnRefreshTimer = stmnScrollSpeed;
		}
		stmnTimer = setTimeout ("RefreshStaticMenu();", stmnRefreshTimer);
	}
	
	this.InitializeStaticMenu = function ()
	{
			STATICMENU.style.top = startPoint + "px";
			RefreshStaticMenu();
	}
}

// 이미지 롤오버
function over(obj,type){
    if(type) obj.src = obj.src.replace(".gif","_on.gif");
    else  obj.src = obj.src.replace("_on.gif",".gif");
}

// 레이어 노출
function stdShow(id) {
	document.getElementById(id).style.display = "block";
}
function stdHidden(id) {
	document.getElementById(id).style.display = "none";
}

function tagShow(){
	var id = document.getElementById('sourceView');

	if( id.style.display  == "none"){
		id.style.display  = "block";
		flag = true;
	}else{
		id.style.display  = "none";
	}
}

//Sitemap Slide
function setTwittFunc(){
	getTwitt();
}

function numStyle(str){

	var money,i,cnt,strleng;
	strleng=str.length;
	cnt=0;
	money="";
	for(i=strleng-1; i>=0; i--){
		money=str.charAt(i)+money;
		cnt++;
		if(cnt%3==0 && i!=0) money=","+money;
	}
	return money;		
}
		
function moneyType(id){
	node=document.getElementById(id);
	money=node.firstChild.nodeValue;
	node.removeChild(node.firstChild);
	node.appendChild(document.createTextNode(numStyle(money)));
}

function setSitemap(id){
	var	aTag = document.getElementById(id);
	aTag.className="on";
	aTag = document.getElementById(id+"h");
	aTag.className="on";	
}

function setCookie(cName, cValue, cDate) {
	var todayDate = new Date();
	todayDate.setDate( todayDate.getDate() + cDate );
	document.cookie = cName + "=" + escape( cValue) + "; path=/; expires=" + todayDate.toGMTString() + ";";
}

function deleteCookie( cookieName )
{
	var expireDate = new Date();
	//어제 날짜를 쿠키 소멸 날짜로 설정한다.
	expireDate.setDate( expireDate.getDate() - 1 );
	document.cookie = cookieName + "= " + "; expires=" + expireDate.toGMTString() + "; path=/";
}

//쿠키 가져오기
function getCookie(cName) {
	var nameOfCookie = cName + "=";
	var x = 0;
	while ( x <= document.cookie.length )
 
	{
			var y = (x+nameOfCookie.length);
			if ( document.cookie.substring( x, y ) == nameOfCookie ) {
					if ( (endOfCookie=document.cookie.indexOf( ";", y )) == -1 )
							endOfCookie = document.cookie.length;
					return unescape( document.cookie.substring( y, endOfCookie ) );
			}
			x = document.cookie.indexOf( " ", x ) + 1;
			if ( x == 0 )
					break;
	}
	return "";
}

$(document).ready(function(){
	//플래시 오브젝트 
	jQuery("object").each(function(){
		if($(this).parent("p").length==1){
			if($(this).parent("p").next().length==1){
				var target = $(this).parent("p").next();
				$(this).parent("p").remove();
				$(target).before($(this));
			}else{
				var target = $(this).parent("p").parent();
				$(this).parent("p").remove();
				$(target).append($(this));
			}			 
		}
	});

    var embeds = document.getElementsByTagName('embed');
    for (i = 0; i < embeds.length; i++) {
        embed = embeds[i];
        var new_embed;
        // everything but Firefox & Konqueror
        if (embed.outerHTML) {
            var html = embed.outerHTML;
            // replace an existing wmode parameter
            if (html.match(/wmode\s*=\s*('|")[a-zA-Z]+('|")/i))
                new_embed = html.replace(/wmode\s*=\s*('|")window('|")/i, "wmode='transparent'");
            // add a new wmode parameter
            else
                new_embed = html.replace(/<embed\s/i, "<embed wmode='transparent' ");
            // replace the old embed object with the fixed version
            embed.insertAdjacentHTML('beforeBegin', new_embed);
            embed.parentNode.removeChild(embed);
        } else {
            // cloneNode is buggy in some versions of Safari & Opera, but works fine in FF
            new_embed = embed.cloneNode(true);
            if (!new_embed.getAttribute('wmode') || new_embed.getAttribute('wmode').toLowerCase() == 'window')
                new_embed.setAttribute('wmode', 'transparent');
            embed.parentNode.replaceChild(new_embed, embed);
        }
    }

    // loop through every object tag on the site
    var objects = document.getElementsByTagName('object');
    for (i = 0; i < objects.length; i++) {
        object = objects[i];
        var new_object;
        // object is an IE specific tag so we can use outerHTML here
        if (object.outerHTML) {
            var html = object.outerHTML;
            // replace an existing wmode parameter
            if (html.match(/<param\s+name\s*=\s*('|")wmode('|")\s+value\s*=\s*('|")[a-zA-Z]+('|")\s*\/?\>/i))
                new_object = html.replace(/<param\s+name\s*=\s*('|")wmode('|")\s+value\s*=\s*('|")window('|")\s*\/?\>/i, "<param name='wmode' value='transparent' />");
            // add a new wmode parameter
            else
                new_object = html.replace(/<\/object\>/i, "<param name='wmode' value='transparent' />\n</object>");
            // loop through each of the param tags
            var children = object.childNodes;
            for (j = 0; j < children.length; j++) {
                try {
                    if (children[j] != null) {
                        var theName = children[j].getAttribute('name');
                        if (theName != null && theName.match(/flashvars/i)) {
                            new_object = new_object.replace(/<param\s+name\s*=\s*('|")flashvars('|")\s+value\s*=\s*('|")[^'"]*('|")\s*\/?\>/i, "<param name='flashvars' value='" + children[j].getAttribute('value') + "' />");
                        }
                    }
                }
                catch (err) {
                }
            }
            // replace the old embed object with the fixed versiony
            object.insertAdjacentHTML('beforeBegin', new_object);
            object.parentNode.removeChild(object);
        }
    }
});

//iframe resize
var resizeEditor;
function iframeResize() {
    var Height=50;
    var objFrame = document.getElementById("frames");
    var objBody = objFrame.contentWindow.document.body;
    var ifrmHeight = objBody.scrollHeight + (objBody.offsetHeight - objBody.clientHeight);

    if (ifrmHeight > Height) {
        objFrame.height = ifrmHeight;
    } else {
        objFrame.style.height = Height;
    }
    resizeEditor = setTimeout(new Function("iframeResize('" + Height + "')"), 100);
}

function setMinWidth(elementId, width){

	$("#"+elementId+" li ul").each(function(){
		var ulWidth = eval($(this).css("width").replace("px",""));
		var liWidth = eval($(this).parent("li").css("width").replace("px",""));

		var width = (ulWidth < liWidth) ? liWidth+"px" : ulWidth+"px";
		$(this).css("width",width);

		$(this).children("li").each(function(){
			$(this).css("width",width);
		});

	});
}

//메뉴 리사이징
if (!window.XMLHttpRequest || (navigator.appVersion.indexOf("MSIE 7.0") >= 0 )){ //ie 6,7 에서만 실행가능
	$(document).ready(function(){
		setMinWidth('nav');
	});
}

// faq 토글 보기
function setFaqToggle(id) {

	var curDisplay = document.getElementById(id).style.display;

	if (curDisplay == 'none' || curDisplay == '') {

		document.getElementById(id).style.display = 'block';
		document.getElementById(id+'T').style.background = '#d6bcf9';
	} else {

		document.getElementById(id).style.display = 'none';
		document.getElementById(id+'T').style.background = '#f4ecff';
	}
}


// faq 전체보기
function setFaqShowToggle() {

	var i = 1;

	var toggleImg = document.getElementById('butShowAll').src;

	var btnShowAll = 'http://static.naver.com/event/opencast/launching/btn_show_all_1.gif';

	// 보이기
	if (toggleImg == btnShowAll) {

		for( i = 1; i < 9; i++) {
			
			document.getElementById('faqT0' + i).style.backgroundColor = '#f4ecff';
			document.getElementById('faq0' + i).style.display = 'block';
			document.getElementById('butShowAll').src = 'http://static.naver.com/event/opencast/launching/btn_close_all_1.gif';
			document.getElementById('butShowAll').alt = '전체 답변 닫기';
		}


	} else {
	// 숨기기
		for( i = 1; i < 9; i++) {
			
			document.getElementById('faqT0' + i).style.backgroundColor = '#f4ecff';
			document.getElementById('faq0' + i).style.display = 'none';
			document.getElementById('butShowAll').src = btnShowAll;
			document.getElementById('butShowAll').alt = '전체 답변 열기';
		}

	}
}

