// Dreamweaver //
// 사용예시 //
//<a href="#" onmouseout="MM_swapImgRestore()" onmouseover="MM_swapImage('객체명','','파일경로이름',1);">
//<img src="img/topmenu01.gif" width="87px" height="26px" name="객체명"></a>

function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_showHideLayers() { //v9.0
  var i,p,v,obj,args=MM_showHideLayers.arguments;
  for (i=0; i<(args.length-2); i+=3)
  with (document) if (getElementById && ((obj=getElementById(args[i]))!=null)) { v=args[i+2];
    if (obj.style) { obj=obj.style; v=(v=='show')?'visible':(v=='hide')?'hidden':v; }
    obj.visibility=v; }
}

function MM_jumpMenu(targ,selObj,restore){ //v3.0
  eval(targ+".location='"+selObj.options[selObj.selectedIndex].value+"'");
  if (restore) selObj.selectedIndex=0;
}
function MM_jumpMenu_blank(selObj,restore){ //v3.0
  eval("window.open='"+selObj.options[selObj.selectedIndex].value+"'");
  if (restore) selObj.selectedIndex=0;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}

function MM_openBrWindow(theURL,winName,features) { //v2.0
  window.open(theURL,winName,features);
}

// 쿠기 생성
function setCookie( name, value, expirehours ) {
var todayDate = new Date();
todayDate.setHours( todayDate.getHours() + expirehours );
document.cookie = name + "=" + escape( value ) + "; path=/; expires=" + todayDate.toGMTString() + ";"
}

// 레이어 창닫기
function closeWin() { 
if ( document.popup.chkbox.checked ){ 
setCookie( "ncookie", "done" , 24 ); 
} 
document.getElementById('divpop').style.display = "none";
}

// 팝업
function openWin(url,wn,sc,ww,wh,le,to) {
	openwin = window.open(url,wn,"'" + "toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=" + sc + ",resizable=yes,width=" + ww + " ,height=" + wh + ",left=" + le + ",top=" + to + "'");
	return false;
}
// 팝업모니터중앙
function popMid(url,wn,ww,wh,sc) {
	le = (screen.width-ww)/2;
	to = (screen.height-wh)/2;
	openwin = window.open(url,wn,"'" + "toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=" + sc + ",resizable=yes,width=" + ww + " ,height=" + wh + ",left=" + le + ",top=" + to + "'");
	return false;
}
// 클릭시 이미지 새창으로 띄우기
var winOpen = null

function displayImage(picName, windowName, windowWidth, windowHeight){
return window.open(picName,windowName,"toolbar=no,scrollbars=no,resizable=no,width=" + (parseInt(windowWidth)+20) + ",height=" + (parseInt(windowHeight)+15))
}

function winClose(){
if(winOpen != null) winOpen.close()
}

function doNothing(){}

// 클릭으로 이미지 바꾸기
function ClickChange(imgName)
{
	if(document.images) document.myImage.src = imgName;
}

//갤러리부분
function winopen(img_view,x,y){
	var img_view = img_view;
	var x = x;
	var y = y;
	window.open("gallery_new.asp?img_src="+img_view, "image", "width="+ x +", height="+ y +",topmagin=0, leftmagin=0, top=0, left=0,scrollbars= yes, resizable=1,toolbar=0, menubar= 0,location=0, directories=0, status=0");
}

// 링크관련
function sub_link(linkurl,w,h,kooboon) {
	if (kooboon=="new")
	{
	window.open('http://'+linkurl+'',''+w+'',''+h+'');
	}else {
	parent.opener.location.href="http://"+linkurl ; 
	}
}

// 관련사이트
function go_site(val){
	var frm = document.link_frm_go;
	if ( val != "" ) {
		frm.target="_blank";
		frm.action=val;
		frm.submit();
	}
}

