

// This will stop image flickering in IE6 when elements with images are moved
try {
	document.execCommand("BackgroundImageCache", false, true);
} catch(e) {}


function openWin(url, w, h, name, bScrollbar, t, l) {

    if(bScrollbar == null)
        bScrollbar = 0;

    if(name == null)
        name = "popWin";

    if(t == null)
        t = (screen.height-h)/2;

    if(l == null)
        l = (screen.width-w)/2;

    var PopWin = window.open(url, name, "toolbar=0, channelmode=0, location=0, directories=0, resizable=0, menubar=0, scrollbars="+ bScrollbar +", width=" + w + ", height=" + h +", top="+t+", left="+l);

    if(PopWin == null){
        alert('팝업이 차단되어 있습니다.\n\n화면 상단의 차단메세지를 클릭하여 팝업을 허용해주세요.');
        return;
    }

    PopWin.focus();

	return PopWin;

}


// 동영상, 사진. 음성 자료를 열람한다.
// mtype에 따라 미디어를 구분하여 오픈되는 윈도우를 결정한다.
// mtype == V 이면 동영상
// mtype == P 이면 사진
// mtype == S 이면 음성

// msrc = MEDIASRCGBN
// mid = MEDIAID
// mdtl = MEDIADETAILID
// gbn = MEDIAGBN
// flag = 동영상 시청시 일반화질, 고화질 여부 (0:일반, 1:고화질)

function open_content(mtype, msrc, mid, mdtl, gbn, flag) {

	var url = "";
	var features ="";
	
	features = "width=848, height=590, toolbar=0, directories=0, scrollbars=no, resizable=0, status=0";
	
	// 동영상인 경우
	if (mtype == "V") {
		url = "/pop/movie_pop.jsp?srcgbn="+msrc+"&mediaid="+mid+"&mediadtl="+mdtl+"&gbn="+gbn+"&quality="+flag;
	}
	// 사진인 경우
	else if (mtype == "P") {
		if (msrc == "PT") {										// 국가기록사진인 경우
			url = "/pop/photo_pop.jsp?photo_PhotoSrcGBN="+msrc+"&photo_PhotoID="+mid+"&detl_PhotoDTL="+mdtl;
		}
		else {													// 국가기록사진 이외의 사진
			url = "/pop/photo_pop2.jsp?photo_PhotoSrcGBN="+msrc+"&photo_PhotoID="+mid+"&detl_PhotoDTL="+mdtl;
		}
		features = "width=848, height=590, toolbar=0, directories=0, scrollbars=no, resizable=0, status=0";
	}
	// 음성인 경우
	else if (mtype == "S") {
		url = "/pop/audio_pop.jsp?srcgbn="+msrc+"&mediaid="+mid+"&mediadtl="+mdtl+"&gbn="+ gbn;
		features = "width=690, height=525, toolbar=0, directories=0, scrollbars=no, resizable=0, status=0";
	}
	else{														// 오류 처리
		alert("잘못된 요청입니다.");
		return;
	}

	// url 값이 설정되었을 경우에만 윈도우 오픈
	if (url != "")	window.open(url, "ehistory_popup", features);

}

//임시 함수
function open_content_test(mtype, msrc, mid, mdtl, gbn, flag) {

	var url = "";
	var features ="";
	
	features = "width=848, height=590, toolbar=0, directories=0, scrollbars=no, resizable=0, status=0";
	
	// 동영상인 경우
	if (mtype == "V") {
		url = "/pop/movie_pop.jsp?srcgbn="+msrc+"&mediaid="+mid+"&mediadtl="+mdtl+"&gbn="+gbn+"&quality="+flag;
	}
	// 사진인 경우
	else if (mtype == "P") {
		if (msrc == "PT") {										// 국가기록사진인 경우
			url = "/pop/photo_pop_test.jsp?photo_PhotoSrcGBN="+msrc+"&photo_PhotoID="+mid+"&detl_PhotoDTL="+mdtl;
		}
		else {													// 국가기록사진 이외의 사진
			url = "/pop/photo_pop2.jsp?photo_PhotoSrcGBN="+msrc+"&photo_PhotoID="+mid+"&detl_PhotoDTL="+mdtl;
		}
		features = "width=848, height=590, toolbar=0, directories=0, scrollbars=no, resizable=0, status=0";
	}
	// 음성인 경우
	else if (mtype == "S") {
		url = "/pop/audio_pop.jsp?srcgbn="+msrc+"&mediaid="+mid+"&mediadtl="+mdtl+"&gbn="+ gbn;
		features = "width=690, height=525, toolbar=0, directories=0, scrollbars=no, resizable=0, status=0";
	}
	else{														// 오류 처리
		alert("잘못된 요청입니다.");
		return;
	}

	// url 값이 설정되었을 경우에만 윈도우 오픈
	if (url != "")	window.open(url, "ehistory_popup", features);

}

