// IE6 Flicker Bug 해결을 위한 Code
try {
	doument.execCommand("BackgroundImageCache", false, true);
} catch(ignored) {}

// 이미지 프리로딩을 위한 함수 jQuery 필요
function preloadImages() {
	var imgCount = $("img").length;
	document.imgArray = new Array();
	var j = 0;
	for(i=0; i<imgCount; i++) {
		document.imgArray[j]=new Image;
		document.imgArray[j++].src=$("img:eq("+i+")").src.replace(".gif","o.gif");
	}
}


// rollOver 이벤트
function rollOverMain() {
	// 메인배너롤
	// 배너
	$(".left_ban a").hover(
		function() { this.getElementsByTagName("img").item(0).src = this.getElementsByTagName("img").item(0).src.replace("off.gif","on.gif"); },
		function() { this.getElementsByTagName("img").item(0).src = this.getElementsByTagName("img").item(0).src.replace("on.gif","off.gif"); }
	);
	$(".left_txt a").hover(
		function() { this.getElementsByTagName("img").item(1).src = this.getElementsByTagName("img").item(1).src.replace("off.gif","on.gif"); },
		function() { this.getElementsByTagName("img").item(1).src = this.getElementsByTagName("img").item(1).src.replace("on.gif","off.gif"); }
	);
	$("#quickBar a").hover(
		function() { this.getElementsByTagName("img").item(0).src = this.getElementsByTagName("img").item(0).src.replace("off.gif","on.gif"); },
		function() { this.getElementsByTagName("img").item(0).src = this.getElementsByTagName("img").item(0).src.replace("on.gif","off.gif"); }
	);
	$("#ban01 a").hover(
		function() { this.getElementsByTagName("img").item(0).src = this.getElementsByTagName("img").item(0).src.replace("off.gif","on.gif"); },
		function() { this.getElementsByTagName("img").item(0).src = this.getElementsByTagName("img").item(0).src.replace("on.gif","off.gif"); }
	);
	$("#ban02 a").hover(
		function() { this.getElementsByTagName("img").item(0).src = this.getElementsByTagName("img").item(0).src.replace("off.gif","on.gif"); },
		function() { this.getElementsByTagName("img").item(0).src = this.getElementsByTagName("img").item(0).src.replace("on.gif","off.gif"); }
	);
	$("#ban03 a").hover(
		function() { this.getElementsByTagName("img").item(0).src = this.getElementsByTagName("img").item(0).src.replace("off.gif","on.gif"); },
		function() { this.getElementsByTagName("img").item(0).src = this.getElementsByTagName("img").item(0).src.replace("on.gif","off.gif"); }
	);
	$("#ban04 a").hover(
		function() { this.getElementsByTagName("img").item(0).src = this.getElementsByTagName("img").item(0).src.replace("off.gif","on.gif"); },
		function() { this.getElementsByTagName("img").item(0).src = this.getElementsByTagName("img").item(0).src.replace("on.gif","off.gif"); }
	);

}


// 탭 메뉴
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 == "boardLastest1" ||
			tabAnchor.item(i).className == "boardLastest2" ||
			tabAnchor.item(i).className == "boardLastest3" ||
			tabAnchor.item(i).className == "boardLastest4"
			) {
			var 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;
		if (thismenu.imgEl) {
			thismenu.onfocus = function () {
				this.onclick();
			}
		}
		thismenu.onclick = tabMenuClick;

		if (!thismenu.container.first) {
			thismenu.container.first = thismenu;
		}
	}
	tabContainer.first.onclick();
}

function tabMenuClick() {
	var currentmenu = this.container.current;
	if (currentmenu != this) {
		if (currentmenu) {
			currentmenu.targetEl.style.display = "none";
			if (currentmenu.imgEl) {
				currentmenu.imgEl.style.backgroundPosition = "0px 0px";
			}
		}

		this.targetEl.style.display = "block";
		if (this.imgEl) {
			this.imgEl.style.backgroundPosition = "0px -25px";
		}
		this.container.current = this;
	}
	return false;
}

function tabMenuOver() {
	var tabContainer = this.current.parentNode;
	var tabDivision = tabContainer.getElementsByTagName("li");
	var i = 0;

	for(i=0; i<tabDivision.length; i++) {
		var thismenu = tabDivision.item(i);

		if(thismenu==this.current) this.current.className = "on";
		else thismenu.className = "";
	}
}



// 탭 메뉴
function initTab2Menu(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 == "bannerLastest1" ||
			tabAnchor.item(i).className == "bannerLastest2" ||
			tabAnchor.item(i).className == "bannerLastest3" ||
			tabAnchor.item(i).className == "bannerLastest4"
			) {
			var 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;
		if (thismenu.imgEl) {
			thismenu.onfocus = function () {
				this.onclick();
			}
		}
		thismenu.onclick = tab2MenuClick;

		if (!thismenu.container.first) {
			thismenu.container.first = thismenu;
		}
	}
	tabContainer.first.onclick();
}