//바로가기
function goUri(uri,target) { 
	if(uri!="") { window.open(uri,target); }
}
//목록상자바로가기
function goSelect(form,target) {
	var myindex=form.uri.selectedIndex
	myUri = form.uri.options[myindex].value;
	if(myUri!="") { window.open(myUri,target); }
}

// 마우스오버아웃
function imgOver(imgEl) {
	imgEl.src = imgEl.src.replace(".gif", "on.gif");
}
function imgOut(imgEl) {
	imgEl.src = imgEl.src.replace("on.gif", ".gif");
}
function menuOver() {
	this.src = this.src.replace(".gif", "on.gif");
}
function menuOut() {
	this.src = this.src.replace("on.gif", ".gif");
}


//이미지롤오버함수할당 // 퀵메뉴에 적용
//ex) initImgRoll("containerId");
function initImgRoll(containerId) { 
 	imgEl = document.getElementById(containerId).getElementsByTagName("img");
	for (i=0; i<imgEl.length; i++) {
		var menuImg = imgEl[i]
		var where = menuImg.src.indexOf("on.gif",0)
		if (where==-1) {
				menuImg.onmouseover = menuOver;
				menuImg.onmouseout = menuOut;
		}
	}
}


// 탭메뉴
function tabOn(tabid,a) {
	for (i=1;i<=10;i++) {
		if(i<10){inn="0"+i;} else {inn=""+i;}
		tabMenu = document.getElementById("tab"+tabid+"m"+i);
		tabContent = document.getElementById("tab"+tabid+"c"+i);
		if (tabMenu) { //객체가존재하면
			if (tabMenu.tagName=="IMG") { tabMenu.src = tabMenu.src.replace("on.gif", ".gif"); } //이미지일때
			if (tabMenu.tagName=="A") { tabMenu.className=""; } //앵커일때
		}
		if (tabContent) { tabContent.style.display="none"; }
	}
	if(a<10){ann="0"+a;} else {ann=""+a;}
	tabMenu = document.getElementById("tab"+tabid+"m"+a);
	tabContent = document.getElementById("tab"+tabid+"c"+a);
//	alert(tabMenu.tagName);
	if (tabMenu) { //객체가존재하면
		if (tabMenu.tagName=="IMG") { tabMenu.src = tabMenu.src.replace(".gif", "on.gif"); } //이미지일때
		if (tabMenu.tagName=="A") { tabMenu.className="on"; } //앵커일때
	}
	if (tabContent) { tabContent.style.display="block"; }
	tabMore = document.getElementById("tab"+tabid+"more");
}

// 왼쪽메뉴 
function leftMenuOver(containderID) {
	var objwrap = document.getElementById(containderID);
	var imgMenu = objwrap.getElementsByTagName("a");

	for (i=0; i<imgMenu.length; i++) {
		if(imgMenu[i].getElementsByTagName("img").length == 0) continue;

		if (imgMenu[i].getElementsByTagName("img")[0].src.indexOf("_over.gif") != -1 ) {
			continue;
		}
		imgMenu[i].onmouseover = function() {
			subImage = this.getElementsByTagName("img")[0];
			if (subImage.src.indexOf("_over.gif") != -1) return false;
			subImage.src = subImage.src.replace(".gif","_over.gif");
		}
		imgMenu[i].onfocus = function() {
			subImage = this.getElementsByTagName("img")[0];
			if (subImage.src.indexOf("_over.gif") != -1) return false;
			subImage.src = subImage.src.replace(".gif","_over.gif");
		}
		imgMenu[i].onmouseout = function() {
			subImage = this.getElementsByTagName("img")[0];
			subImage.src = subImage.src.replace("_over.gif", ".gif");
		}
		imgMenu[i].onblur = function() {
			subImage = this.getElementsByTagName("img")[0];
			subImage.src = subImage.src.replace("_over.gif", ".gif");
		}
	}
}

