function MM_openBrWindow(theURL,winName,features) { //v2.0
  window.open(theURL,winName,features);
}

/* top navigation */
function initTopMenu(el,depth1) {
	topMenuOut(el.getElementsByTagName("img").item(0));
	if(el.id == "top-menu" + depth1) {
		topMenuOver(el.getElementsByTagName("img").item(0));
	}
}
function topMenuOver(img) {
	img.src = img.src.replace(".gif", "_on.gif");
}
function topMenuOut(img) {
	img.src = img.src.replace("_on.gif", ".gif");
}

function selectTopmenuByMenuId() {
	var depth1 = this.id.substring("top-menu-head".length,this.id.length);
	var menuId = "sub-menu" + depth1;		
	var selectDepth1 = "top-" + depth1 + "-1";
	var topnav = document.getElementById("lnb");
	if(!topnav) return;
	var topEl = topnav.getElementsByTagName("ul");
	for(i = 0 ; i < topEl.length ; i++){
		if(topEl[i].id.substring(0,12) == "top-sub-menu") {
			topEl[i].style.display = "none";
		}
	}
	var topEl2 = topnav.getElementsByTagName("li");
	for(i = 0 , seq = 1; i < topEl2.length ; i++){
		if(topEl2[i].id.substring(0,8) == "top-menu") {
			initTopMenu(topEl2[i],depth1);
		}
	}
	
	var nav = document.getElementById("top-" + menuId);
	if(!nav) return;
	nav.style.display = "block";
	menuEl = nav.getElementsByTagName("li");
	for(i = 0; i < menuEl.length; i++) {
		var imgEl = menuEl.item(i).getElementsByTagName("img")
		if(imgEl != null && imgEl.length>0) {
			imgEl.item(0).onmouseover = menuOver;
			imgEl.item(0).onmouseout = menuOut;
			imgEl.item(0).onfocus = menuOver;
			imgEl.item(0).onblur = menuOut;
		}
	}
}

function initTopmenuByMenuId(depth1, depth2, depth3, depth4, menuId) {
	var selectDepth1 = "top-" + depth1 + "-" + depth2;
	var selectDepth2 = "top-" + depth1 + "-" + depth2 + "-" + depth3;
	var selectDepth3 = "top-" + depth1 + "-" + depth2 + "-" + depth3 + "-" + depth4;
	var topnav = document.getElementById("lnb");
	if(!topnav) return;
	var topEl = topnav.getElementsByTagName("ul");
	for(var i = 0 ; i < topEl.length ; i++){
		if(topEl[i].id.substring(0,12) == "top-sub-menu") {
			topEl[i].style.display = "none";
		}
	}
	
	var topEl2 = topnav.getElementsByTagName("a");

	for(i = 0, seq = 0 ; i < topEl2.length ; i++){
		if(topEl2[i].id.substring(0,13) == "top-menu-head") {
			topEl2[i].onmouseover =  selectTopmenuByMenuId;
			topEl2[i].onfocus = selectTopmenuByMenuId;
			if ( topEl2[i].id.substring(13) == depth1) {
				topEl2[i].onmouseover();
			}
			seq++;
		}
	}
	
	var nav = document.getElementById("top-" + menuId);
	if(!nav) return;
	nav.style.display = "block";
	menuEl = nav.getElementsByTagName("li");
	for(i = 0; i < menuEl.length; i++) {
		var menuElItm = menuEl.item(i);
		var imgEl = menuElItm.getElementsByTagName("img");
		if(imgEl == null || imgEl.length == 0)  {
			var aEl = menuElItm.getElementsByTagName("a");
			var itm = aEl.item(0);
			if (menuElItm.id == selectDepth1 || menuElItm.id == selectDepth2  || menuElItm.id == selectDepth3  ) {
				itm.className = "on";
			}
		} else {
			var itm = imgEl.item(0);
			if (menuElItm.id == selectDepth1 || menuElItm.id == selectDepth2  || menuElItm.id == selectDepth3  ) {
				itm.src = itm.src.replace(".gif", "_on.gif");
				itm.onmouseover = null;
				itm.onmouseout = null;
				itm.onfocus = null;
				itm.onblur = null;
			}
			else {
				itm.onmouseover = menuOver;
				itm.onmouseout = menuOut;
				itm.onfocus = menuOver;
				itm.onblur = menuOut;
			}
		}
	}
}