function tab2MenuClick() {
	var currentmenu = this.container.current;
	if (currentmenu != this) {
		if (currentmenu) {
			currentmenu.targetEl.style.display = "none";
			if (currentmenu.imgEl) {
				currentmenu.imgEl.getElementsByTagName("img").item(0).src = currentmenu.imgEl.getElementsByTagName("img").item(0).src.replace("on.gif","off.gif");
			}
		}

		this.targetEl.style.display = "block";
		if (this.imgEl) {
			this.imgEl.getElementsByTagName("img").item(0).src = this.imgEl.getElementsByTagName("img").item(0).src.replace("off.gif","on.gif");
		}
		this.container.current = this;
	}
	return false;
}

function tab2MenuOver() {
	var tabContainer = this.current.parentNode;
	var tabDivision = tabContainer.getElementsByTagName("li");
	var i = 0;

	for(i=0; i<tabDivision.length; i++) {
		var thismenu = tabDivision.item(i);

		if(thismenu==this.current) this.current.className = "on";
		else thismenu.className = "";
	}
}

// 달력 툴팁
function calendar() {
	calendarInit();
}
function calendarInit() {
	$("table.calendar strong").tooltip("#tooltip");
}

// 달력 Ajax
function calendarMoveEvent() {
	$(".calendarMove a").click(function() {
		var Qcount = $(this).attr("href").lastIndexOf(".");
		var curY = $(this).attr("href").substr(Qcount + 10,4);
		var curM = $(this).attr("href").substr(Qcount + 20,2);
		calendarAjax(curY, curM);
		return false;
	});
}

function calendarAjax(curY, curM) {
	$.ajax({
		type: "GET",
		url: "/include/calendar.php",
		data:{"curY": curY,"curM": curM},
		dataType:"xml",
		success: function(xml) {
			var currentYear = $(xml).find("currentYear").text();
			var currentMonth = $(xml).find("currentMonth").text();
			var currentTable = $(xml).find("currentTable").text();

			var preYear = $(xml).find("preYear").text();
			var preMonth = $(xml).find("preMonth").text();
			var nextYear = $(xml).find("nextYear").text();
			var nextMonth = $(xml).find("nextMonth").text();
			$(".calendarMove").html("<a href=\"/index.php?curY=" + preYear + "&amp;curM=" + preMonth + "\"><img src=\"/img/submain8_ar1.gif\" alt=\"이전달\" /></a> <font class=\"CALM_M\">" + currentYear + "." + currentMonth + "</font> <a href=\"/index.php?curY=" + nextYear + "&amp;curM=" + nextMonth + "\"><img src=\"/img/submain8_ar2.gif\" alt=\"다음달\" /></a>");
			$("#calendarTable").html(currentTable);
			calendarInit(); // 달력 툴팁기능 초기화
			calendarMoveEvent();
		},
		error: function(a,b,c,d) {
			$(".calendarMove").html(calendarMove);
			$("#calendarTable").html(calendarTable);
			//$("#calendarTable").html("<span>Error Detected. <br />please contact administrator...</span>");
		},
		beforeSend: function() {
			var calendarMove = $(".calendarMove").html();
			var calendarTable = $("#calendarTable").html();
			$(".calendarMove").html("");
			$("#calendarTable").html("<div style=\"width:50px;height:20px;margin:40px auto;\"><img src=\"/common/ajaxLoading/32-1.gif\" alt=\"로딩중\" /></div>");
		}
	});
}

// 팝업제어
function draggablePopup() {
	$(".divPopup").draggable();
	//$(".divPopup").draggable({ cursor: 'move' });
	//$(".divPopup").css("cursor","move");
}

function debug(title, msg) {
	if(document.getElementById("Debug") == null) return false;
	var debugWindow = document.getElementById("Debug");
	title = title + "";
	msg = msg + "";
	title = title.replace(/</gi,"&lt;");
	title = title.replace(/>/gi,"&gt;");
	msg = msg.replace(/</gi,"&lt;");
	msg = msg.replace(/>/gi,"&gt;");
	debugWindow.innerHTML = debugWindow.innerHTML + "<div class=\"debugLine\"><strong>" + title + "</strong> : " + msg + "</div>";
	var scrollHeight = debugWindow.scrollHeight;
	var scrollTop = debugWindow.scrollTop;
	var divHeight = debugWindow.style.height - 13;
	debugWindow.scrollTop = scrollHeight - divHeight;
}