//왼쪽메뉴2차메뉴보이기
function activeLNB(id) {
	for(num=1; num<=4; num++) document.getElementById('lm'+num).style.display='none'; //D4MG1~D4MG4 까지 숨긴 다음
	document.getElementById(id).style.display='block'; //해당 ID만 보임
}

// 탭메뉴 공통
function tabMenuOver(containderID) {
	var objwrap = document.getElementById(containderID);
	var imgMenu = objwrap.getElementsByTagName("a");

	for (i=0; i<imgMenu.length; i++) {
		if(imgMenu[i].getElementsByTagName("img").length == 0) continue;

		if (imgMenu[i].getElementsByTagName("img")[0].src.indexOf("_over.gif") != -1 ) {
			continue;
		}
		imgMenu[i].onmouseover = function() {
			subImage = this.getElementsByTagName("img")[0];
			if (subImage.src.indexOf("_over.gif") != -1) return false;
			subImage.src = subImage.src.replace(".gif","_over.gif");
		}
		imgMenu[i].onfocus = function() {
			subImage = this.getElementsByTagName("img")[0];
			if (subImage.src.indexOf("_over.gif") != -1) return false;
			subImage.src = subImage.src.replace(".gif","_over.gif");
		}
		imgMenu[i].onmouseout = function() {
			subImage = this.getElementsByTagName("img")[0];
			subImage.src = subImage.src.replace("_over.gif", ".gif");
		}
		imgMenu[i].onblur = function() {
			subImage = this.getElementsByTagName("img")[0];
			subImage.src = subImage.src.replace("_over.gif", ".gif");
		}
	}
}

// 이미지 오버 공통
function imgMenuOver(containderID) {
	var objwrap = document.getElementById(containderID);
	var imgMenu = objwrap.getElementsByTagName("a");

	for (i=0; i<imgMenu.length; i++) {
		if(imgMenu[i].getElementsByTagName("img").length == 0) continue;

		if (imgMenu[i].getElementsByTagName("img")[0].src.indexOf("_over.gif") != -1 ) {
			continue;
		}
		imgMenu[i].onmouseover = function() {
			subImage = this.getElementsByTagName("img")[0];
			if (subImage.src.indexOf("_over.gif") != -1) return false;
			subImage.src = subImage.src.replace(".gif","_over.gif");
		}
		imgMenu[i].onfocus = function() {
			subImage = this.getElementsByTagName("img")[0];
			if (subImage.src.indexOf("_over.gif") != -1) return false;
			subImage.src = subImage.src.replace(".gif","_over.gif");
		}
		imgMenu[i].onmouseout = function() {
			subImage = this.getElementsByTagName("img")[0];
			subImage.src = subImage.src.replace("_over.gif", ".gif");
		}
		imgMenu[i].onblur = function() {
			subImage = this.getElementsByTagName("img")[0];
			subImage.src = subImage.src.replace("_over.gif", ".gif");
		}
	}
}

// 퀵메뉴부분
// Float layer
function initMoving(target, position, topLimit, btmLimit) {
	if (!target)
		return false;

	var obj = target;
	obj.initTop = position;
	obj.topLimit = topLimit;
	obj.bottomLimit = document.documentElement.scrollHeight - btmLimit;

	obj.style.position = "absolute";
	obj.top = obj.initTop;
	obj.left = obj.initLeft;

	if (typeof(window.pageYOffset) == "number") {
		obj.getTop = function() {
			return window.pageYOffset;
		}
	} else if (typeof(document.documentElement.scrollTop) == "number") {
		obj.getTop = function() {
			return document.documentElement.scrollTop;
		}
	} else {
		obj.getTop = function() {
			return 0;
		}
	}

	if (self.innerHeight) {
		obj.getHeight = function() {
			return self.innerHeight;
		}
	} else if(document.documentElement.clientHeight) {
		obj.getHeight = function() {
			return document.documentElement.clientHeight;
		}
	} else {
		obj.getHeight = function() {
			return 500;
		}
	}

	obj.move = setInterval(function() {
		if (obj.initTop > 0) {
			pos = obj.getTop() + obj.initTop;
		} else {
			pos = obj.getTop() + obj.getHeight() + obj.initTop;
			//pos = obj.getTop() + obj.getHeight() / 2 - 15;
		}

		if (pos > obj.bottomLimit)
			pos = obj.bottomLimit;
		if (pos < obj.topLimit)
			pos = obj.topLimit;

		interval = obj.top - pos;
		obj.top = obj.top - interval / 3;
		obj.style.top = obj.top + "px";
	}, 30)
}