/* side navigation */
function initSubmenuByMenuId(depth1, depth2, depth3,depth4, menuId) {
	selectDepth1 = "menu" + depth1 + "-" + depth2;
	selectDepth2 = "menu" + depth1 + "-" + depth2 + "-" + depth3;
	selectDepth3 = "menu" + depth1 + "-" + depth2 + "-" + depth3 + "-" + depth4;
	
	nav = document.getElementById(menuId);
	if(!nav) return;
	menuEl = nav.getElementsByTagName("li");	
	
	for(i = 0; i < menuEl.length; i++) {
		if (menuEl.item(i).id == selectDepth1 || menuEl.item(i).id == selectDepth2  || menuEl.item(i).id == selectDepth3  ) {
			var im = menuEl.item(i).getElementsByTagName("img");
			if(im && im.length > 0 ) {
				im.item(0).src = im.item(0).src.replace(".gif", "_on.gif");
			}
			else {
				var anc = menuEl.item(i).getElementsByTagName("a");
				if(anc && anc.length > 0) {
					anc.item(0).className = "on";
					if(menuEl.item(i).id == selectDepth3) {
						anc.item(0).className += " leaf";
					}
				}
			}
		} else {
			var im = menuEl.item(i).getElementsByTagName("img");
			if( im == null || im.length == 0)  continue;
			im.item(0).onmouseover = menuOver;
			im.item(0).onmouseout = menuOut;
			im.item(0).onfocus = menuOver;
			im.item(0).onblur = menuOut;
			if (menuEl.item(i).getElementsByTagName("ul").item(0)) {
				menuEl.item(i).getElementsByTagName("ul").item(0).style.display = "none";
			}
		}
	}	
	menuId = "menu" + depth1;
	//initTopmenuByMenuId(depth1,depth2,depth3,depth4,menuId);
}

/* roll over-out image */
function menuOver ()
{
	var s = this.src;
	s = s.replace("_on.gif", ".gif");
	this.src = s.replace(".gif", "_on.gif");
}

function menuOut ()
{
	this.src = this.src.replace("_on.gif", ".gif");
}

function initImgEffect(ImgEls, SelImg)
{
	MenuImg		= document.getElementById(ImgEls).getElementsByTagName("img");
	MenuImgLen	= MenuImg.length;

	for (i=0; i<MenuImgLen; i++)
	{
		MenuImg.item(i).onmouseover = menuOver;
		MenuImg.item(i).onmouseout = menuOut;
		
		if (i==SelImg)
		{
			MenuImg.item(i).onmouseover();
			MenuImg.item(i).onmouseover = null;
			MenuImg.item(i).onmouseout = null;
		}
	}
}

/* Initialize Follow Banner */
function initFollowBanner ()
{
	var div_id	= 'up';
	var self	= document.getElementById(div_id);
		//self.style.display = "block";

	var scroll_top	= (document.body.scrollTop)
					? parseInt(document.body.scrollTop, 10)
					: parseInt(document.documentElement.scrollTop, 10);
	
	
	var base	= document.getElementById("container");
	var max		= parseInt(base.clientHeight, 10);

	var t = self.style.top ? parseInt(self.style.top, 10) : 0;
	
	if (t!=scroll_top)
	{
		var g	= Math.ceil((t-scroll_top)/15);
			g	= g ? g : 0;
		
		if (max>scroll_top+parseInt(self.offsetHeight, 10))
		{
			self.style.top = (t-g) + "px";
		}
		else
		{
			self.style.top	= parseInt(max-self.offsetHeight, 10) + "px";
		}
	}

	setTimeout("initFollowBanner();", 5);
}



$(function()
{
	$("li.top-menu").hover(function()
	{
		$("div#lnb-layer-menus").show();
	},
	function()
	{
	});

	$("div#lnb-layer-menus").hover(function()
	{},
	function()
	{
		$(this).hide();
	});

	$("div.lnbSmenu > ul > li > a > img").mouseover(function()
	{
		var src	= $(this).attr('src');
			src	= src.replace('.jpg', '_on.jpg');

		$(this).attr('src', src);
	});
	$("div.lnbSmenu > ul > li > a > img").mouseout(function()
	{
		var src	= $(this).attr('src');
			src	= src.replace('_on.jpg', '.jpg');

		$(this).attr('src', src);
	});
});


/* 팝업창으로 띄우기 2010-10-27 */
function MM_openBrWindow(theURL,winName,features) { //v2.0
  window.open(theURL,winName,features);
}