// 대한뉴스, 대한뉴스 KC 호수 전체 영상을 보기 위한 함수
function open_contentsall(msrc, mid, gbn, flag) {
	var url = "/pop/movie_popall.jsp?srcgbn="+msrc+"&mediaid="+mid+"&gbn="+gbn+"&quality="+flag;
	var features = "width=500, height=500, toolbar=0, directories=0, scrollbars=no, resizable=0, status=0";

	window.open(url, "ehistory_popup", features);
 }


function goto_flashconts(fid, url) {
	document.location.href = "/iframe/flash_count.jsp?flashid="+fid+"&url="+url;
}



// IE Eolas Patch 우회 스크립트
function IE_HtmlRewrite(objParent) {
	if (window.ActiveXObject && objParent) {
		objParent.innerHTML = objParent.innerHTML;
	}
}


// 해당일의 요일 구하기
// @param date 2007-01-01 형식으로 입력

var weeks = new Array("일", "월", "화", "수", "목", "금", "토");

function getWeekName(date) {
	var splitDate = date.split("-");
	var checkDate = new Date(splitDate[0],splitDate[1]-1,splitDate[2]);

	return weeks[checkDate.getDay()];
}


// 기관별 문화컨텐츠 보기 팝업

function popMuseum(url) {
	var features = "width=848, height=624, toolbar=0, directories=0, scrollbars=no, resizable=0, status=0";
	window.open(url, "museum", features);
}


function ajaxPaginate(url, divId){
	new Ajax.Updater(
		divId,
		url,
		{
		asynchronous: true,
		evalScripts: true,
		method: 'get',
		onFailure:function(request){alert("오류!!\n\nHTTP Error "+ request.status +" \n\n서버와의 통신을 구성하지 못하였습니다.")}
		}
	);
}


/**********************************************************************/

Tree = Class.create();

Tree.prototype = {
   initialize: function( element, options ) {
      this.ul = $(element);
      this.lis = new Array();

      this.options = {
         element: Tree.Node
      }
      Object.extend( this.options, options );

      this.setup();

	  $(element).style.display = "block";
   },

   setup: function() {
      var name = "";
      var children = this.ul.immediateDescendants();

      children.each( function( child ) {
         name = child.tagName || "";
         if( name != "LI" )
            return;

         this.lis.push( new this.options.element( child, this.options ) );

      }.bind( this ) );



   }


};

/**********************************************************************/