/* 글자확대축소 */
//ex) onclick="setFontSize(+10);"	 onclick="setFontSize(-10);" //단위%
function setFontSize(a) {
	defaultFontSize = "100%";
	obj = document.getElementById("container");
	var objFontSize = obj.style.fontSize;
	var newFontSize = parseInt(objFontSize)+a;
	if (!objFontSize) { objFontSize = parseInt(defaultFontSize); }
	if(a==0) { obj.style.fontSize = defaultFontSize; }
//	alert(parseInt(objFontSize));
	else {
		if (newFontSize>130) { alert("더이상 확대할 수 없습니다"); }
		else if (newFontSize<80) { alert("더이상 축소할 수 없습니다"); }
		else { obj.style.fontSize =  parseInt(objFontSize)+a+"%";  }
	}
}

/* 폰트사이즈  */
//Zoom In & Zoom Out
var zoomRate = 10;            // 확대/축소시 증감률
var maxRate = 300;            //최대확대률
var minRate = 100;            //최소축소률


function GetCookie(name){
    if (document.cookie != "") {
        zoomc = document.cookie.split("; ");
        for (var i=0; i < zoomc.length; i++) {
            zoomv = zoomc[i].split("="); 
            if (zoomv[0] == name) {
                return  unescape(zoomv[1]);
            }
        }
    }else{
        return "";
    }
}

// 화면 확대/축소
function SetCookie(name,value){
    document.cookie = name + "=" + escape (value)+";";
}


function zoom_body(contentid, how) {
    if(GetCookie("zoomVal") != null && GetCookie("zoomVal") != "" && GetCookie("zoomVal") != "undefined"){
        //document.all[contentid].style.zoom = GetCookie("zoomVal");
		document.body.style.zoom = GetCookie("zoomVal");
        currZoom=GetCookie("zoomVal");
    }
    else{
        //document.all[contentid].style.zoom = '100%'; 
		document.body.style.zoom = '100%'; 
        currZoom = '100%';
    }
    if (((how == "in") && (parseInt(currZoom) >= maxRate)) || ((how == "out") && (parseInt(currZoom) <= minRate)) ) {
        return; 
    }
    if (how == "in") {
		//alert(document.body.style.zoom);
        //document.all[contentid].style.zoom = parseInt(document.all[contentid].style.zoom)+zoomRate+'%'
		document.body.style.zoom = parseInt(document.body.style.zoom)+zoomRate+'%';
    }
    else if (how == "out") {
        //document.all[contentid].style.zoom = parseInt(document.all[contentid].style.zoom)-zoomRate+'%'
		document.body.style.zoom = parseInt(document.body.style.zoom)-zoomRate+'%';
    }
	else {
        //document.all[contentid].style.zoom = parseInt(document.all[contentid].style.zoom)-zoomRate+'%'
		document.body.style.zoom = 100+'%';
    }
    SetCookie("zoomVal",document.body.style.zoom);
}

//IE6 png 사용
//ex).png24 { tmp:expression(setPng24(this)); }
function setPng24(obj) {
		obj.width=obj.height="1";
		obj.className=obj.className.replace(/\bpng24\b/i,"");
		obj.style.filter=	"progid:DXImageTransform.Microsoft.AlphaImageLoader(src='"+ obj.src +"',sizingMethod='image');"
		obj.src=""; 
		return "";
}