function OpenWindow(nLink, nTarget, features) {
	if(typeof nLink == "object") url = nLink.href;
	else url = nLink;
	var qResult = window.open( url, nTarget, features );
	if (qResult == null) {
		if ((navigator.userAgent.indexOf("Windows NT 5.1")!=-1) && (navigator.userAgent.indexOf("SV1")!=-1)) {      // SP2 웹 브라우저
			alert("팝업 창이 차단되었습니다.\n브라우저의 상단 노란색 [알림 표시줄]을 클릭하신 후 팝업 창을 허용하도록 선택하여 주세요.");
		}
		else {
			alert("팝업 창을 오픈 할 수 없습니다.\n팝업 차단 프로그램이 설치되어 있으면 팝업 창을 허용하여 팝업 창을 열어 주세요.");
		}
	} else {
	//return qResult;
	}
}

// 기본 플래시
function flashObj(URL,SizeX,SizeY,LnkId,Frm,Flag) // quick
{
    document.write('            <object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" ');
    document.write('                    codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=8,0,0,0" ');
    document.write('                    width="'+SizeX+'" height="'+SizeY+'"  id="'+LnkId+'" align="middle">');
    document.write('            <param name="movie"     value="'+URL+'" />');
    document.write('            <param name="quality"   value="high" />');
    if ( Flag == null || Flag != 'N' )
    {
        document.write('        <param name="wmode"     value="transparent"/>');
    }
 document.write('   <param name="allowScriptAccess" value="always"/> ');
 document.write('   <param name="base" value="." />');
    document.write('            <embed base="." src="'+URL+'" quality="high" width="'+SizeX+'" height="'+SizeY+'"  align="middle" ');
  if ( Flag == null || Flag != 'N' )
    {
        document.write('         wmode="transparent" ');
    }
    document.write('type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" allowScriptAccess="always" swLiveConnect=true name="'+LnkId+'"  />');
    document.write('            </embed></object>');
 if ( Frm == 'Y' ) { // form 태그 들어가는 페이지에 적용
  eval("window." + LnkId + " = document.forms[0]."+ LnkId +"; ");
 }
}

function getCookie( name )
{
        var nameOfCookie = name + "=";
        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 "";
}

function getObject(objectId) {
// checkW3C DOM, then MSIE 4, then NN 4.
//
if(document.getElementById && document.getElementById(objectId)) {
return document.getElementById(objectId);
}
else if (document.all && document.all(objectId)) {
return document.all(objectId);
}
else if (document.layers && document.layers[objectId]) {
return document.layers[objectId];
} else {
return false;
}
}

function notice_getCookie( name )
{
        var nameOfCookie = name + "=";
        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 "";
}

function notice_setCookie( name, value, expiredays ){
        var todayDate = new Date();
        todayDate.setDate( todayDate.getDate() + expiredays );
        document.cookie = name + "=" + escape( value ) + "; path=/; expires=" + todayDate.toGMTString() + ";"
}

function WM_Pop(a,b,c,d,e){
	var url= "/htm/popup.htm?idx="+a;
	var win_name = a;

	if ( notice_getCookie( a ) != "done" ){
		if ( d == "blank"){
		OpenWin = window.open( url ,win_name,"left=0, top=0,toolbar=no,location=no,directories=no,status=no,scrollbars=no,menubar=no,width=5,height=5,top=" + b +",left=" + c +";");
		}else{
			getObject(e).style.visibility = "visible";
		}
	}else{
		if ( d == "blank"){

		}else{
			getObject(e).style.visibility = "hidden";
		}
	}
}

function notice_closeWin(a, b) {
        notice_setCookie( a, "done" , 1); // 1=하룻동안 공지창 열지 않음
        getObject(b).style.visibility = "hidden";
}

function notice_closeWin2(a) {
		getObject(a).style.visibility = "hidden";
}


function OnclickEventInit() {
	$("#footSelectButton1").toggle(function() {
		$(".footSelect1>ul").show();
	},function() {
		$(".footSelect1>ul").hide();
	});
	$("#footSelectButton2").toggle(function() {
		$(".footSelect2>ul").show();
	},function() {
		$(".footSelect2>ul").hide();
	});

	$(".footerView img[title]").tooltip("#tooltip");
}

// 퀵메뉴 제어
function quickBar(defaultTop) {
	var quickBarTimer;
	$(window).scroll(function() {
		clearTimeout(quickBarTimer);
		quickBarTimer = setTimeout("quickBarMove(" + defaultTop + ")",200);
	});
}
function quickBarMove(defaultTop) {
	var minTop = 15;
	if($(window).scrollTop() < defaultTop) var scrollTop = defaultTop;
	else var scrollTop = minTop + $(window).scrollTop();
	$(".quickBar").animate({
		top: scrollTop + "px"
	}, 300 );
}