function fnTopMenuOnloadEvent(Event)
{
	var objSiteTopMenuDiv		= fnGetObject('site_top_menu');

	if(objSiteTopMenuDiv)
	{
		// 2차메뉴에 오버 이벤트 추가
		fnTopMenuDepth2OverEventAdjust();

		// 현재 활성화된 메뉴 찾기
		fnTopMenuThisPageMenuFind();
	}


/*
// 구 사이트 정보 가지고 올경우 이미지 주소 변경 처리
	var arrImages		= document.images;
	var strBuf		= '';
	for(var i=0; i<arrImages.length; i++)
	{
		if(!arrImages[i].complete)
		{
			arrImages[i].src	= arrImages[i].src.replace(document.domain, 'dy21.net');
		}
	}
*/
}


if(window.attachEvent)
{
	window.attachEvent('onload', fnTopMenuOnloadEvent);
}
else if(window.addEventListener)
{
	window.addEventListener('load', fnTopMenuOnloadEvent, false);
}







// 2차메뉴에 오버 이벤트 추가
var g_arrTopMenuDepth2ChildNodeObject		= new Array;
function fnTopMenuDepth2OverEventAdjust()
{
	var objSiteTopMenuDiv		= fnGetObject('site_top_menu');

	if(objSiteTopMenuDiv)
	{
		var arrTagA				= objSiteTopMenuDiv.getElementsByTagName("a");
		var arrMenuDepth2		= new Array;

		for(var i=0; i<arrTagA.length; i++)
		{
			var strId	 	= arrTagA[i].id ? arrTagA[i].id : '';

			if(strId != '')
			{
				if(strId.search(/topmenu_link_depth2_child[0-9]{1,}/gi) >= 0)
				{
					arrMenuDepth2[arrMenuDepth2.length]	= arrTagA[i];
				}
			}
		}

		var arrDiv		= objSiteTopMenuDiv.getElementsByTagName("div");
		var arrMenuDepth3		= new Array;

		for(var i=0; i<arrDiv.length; i++)
		{
			var strClassName	= arrDiv[i].className ? arrDiv[i].className : '';

			if(strClassName != '')
			{
				if(strClassName.search(/sublist_box_depth2/gi) >= 0)
				{
					arrMenuDepth3[arrMenuDepth3.length]	= arrDiv[i];
				}
			}
		}

		if(arrMenuDepth2.length > 0 && arrMenuDepth3.length > 0)
		{
			for(var i=0; i<arrMenuDepth2.length; i++)
			{
				var strId	 				= arrMenuDepth2[i].id ? arrMenuDepth2[i].id : '';
				var strChildNo			= strId.match(/topmenu_link_depth2_child[0-9]{1,}/gi);
				strChildNo				= strChildNo.toString().replace(/topmenu_link_depth2_child/gi, '');

				if(strChildNo != '')
				{
					var strSearchChildClassName	= '/sublist_box_depth2_child'+ strChildNo +'/gi';

					for(var j=0; j<arrMenuDepth3.length; j++)
					{
						var strChildClassName	= arrMenuDepth3[j].className ? arrMenuDepth3[j].className : '';

						if(strChildClassName.search(eval(strSearchChildClassName)) >= 0)
						{
							var dwIndex		= g_arrTopMenuDepth2ChildNodeObject.length;
							g_arrTopMenuDepth2ChildNodeObject[dwIndex]		= arrMenuDepth3[j];
							arrMenuDepth2[i].setAttribute('childnodediv', dwIndex);

							strChildClassName					+= ' hide';
							arrMenuDepth3[j].className	= strChildClassName;

							break;
						}
					}
				}

				fnAddEvent(arrMenuDepth2[i], 'onmouseover', fnTopMenuDepth2OnMouseOverEvent, 'function');
				fnAddEvent(arrMenuDepth2[i], 'onfocus', fnTopMenuDepth2OnMouseOverEvent, 'function');
				var arrInSpan		= arrMenuDepth2[i].getElementsByTagName('span');
				for(var j=0; j<arrInSpan.length; j++)
				{
					arrInSpan[j].onmouseover	= function (){ fnTopMenuDepth2EventProcess(arrMenuDepth2[i]); };
					//arrInSpan[j].onfocus	= function (){ fnTopMenuDepth2EventProcess(arrMenuDepth2[i]); };
				}
			}
		}
	}
}