//도메인 미정 링크
//ex) <a href="/korea/data/information/info/1/week/101.html" onclick="domainLink(this.href); return false;">a</a>
function domainLink(url) {
	var url = url.replace("http://"+document.domain, "");
	url = "/korea/data/information/subway_schedule.php?url=" + url;
	window.open(url,'','width=550,height=550,scrollbars=yes,left=20,top=20');
}

/* IE HTML rewrite */
//ex) IE_HtmlRewrite(document.getElementById("object요소부모id이름"));
function IE_HtmlRewrite(objParent) {
	if (window.activeXObject && objParent) {
		objParent.innerHTML = objParent.innerHTML;
	}
}


// 플래시
function Flash(id,url,w,h,bg,t){
 document.writeln("<object classid='clsid:d27cdb6e-ae6d-11cf-96b8-444553540000' codebase='http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,28,0' width="+w+" height="+h+" id="+id+">");
 document.writeln("<param name='movie' value="+url+" />");
 document.writeln("<param name='wmode' value="+t+" />");
 document.writeln("<param name='bgcolor' value="+bg+" />");
 document.writeln("<param name='allowScriptAccess' value='always' />");
 document.writeln("<param name='quality' value='high' />");
 document.writeln("<param name='menu' value='false' />");
 document.writeln("<embed src="+url+" wmode="+t+" width="+w+" height="+h+" name="+id+" bgcolor="+bg+" allowScriptAccess='always' quality='high' type='application/x-shockwave-flash' pluginspage='http://www.macromedia.com/go/getflashplayer' />");
 document.writeln("</object>");
}

// flashWrite(파일경로, 가로, 세로, 아이디, 배경색, 변수, 윈도우모드)
function flashWrite(url,w,h,id,bg,vars,win)
{
	var flashStr=
	"<object classid='clsid:d27cdb6e-ae6d-11cf-96b8-444553540000' codebase='http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,28,0' width='"+w+"' height='"+h+"' id='"+id+"' align='middle'>"+
		"<param name='allowScriptAccess' value='always' />"+
		"<param name='movie' value='"+url+"' />"+
		"<param name='FlashVars' value='"+vars+"' />"+
		"<param name='wmode' value='"+win+"' />"+
		"<param name='menu' value='false' />"+
		"<param name='quality' value='high' />"+
		"<param name='bgcolor' value='"+bg+"' />"+
		"<embed src='"+url+"' FlashVars='"+vars+"' wmode='"+win+"' menu='false' quality='high' bgcolor='"+bg+"' width='"+w+"' height='"+h+"' name='"+id+"' align='middle' allowScriptAccess='always' type='application/x-shockwave-flash' pluginspage='http://www.macromedia.com/go/getflashplayer' />"+
	"</object>";
	document.write(flashStr);

}

function movieWrite(url,w,h)
{
	var movieStr="<object id='MediaPlayer1' width="+w+" height="+h+" CLASSID='CLSID:22D6f312-B0F6-11D0-94AB-0080C74C7E95' CODEBASE='http://activex.microsoft.com/activex/controls/mplayer/en/nsmp2inf.cab#Version=5,1,52,701'standby='Loading Microsoft Windows Media Player components...' type='application/x-oleobject'>"+
						 "<param name='FileName' value='"+url+"'>"+
					  "</object>"
	document.write(movieStr);
//document.getElementById(id).innerHTML = document.getElementById(id).innerHTML;
}