Tree.Node = Class.create();
Tree.Node.prototype = {
   initialize: function( element, options ) {
      this.li = $( element );
      this.uls = new Array();
      this.root = false;

      this.options = {
         more: '/images/plus.png',
         less: '/images/minus.png'
      }
      Object.extend( this.options, options );

      this.setup();


   },

   setup: function() {
      var name = "";
      var children = this.li.immediateDescendants();

      children.each( function( child ) {
         name = child.tagName || "";
         if( name != "UL" )
            return;

         this.uls.push( new Tree( child, this.options ) );
		 child.style.display = "none";
      }.bind( this ) );


      this.checkRoot();
   },

   checkRoot: function( ) {
      if( this.uls.length == 0 ) {
		  Element.addClassName( this.li, 'bullet' );
		  this.tog = Builder.node( 'img',
			 { className: 'bullet', src: this.options.less , alt: '마지막메뉴'} );
		  this.li.insertBefore( this.tog, this.li.childNodes[0] );

		  return;
	  }

      this.root = true;
      Element.addClassName( this.li, 'root' );
      //this.tog = Builder.node( 'img',{ className: 'toggle', src: this.options.more, alt: '하위메뉴표시' });
      //this.tog = Builder.node('a',{href: '#', onclick: 'return false;'},Builder.node( 'img',{ id:'toggle' , className: 'toggle', src: this.options.more, alt: '하위메뉴표시' }));
      this.tog= Builder.node( 'input',{ className: 'toggle' ,type: 'image', src: this.options.more, title: '하위메뉴표시',onclick: 'return false;' });
      this.li.insertBefore( this.tog, this.li.childNodes[0] );
      this.tog.onclick = this.closeChildren.bindAsEventListener( this );
   },

   closeChildren: function( event ) {
      var node;
	   event.cancelBubble = true;

	  this.uls.each( function( ul ) {
         node = ul.ul;
         if( node.visible() ) {
            new Effect.SwitchOff(node);
           this.tog.src = this.options.more;
           
         }
         else {
           new Effect.BlindDown(node);
            this.tog.src = this.options.less;
            
         }
      }.bind( this ) );
   }




};



// playerWrite(파일경로, 가로, 세로, 아이디)
function playerWrite(src, pid, options){

	// 미디어 코드 출력
	document.writeln(getPlayer(src, pid, options));

}

function getPlayer(src, pid, options){

	//그외 embed
	var MEDIA_TYPE = "video/x-ms-asf-plugin";
	var PLUGIN_PAGE = "http://www.microsoft.com/Windows/Downloads/Contents/Products/MediaPlayer/";

	var objectStr = "<object id='"+ pid +"' data='"+ src +"' "+ ((options.width) ? ("width='"+ options.width +"' ") : "") + ((options.height) ? ("height='"+ options.height +"' ") : "") +"type='video/x-ms-asf-plugin'>";

	try{

		var features = options.features.split(/\s*,\s*/);

		for(var i=0;i<features.length;i++){
			var temp = features[i].split(/\s*=\s*/);
			objectStr += "<param name='"+ temp[0] +"' value='"+ temp[1] +"'>";
		}

	}catch(e){/*alert(e.message);*/}

	objectStr += "<embed id='"+ pid +"' type='"+ MEDIA_TYPE +"' pluginspage = '"+ PLUGIN_PAGE +"' src='"+ src +"' "+ ((options.width) ? ("width='"+ options.width +"' ") : "") + ((options.height) ? ("height='"+ options.height +"' ") : "") +"autostart='true' controller='true'></embed></object>";

	/*
	//var objectStr = "<object id='"+ customId +"Object' "+ ((w) ? ("width='"+ w +"' ") : "") + ((h) ? ("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'>" ;
	//var objectStr = "<object id='"+ customId +"Object' "+ ((w) ? ("width='"+ w +"' ") : "") + ((h) ? ("height='"+ h +"' ") : "") +"classid='CLSID:6BF52A52-394A-11d3-B153-00C04F79FAA6' 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'>" ;
	objectStr += "<param name='AutoStart' value='"+ ((autoStart) ? '1' : '0') +"'>";
	objectStr += "<param name='AutoSize' value='1'>";
	objectStr += "<param name='AutoReSize' value='1'>";
	//objectStr += "<param name='uiMode' value='full'>";
	if(src != null)objectStr += "<param name='FileName' value='"+ src +"'>";
	objectStr += "<param name='ShowStatusBar' value='1'>";
	objectStr += "<param name='EnableContextMenu' value='1'>";
	objectStr += "<param name='AnimationAtStart' value='1'>";
	//objectStr += "<PARAM NAME='rate' VALUE='1'><PARAM NAME='balance' VALUE='0'>";
	objectStr += "<embed id='"+ customId +"Embed' type='' pluginspage = '' "+ ((src != null) ? ("src='"+ src +"' ") : " ") + ((w) ? ("width='"+ w +"' ") : "") + ((h) ? ("height='"+ h +"' ") : "") +"autostart='"+ autoStart +"' controller='true'></embed>";
	objectStr += "</object>";*/

	return objectStr;

}