/***************************************************************************************
******************************** GNB RollOver MENU *************************************
****************************************************************************************/
var TimeOut         = 300;
var currentLayer    = null;
var currentitem     = null;

var currentLayerNum = 0;
var noClose         = 0;
var closeTimer      = null;

// Open Hidden Layer
function mopen(n)
{
    var l  = document.getElementById("menu"+n);
    var mm = document.getElementById("mmenu"+n);
    
    if(l)
    {
        mcancelclosetime();
        l.style.visibility='visible';

        if(currentLayer && (currentLayerNum != n))
            currentLayer.style.visibility='hidden';

        currentLayer = l;
        currentitem = mm;
        currentLayerNum = n;            
    }
    else if(currentLayer)
    {
        currentLayer.style.visibility='hidden';
        currentLayerNum = 0;
        currentitem = null;
        currentLayer = null;
    }
}

// Turn On Close Timer
function mclosetime()
{
    closeTimer = window.setTimeout(mclose, TimeOut);
}

// Cancel Close Timer
function mcancelclosetime()
{
    if(closeTimer)
    {
        window.clearTimeout(closeTimer);
        closeTimer = null;
    }
}

// Close Showed Layer
function mclose()
{
    if(currentLayer && noClose!=1)
    {
        currentLayer.style.visibility='hidden';
        currentLayerNum = 0;
        currentLayer = null;
        currentitem = null;
    }
    else
    {
        noClose = 0;
    }

    currentLayer = null;
    currentitem = null;
}

// Close Layer Then Click-out
document.onclick = mclose;


/***************************************************************************************
******************************** LNB MENU *************************************
****************************************************************************************/
function initLnb() {
	var objli = document.getElementById("leftMenu").getElementsByTagName("LI");
	var obja = document.getElementById("leftMenu").getElementsByTagName("a");
	for(var k=0; k<objli.length; k++) {
		var imgli = objli.item(k);
		var imga = obja.item(k);
		//var imgobj = imgli.className.split(" ")[1];
		//if(imgobj == "on" || "onsub") {
			//imga.getElementsByTagName("img").item(0).onmouseover = imgon;
			//imga.getElementsByTagName("img").item(0).onmouseout = imgon;
			//imga.getElementsByTagName("img").item(0).onmouseover();
		//}
		imga.getElementsByTagName("img").item(0).onmouseover = imgon;
		imga.getElementsByTagName("img").item(0).onmouseout = imgoff;
		//imga.getElementsByTagName("img").item(0).onmouseout();
	}
}

function initLnbIdx(menuElId, index) {
	var lnbMenu = document.getElementById(menuElId).getElementsByTagName("a");
	for(i=0; i<lnbMenu.length; i++) {
		thismenu = lnbMenu.item(i);
		thismenu.menuContainer = document.getElementById(menuElId);
		//thismenu.targetEl = document.getElementById(lnbMenu.item(i).href.split("#")[1]);
		thismenu.getElementsByTagName("img").item(0).onmouseover = imgon;
		thismenu.getElementsByTagName("img").item(0).onmouseout = imgoff;
		//thismenu.onclick = lnb(obj);
	}
	initmenu = lnbMenu.item(index);
	initmenu.getElementsByTagName("img").item(0).onmouseover = imgon;
	initmenu.getElementsByTagName("img").item(0).onmouseout = imgon;
	initmenu.getElementsByTagName("img").item(0).onmouseover();
	initmenu.menuContainer.current = initmenu;
	thismenu = lnbMenu.item(0);
	thismenu.getElementsByTagName("img").item(0).onmouseout();
}

function image_chg(obj,off) {
	var imgobj = obj.childNodes[0];
	if(!off){
		if(imgobj.src.indexOf("_on") == -1){
			imgobj.src = imgobj.src.replace("_off.gif","_on.gif")
			return;
		}else return false;
	}else{
		if(imgobj.src.indexOf("_on") != -1) imgobj.src = imgobj.src.replace("_on.gif","_off.gif")
	}
	return;
}

function upfind(el,target) {
	var loca = el;
	var rootchk=0;
	while(loca.tagName != target) {
		if(loca.tagName == "UL") rootchk++;
		loca = loca.parentNode;
	}
	this.root = rootchk;
	return loca;
}