var g_objTopMenuDepth2PreOnMouseOverEvent	= null;
function fnTopMenuDepth2OnMouseOverEvent(Event)
{
	Event		= Event ? Event : window.event;

	var objEventTarget	= Event.srcElement ? Event.srcElement : (Event.target ? Event.target : (Event.toElement ? Event.toElement : (Event.currentTarget ? Event.currentTarget : null)));

	while(1 == 1)
	{
		var strTagName	= objEventTarget.tagName ? objEventTarget.tagName.toLowerCase() : '';
		if(strTagName == 'a')
		{
			fnTopMenuDepth2EventProcess(objEventTarget);
			break;
		}
		else if(strTagName == 'span')
		{
			objEventTarget		= objEventTarget.parentNode;
		}
		else
		{
			break;
		}
	}
}


function fnTopMenuDepth2EventProcess(objThis)
{
	if(g_objTopMenuDepth2PreOnMouseOverEvent)
	{
		if(g_objTopMenuDepth2PreOnMouseOverEvent != objThis)
		{
			var strPreClassname	= g_objTopMenuDepth2PreOnMouseOverEvent.className ? g_objTopMenuDepth2PreOnMouseOverEvent.className : '';
			strPreClassname		= strPreClassname.search(/path/gi) >= 0 ? strPreClassname.replace(/path/gi, '') : strPreClassname;
			g_objTopMenuDepth2PreOnMouseOverEvent.className			= strPreClassname;

			var dwPreChildIndex		= g_objTopMenuDepth2PreOnMouseOverEvent.getAttribute('childnodediv');
			var objPreChild				= g_arrTopMenuDepth2ChildNodeObject[dwPreChildIndex];

			if(objPreChild)
			{
				var strPreChildClassName	= objPreChild.className ? objPreChild.className : '';
				strPreChildClassName			= strPreChildClassName.replace(/show/gi, 'hide');

				objPreChild.className		= strPreChildClassName;
			}
		}
	}

	if(objThis)
	{
		var strClassname	= objThis.className ? objThis.className : '';
		strClassname			= strClassname.search(/path/gi) >= 0 ? strClassname : strClassname + ' path';
		objThis.className			= strClassname;

		var dwChildIndex		= objThis.getAttribute('childnodediv');
		var objChild				= g_arrTopMenuDepth2ChildNodeObject[dwChildIndex];

		if(objChild)
		{
			var strChildClassName	= objChild.className ? objChild.className : '';
			strChildClassName			= strChildClassName.replace(/hide/gi, 'show');

			objChild.className		= strChildClassName;
		}

		g_objTopMenuDepth2PreOnMouseOverEvent		= objThis;
	}
}









// 현재 활성화된 메뉴 찾기
function fnTopMenuThisPageMenuFind()
{
	try
	{
		var strMenuCode		= g_strMenuCode ? g_strMenuCode : '';	
	}
	catch (e)
	{
		var strMenuCode		= '';
	}

	var objSiteTopMenuDiv		= fnGetObject('site_top_menu');
	if(objSiteTopMenuDiv && strMenuCode != '')
	{
		var objThisTopMenu	= null;
		var strSearchWord		= '/^topmenu_'+ strMenuCode +'$/i';
		var arrTagA				= objSiteTopMenuDiv.getElementsByTagName("a");
		for(var i=0; i<arrTagA.length; i++)
		{
			var strName		= arrTagA[i].name ? arrTagA[i].name : '';
			if(strName != '')
			{
				if(strName.search(eval(strSearchWord)) >= 0)
				{
					objThisTopMenu		= arrTagA[i];
					break;
				}
			}
		}

		if(objThisTopMenu)
		{
			fnTopMenuDepth2EventProcess(objThisTopMenu);
		}
	}
}