//VR불러오기
function ptviewerWrite(url,w,h,bgcolor,auto,quality,fov,pan,tilt,fovmin,fovmax,tiltmin,tiltmax,panmin,panmax,bar_x,bar_y,bar_width,bar_height,barcolor)
{
	var vrStr2="<applet name='NaMuZaengEeviewer' archive=../pr/vr/NaMuZaengEeviewer.jar  code=NaMuZaengEeviewer.class width="+w+" height="+h+" mayscript=true>"+
				  "<param name=file value='NaMuZaengEeviewer:0'>"+
				  "<param name=wait value='logotype.gif'>"+
				  "<param name=bgcolor value="+bgcolor+">"+
				  "<param name=auto value="+auto+">"+
				  "<param name=quality value="+quality+">"+
				  "<param name=fov value="+fov+">"+
				  "<param name=pan value="+pan+">"+
				  "<param name=tilt value="+tilt+">"+
				  "<param name=fovmin value="+fovmin+">"+
				  "<param name=fovmax value="+fovmax+">"+
				  "<param name=tiltmin value="+tiltmin+">"+
				  "<param name=tiltmax value="+tiltmax+">"+
				  "<param name=panmin value="+panmin+">"+
				  "<param name=panmax value="+panmax+">"+
				  "<param name=bar_x	value='"+bar_x+"'>"+
				  "<param name=bar_y	value='"+bar_y+"'>"+
				  "<param name=bar_width value='"+bar_width+"'>"+
				  "<param name=bar_height value='"+bar_height+"'>"+
				  "<param name=barcolor value='"+barcolor+"'>"+
				  "<param name=applet0 value='{code= NaMuZaengEemedia.class} {file=sound.au}'>"+
				  "<param name=applet1 value='{code= NaMuZaengEecompass.class}'>"+
				  "<PARAM name=inits value='NaMuZaengEeviewer:startApplet(1)'>"+
				  "<param name=pano0 value='{file="+url+"}'>"+
				"</applet>"

	document.write(vrStr2);
}

/*--------------------------------------------------------------------------*
 *  
 *  wordBreak JavaScript Library for Opera & Firefox
 *  
 *  MIT-style license. 
 *  
 *  2008 Kazuma Nishihata 
 *  http://www.to-r.net
 *  table 클래스명을 wordBreak 라고 주면됨.
 *--------------------------------------------------------------------------*/
new function(){
	if(window.opera || navigator.userAgent.indexOf("Firefox") != -1){
		var wordBreak = function() {
			var wordBreakClass = "wordBreak";
			var table = document.getElementsByTagName("table");
			for(var i=0,len=table.length ; i<len ; i++){
				var tbClass = table[i].className.split(/\s+/);
				for (var j = 0; j < tbClass.length; j++) {
					if (tbClass[j] == wordBreakClass) {
						recursiveParse(table[i])
					}
				}
			}
		}
		var recursiveParse = function(pNode) {
			var childs = pNode.childNodes;
			for (var i = 0; i < childs.length; i++) {
				var cNode = childs[i];
				if (childs[i].nodeType == 1) {
					recursiveParse(childs[i]);
				}else if(cNode.nodeType == 3) {
					if(cNode.nodeValue.match("[^\n ]")){
						var plTxt = cNode.nodeValue.replace(/\t/g,"")
						var spTxt = plTxt.split("");
						spTxt = spTxt.join(String.fromCharCode(8203));
						var chNode = document.createTextNode(spTxt);
						cNode.parentNode.replaceChild(chNode,cNode)
					}
				}
			}
		}

	}else{
		var wordBreak = function() {
			if( document.styleSheets[0].addRule ){
				document.styleSheets[0].addRule(".wordBreak","word-break:break-all");
			}else if( document.styleSheets[0].insertRule ){
				document.styleSheets[0].insertRule(".wordBreak{word-break:break-all}", document.styleSheets[0].cssRules.length );
			}else{
				return false;
			}
		}
	}
	var addEvent = function(elm,listener,fn){
		try{
			elm.addEventListener(listener,fn,false);
		}catch(e){
			elm.attachEvent("on"+listener,fn);
		}
	}
	addEvent(window,"load",wordBreak);
}

/**** onload event func ********/
function addLoadEvent(func){
	var oldonload = window.onload;
	if (typeof window.onload != 'function'){
		window.onload = func;
	}else{
		window.onload = function() {
			oldonload();
			func();
		}
	}
}
/**** onload event func ********/