function lnb(obj) {
	var chkmom = obj.parentNode.parentNode;
	var chkfr = obj.parentNode;
	var dvmom = upfind(obj,"DIV");
	var w=0;
	var subchk = (chkfr.getElementsByTagName("ul")[0]) ? 0 : 1;
	//alert(document.location.href);
	for(var i=0; i<chkmom.childNodes.length; i++){
		if(chkmom.childNodes[i].tagName == "LI"){
			var a = chkmom.childNodes[i].getElementsByTagName("a")[0];
			if(chkmom.childNodes[i].className.indexOf("dep02") != -1 )  chkmom.childNodes[i].className="dep02";
			else chkmom.childNodes[i].className="dep01";
			image_chg(a,"off");
			a.getElementsByTagName("img").item(0).onmouseover = imgon;
			a.getElementsByTagName("img").item(0).onmouseout = imgoff;
			w++;
		}
	}
	if(subchk) {
		document.location.href = obj.href;
		if(chkfr.className=="dep01") chkfr.className="dep01 on";
		if(chkfr.className=="dep02") chkfr.className="dep02 on";
		image_chg(obj);
		chkfr.getElementsByTagName("img").item(0).onmouseover = imgon;
		chkfr.getElementsByTagName("img").item(0).onmouseout = imgon;
		chkfr.getElementsByTagName("img").item(0).onmouseover();
		return false;
	}
	var subul = chkfr.getElementsByTagName("ul")[0];
	if(root == 1){
		for(var j=0; j<subul.childNodes.length; j++){
			if(subul.childNodes[j].tagName == "LI"){
				var b = subul.childNodes[j].getElementsByTagName("a")[0];
				image_chg(b,"off");
			}
		}
		if(chkfr.className=="dep02") chkfr.className="dep02";
		else chkfr.className="dep01 onsub";
		
		var imgobj = chkfr.className.split(" ")[1]; 
		if(imgobj == "on" || "onsub") {
			chkfr.getElementsByTagName("img").item(0).onmouseover = imgon;
			chkfr.getElementsByTagName("img").item(0).onmouseout = imgon;
			chkfr.getElementsByTagName("img").item(0).onmouseover();
		}
		//image_chg(subul.getElementsByTagName("li")[0].getElementsByTagName("a")[0]);
	}
	image_chg(obj);
	return false;
}

function imgon() {
	this.src = this.src.replace("_off.gif", "_on.gif");
}
function imgoff() {
	this.src = this.src.replace("_on.gif", "_off.gif");
}


/* 이미지 롤오버 */
function img_on(obj) { 
	obj.src = obj.src.replace('_off.gif','_on.gif');  
}    

function img_off(obj) {
	obj.src = obj.src.replace('_on.gif','_off.gif');  
}  




/* 탭메뉴 */
function initTab(menuElId) {
	var tabMenu = document.getElementById(menuElId).getElementsByTagName("a");
	for(i=0; i<tabMenu.length; i++) {
		thismenu = tabMenu.item(i);
		thismenu.menuContainer = document.getElementById(menuElId);
		thismenu.targetEl = document.getElementById(tabMenu.item(i).href.split("#")[1]);
		thismenu.targetEl.style.display = "none";
		thismenu.getElementsByTagName("img").item(0).onmouseover = imgoff;
		thismenu.getElementsByTagName("img").item(0).onmouseout = imgoff;
		thismenu.onclick = tabClick;
	}
	initmenu = tabMenu.item(0);
	initmenu.targetEl.style.display = "block";
	initmenu.getElementsByTagName("img").item(0).onmouseover = imgon;
	initmenu.getElementsByTagName("img").item(0).onmouseout = imgon;
	initmenu.getElementsByTagName("img").item(0).onmouseover();
	initmenu.menuContainer.current = initmenu;
}