function popupZone ()
{
	var root	= document.getElementById('popupzone');
	var delay	= 3000;
	var max		= 6;
	var items	= new Array();
	var num		= new Array();
	var selected	= 0;
	var interval	= null;

	if (root.nodeName!='DIV') { return false; }

	var body	= root.getElementsByTagName('ul')[0];

	if (typeof(body)!='object') { return false; }
	
	body.style.overflow	= 'hidden';
	body.style.position	= 'relative';
	
	for (var i in body.childNodes)
	{
		if (typeof(body.childNodes[i])=='object' && body.childNodes[i].nodeType==3 && body.childNodes[i].nodeName=='#text')
		{
			body.removeChild(body.childNodes[i]);
		}
	}

	var j	= 0;

	for (var i in body.childNodes)
	{
		if (typeof(body.childNodes[i])=='object' && body.childNodes[i].nodeType==1 && body.childNodes[i].nodeName=='LI')
		{
			if (j<max)
			{
				items.push(body.childNodes[i]);

				body.childNodes[i].onmouseover	= function ()
				{
					var j	= 1;

					for (var i in num)
					{
						num[i].className	= (i==this.i) ? 'popupzone-direct' + j + '-on' : 'popupzone-direct' + j;
						j++;
					}

					clearInterval(interval);
					interval	= null;
				};

				body.childNodes[i].onmouseout	= function ()
				{
					interval	= setInterval(function()
					{
						display();
					}
					, delay);

				};
				/*
				body.childNodes[i].getElementsByTagName('a')[0].i	= j;
				
				body.childNodes[i].getElementsByTagName('a')[0].onfocus	= function ()
				{
					var j	= 1;

					for (var i in num)
					{
						num[i].className	= (i==this.i) ? 'popupzone-direct' + j + '-on' : 'popupzone-direct' + j;
						j++;
					}

					clearInterval(interval);
					interval	= null;
				};

				body.childNodes[i].getElementsByTagName('a')[0].onblur	= function ()
				{
					interval	= setInterval(function()
					{
						display();
					}
					, delay);
				};
				*/

			}
			else
			{
				body.removeChild(body.childNodes[i]);
			}
			
			j++;
		}
	}

	max	= (items.length>=max) ? max : items.length;

	var popupzone_action	= document.createElement('div');
		popupzone_action.setAttribute('id', 'popupzone-function');

	var pause	= document.createElement('a');
		pause.setAttribute('href', '#' + root.getAttribute('id'));
		pause.setAttribute('title', '팝업존 콘텐츠 자동변환정지');
		pause.className	= 'pause';
		pause.onclick = function ()
		{
			clearInterval(interval);
			interval	= null;
			return false;
		};
		popupzone_action.appendChild(pause);
	
	var play	= document.createElement('a');
		play.setAttribute('href', '#' + root.getAttribute('id'));
		play.setAttribute('title', '팝업존 콘텐츠 자동변환시작');
		play.className	= 'play';
		play.onclick	= function ()
		{
			if (interval==null)
			{
				interval	= setInterval(function()
				{
					display();
				}
				, delay);

				display();
			}
			return false;
		};
		popupzone_action.appendChild(play);
	
		root.insertBefore(popupzone_action, body);
		//root.appendChild(popupzone_action);

	var direct	= document.createElement('div');
		direct.setAttribute('id', 'popupzone-direct');

		for (var i=0; i<max; i++)
		{
			var alt	= items[i].getElementsByTagName('img')[0].getAttribute('alt');
			var direct_item	= document.createElement('a');
				direct_item.setAttribute('href', '#' + root.getAttribute('id'));
				direct_item.setAttribute('title', alt);
				
				direct_item.className	= (i==0) ? 'popupzone-direct' + (i+1) + '-on' : 'popupzone-direct' + (i+1);
				direct_item.i	= i;
				direct_item.onclick = direct_item.onfocus	= function (event)
				{
					event	= event ? event : window.event;

					if (event.type=='click') { return false; }

					clearInterval(interval);
					interval	= null;

					var orderby	= new Array();
						orderby.push(items[this.i]);

					for (var i in items) { if (i!=this.i) { orderby.push(items[i]); } }
					
					var j	= 1;
					for (var i in orderby)
					{
						num[i].className	= (j==(this.i+1)) ? 'popupzone-direct' + j + '-on' : 'popupzone-direct' + j;
						body.appendChild(orderby[i]);
						j++;
					}

				};
				
				num.push(direct_item);
				direct.appendChild(direct_item);
		}

		root.insertBefore(direct, body);
		//root.appendChild(direct);

	var display	= function ()
	{
		if (body.childNodes.length<2 || !body.style.cssText)
		{
			clearInterval(interval);
			interval	= null;
			return false;
		}

		selected	= max<=(selected+1) ? 0 : selected+1;

		var j	= 1;
		for (var i in num)
		{
			num[i].className	= (i==selected) ? 'popupzone-direct' + j + '-on' : 'popupzone-direct' + j;
			j++;
		}

		body.appendChild(body.firstChild);
	};

	var interval	= setInterval(function()
	{
		if (pause==true) { return false;}
		display();
	}
	, delay);

}