function initTabIdx(menuElId, index) {
	var tabMenu = document.getElementById(menuElId).getElementsByTagName("a");
	for(i=0; i<tabMenu.length; i++) {
		thismenu = tabMenu.item(i);
		thismenu.menuContainer = document.getElementById(menuElId);
		thismenu.targetEl = document.getElementById(tabMenu.item(i).href.split("#")[1]);
		thismenu.targetEl.style.display = "none";
		thismenu.getElementsByTagName("img").item(0).onmouseover = imgoff;
		thismenu.getElementsByTagName("img").item(0).onmouseout = imgoff;
		thismenu.onclick = tabClick;
	}
	initmenu = tabMenu.item(index);
	initmenu.targetEl.style.display = "block";
	initmenu.getElementsByTagName("img").item(0).onmouseover = imgon;
	initmenu.getElementsByTagName("img").item(0).onmouseout = imgon;
	initmenu.getElementsByTagName("img").item(0).onmouseover();
	initmenu.menuContainer.current = initmenu;
	thismenu = tabMenu.item(0);
	thismenu.getElementsByTagName("img").item(0).onmouseout();
}

function tabClick() {
	currentmenu = this.menuContainer.current;
	if (currentmenu != this) {
		currentmenu.targetEl.style.display = "none";
		currentmenu.getElementsByTagName("img").item(0).onmouseover = imgoff;
		currentmenu.getElementsByTagName("img").item(0).onmouseout = imgoff;
		currentmenu.getElementsByTagName("img").item(0).onmouseout();
	
		this.targetEl.style.display = "block";
		this.getElementsByTagName("img").item(0).onmouseover = imgon;
		this.getElementsByTagName("img").item(0).onmouseout = imgon;
		this.getElementsByTagName("img").item(0).onmouseover();
		this.menuContainer.current = this;
	}
	return false;
}

// 글자탭
function txtTab(menuElId) {
	var tabMenu = document.getElementById(menuElId).getElementsByTagName("a");
	for(i=0; i<tabMenu.length; i++) {
		thismenu = tabMenu.item(i);
		thismenu.menuContainer = document.getElementById(menuElId);
		thismenu.targetEl = document.getElementById(tabMenu.item(i).href.split("#")[1]);
		thismenu.targetEl.style.display = "none";
		thismenu.className = "";
		thismenu.onclick = txtTabClick;
	}
	initmenu = tabMenu.item(0);
	initmenu.className = "on";
	initmenu.targetEl.style.display = "block";
	initmenu.menuContainer.current = initmenu;
}

function txtTabIdx(menuElId, index) {
	var tabMenu = document.getElementById(menuElId).getElementsByTagName("a");
	for(i=0; i<tabMenu.length; i++) {
		thismenu = tabMenu.item(i);
		thismenu.menuContainer = document.getElementById(menuElId);
		thismenu.targetEl = document.getElementById(tabMenu.item(i).href.split("#")[1]);
		thismenu.targetEl.style.display = "none";
		thismenu.className = "";
		thismenu.onclick = txtTabClick;
	}
	initmenu = tabMenu.item(index);
	initmenu.className = "on";
	initmenu.targetEl.style.display = "block";
	initmenu.menuContainer.current = initmenu;
	thismenu = tabMenu.item(0);
}

function txtTabClick() {
	currentmenu = this.menuContainer.current;
	if (currentmenu != this) {
		currentmenu.targetEl.style.display = "none";
		currentmenu.className = "";
	
		this.targetEl.style.display = "block";
		this.className = "on";
		this.menuContainer.current = this;
	}
	return false;
}


// 보이기
function initShow(id) {
  document.getElementById(id).style.display = "block";
}
// 감추기
function initHide(id) {
  document.getElementById(id).style.display = "none";
}
// altBox
function initAlt(id){
	var target = document.getElementById(id); 
	target.style.display = (target.style.display == 'block' ? 'none':'block');
}

/***************************************************************************************
******************************** ScrollControl *************************************
****************************************************************************************/
var ScrollControl	= function(objId,options){
	this.init(objId,options);
}
ScrollControl.prototype	= {
	stage : {},
	options : {},
	isover : false,
	freeze : false,
	course : 'top',
	itimes : 0,
	top : 0,

	init : function(objId,options){
		this.setOptions(options);
		this.setStage(objId);
		this.setTrueData();

		this.move();
	},
	setOptions : function(options){
		options.inteval	= options.inteval	|| 50;
		options.freeze	= options.freeze	|| 1000;
		options.height	= parseInt(options.height, 10)	|| 20;
		options.style	= options.style || 'scroll';
		options.line	= options.line || 1;
		options.stopline	= options.stopline || options.line;
		options.reverse	= options.reverse || '';
		options.debug	= options.debug || false;

		options.blockHeight	= options.height * options.line;
		options.stopHeight	= options.height * (options.stopline || options.line);


//		options.cMarginTop	= options.cMarginTop	|| (options.height/2) * 0.3;
		options.cMarginTop	= 0;
		options.cHeight		= options.height - options.cMarginTop;
		options.freeze		= (options.style == 'no-freeze') ? options.inteval : options.freeze;

		switch(options.style){
			case 'jump' :		options.style = options.style;	break;
			default :			options.style = 'scroll';	break;
		}


		this.course		= options.start || 'top';
		this.options	= options;
	},
	setTrueData : function(){
		var cObjs		= this.stage.childNodes;
		var cObjLen		= cObjs.length;
		var removes		= [];

		for(var i=0;i<cObjs.length;i++){
			if(!cObjs[i].tagName){
				removes.push(cObjs[i]);	//바로 삭제 시 데이터 꼬이는듯 하여 일단 킵함.
			}else{
				cObjs[i].style.margin		= "0";

				cObjs[i].style.marginTop	= this.options.cMarginTop;
				cObjs[i].style.height		= this.options.cHeight+'px';
			}
		}

		// 찾은 데이터를 삭제함.(FF의 경우 text 노드가 첨부됨.)
		for(var i=0;i<removes.length;i++){
			this.stage.removeChild(removes[i]);
		}

		if(!this.options.debug && cObjLen <= this.options.line ){
			var attachLen	= parseInt(this.options.line/cObjLen, 10);

			for(var i=0; i<attachLen; i++){
				for(var j=0; j<cObjLen; j++){
					this.stage.appendChild( cObjs[j].cloneNode(true) );
				}
			}
		}

	},
	setStage : function(objId){
		var This	= this;
		this.stage		= document.getElementById(objId);

		this.stage.style.height		= this.options.blockHeight+'px';
		this.stage.style.padding	= "0px";
		this.stage.style.margin		= "0px";

		if(!this.options.debug)
			this.stage.style.overflow	= "hidden";


		this.stage.onmouseover	= function(){This.isover=true;} 
		this.stage.onmouseout	= function(){This.isover=false;} 

		this.stage.scrollTop		= 0;	//파폭에서 리프래시 문제
	},
	setCourse : function(course){
		if(this.course != 'down' && course == 'down' && this.stage.scrollTop <= 0){
			this.changeChild();
			this.stage.scrollTop = this.options.height;
		}else if(course == 'top' && this.stage.scrollTop >= this.options.height){
			if(this.options.reverse != 'all'){
				this.changeChild(this.options.line);
				this.stage.scrollTop = this.stage.scrollTop - this.options.stopHeight;
			}
		}

		this.course	= course;
		if(this.itimes > 0){
			window.clearTimeout(this.itimes);
			this.move();
		}
	},
	changeChild : function(count){
		if(count == undefined){	count	= this.stage.childNodes.length - 1;}

		for(var i=0; i<count;i++ ){
			this.stage.appendChild( this.stage.childNodes[0] );	// 항상 첫번째것을 뒤로 이동
		}
	},
	actionTop : function(){
		if(this.options.style == 'jump'){
			this.changeChild(this.options.stopline);
			this.stage.scrollTop = 0;
			this.freeze			= true;
		}else{
			this.top++;
			this.stage.scrollTop++;

			if( this.stage.scrollTop >= this.options.height ){
				this.changeChild(1);
				this.stage.scrollTop = this.stage.scrollTop - this.options.height;

				//if문 안에 있는게 효율
				if( this.top >= this.options.stopHeight ){
					this.top			= 0;
					this.freeze			= true;
					if(this.options.reverse == 'top' || this.options.reverse == 'all')	this.setCourse("down");
				}
			}
		}
	},
	actionDown : function(){
		if(this.options.style == 'jump'){
			this.freeze				= true;
			for(var i=0; i<this.options.stopline;i++){
				this.changeChild();
			}
		}else{
			this.top--;
			this.stage.scrollTop--;

			if( this.stage.scrollTop <= 0 ){
				this.changeChild();
				this.stage.scrollTop = this.stage.scrollTop + this.options.height;

				//Math.abs 로 구할 수 있지만, Math함수가 무거운 관계로 음수 처리함.(if문 안에 있는게 효율)
				if( -(this.top) >= this.options.stopHeight ){
					for(var i=1; i<this.options.stopline;i++){
						this.changeChild();
					}

					this.top			= this.top + this.options.stopHeight;
					this.freeze			= true;
				}
			}
		}

		if(this.freeze){
			this.stage.scrollTop	= this.options.stopHeight;
			if(this.options.reverse == 'down' || this.options.reverse == 'all')	this.setCourse("top");
		}

	},
	move : function(){
		this.itimes	= 0;
		if(!this.isover){
			if(this.course == 'top')	this.actionTop();
			else						this.actionDown();
		}

		var This	= this;
		if(this.freeze){	this.itimes	=		window.setTimeout(function(){This.move()}, this.options.freeze); }
		else{				window.setTimeout(function(){This.move()}, this.options.inteval); }
		this.freeze	= false;
	}

}

/* parduct clinical images */
function checkBrowser(string) {
	var detect = navigator.userAgent.toLowerCase();
    place = detect.indexOf(string) + 1;
    thestring = string;
	return place;
}
function cnjRol(after) {
	if (checkBrowser('msie')){
		var objimg = document.getElementById("imgShow");
		objimg.filters.blendTrans.stop();
		objimg.filters.blendTrans.Apply(); 
		objimg.src=after; 
		objimg.filters.blendTrans.Play();
	}
	else{
		document.imgShow.src=after;
	} 
} 
var counter = 0 ;
function imgShow(n1){
	cnjRol(imgArray[counter]);
	counter++;
	if (counter >= n1) 
		counter = 0;
	rolling = window.setTimeout("imgShow("+n1+")", 2000) ;
}
function changeImg(n1,n2){
	document.imgShow.src=imgArray[n2];
	var listImg = document.getElementById("listImg"+n2);
	for (i = 0; i < n1; i++){
		document.getElementById("listImg"+i).className="";
	}
	listImg.className="on";
	clearTimeout(rolling);
}

//popup
function PopUpWindowOpen(surl, popupwidth, popupheight)
{
	Top = (window.screen.availHeight - popupheight) / 2;
	Left = (window.screen.availWidth - popupwidth) / 2;
	if (Top < 0) Top = 0;
	if (Left < 0) Left = 0;
	Future = "fullscreen=no,toolbar=no,location=no,directories=no,status=yes,menubar=no,scrollbars=no,left=" + Left + ",top=" + Top + ",width=" + popupwidth + ",height=" + popupheight;
	PopUpWindow = window.open(surl, "PopUpWindow", Future);
	PopUpWindow.focus();
}


function PopUpWindowOpenScroll(surl, popupwidth, popupheight)
{
	Top = (window.screen.availHeight - popupheight) / 2;
	Left = (window.screen.availWidth - popupwidth) / 2;
	if (Top < 0) Top = 0;
	if (Left < 0) Left = 0;
	Future = "fullscreen=no,toolbar=no,location=no,directories=no,status=yes,menubar=no,scrollbars=yes,left=" + Left + ",top=" + Top + ",width=" + popupwidth + ",height=" + popupheight;
	PopUpWindow = window.open(surl, "PopUpWindow", Future);
	PopUpWindow.focus();
}

function mapPosition(n) {
	document.getElementById("map").src = "../images/map/map" + n +".gif";
}
function mapList(n) {
	for(i=2;i<36;i++) {
		obj = document.getElementById("office"+i);
		if(obj != null) {
			if(n == i || n == 'all') {
				document.getElementById("office"+i).style.display = "block";
			} else {
				document.getElementById("office"+i).style.display = "none";
			}
		}
	}
}

