﻿


var dwSiteMenuCount			= 0;
var arrSiteMenu				= new Array;

function scSiteMenu(dwParentIdex, dwSeq, dwThread, bDepth, strName, strCode, strType, strTypeAdd, bUsed, bShow, strFilePath, strFileName)
{
	this._dwIndex			= -1;
	this._dwParentIdex		= dwParentIdex;
	this._dwSeq				= dwSeq;
	this._dwThread			= dwThread;
	this._bDepth			= bDepth;
	this._strName			= strName;
	this._strCode			= strCode;
	this._strType			= strType;
	this._strTypeAdd		= strTypeAdd;
	this._bUsed				= bUsed;
	this._bShow				= bShow;
	this._strFilePath		= strFilePath;
	this._strFileName		= strFileName;


	this._dwChildCount		= 0;
	this._arrChildren		= new Array;

	this.Initialize			= fnSiteMenu_Initialize;
}


function fnSiteMenu_Initialize()
{
	this._dwIndex		= dwSiteMenuCount;
	arrSiteMenu[dwSiteMenuCount]	= this;
	dwSiteMenuCount++;


//--------------
/*
var strBuf	= '';
for(var i=0; i<this._bDepth; i++)
	strBuf	+= '&nbsp;&nbsp;';

document.write(strBuf + this._strName +'['+ this._bDepth +']<br>');
*/
}







function CreateMenu(objParentNode, dwSeq, dwThread, bDepth, strName, strCode, strType, strTypeAdd, bUsed, bShow, strFilePath, strFileName)
{
	var dwParentIdex		= -1;
	if(objParentNode)
	{
		if(objParentNode._dwIndex)
			dwParentIdex	= objParentNode._dwIndex;
	}

	var objBufMenu			= new scSiteMenu(dwParentIdex, dwSeq, dwThread, bDepth, strName, strCode, strType, strTypeAdd, bUsed, bShow, strFilePath, strFileName);
	objBufMenu.Initialize();

	return objBufMenu;
}

function AddChild(objParentNode, objChildNode)
{
	if(objParentNode)
	{
		if(objChildNode)
		{
			objParentNode._arrChildren[objParentNode._dwChildCount]	= objChildNode;
			objParentNode._dwChildCount++;
		}
	}

	return objChildNode;
}

var g_dwMenuCount		= 0;
function fnPrintMenu()
{

	var strMenuList		= g_strRootMainPrintMenuList;

	if(!objMenu1)
		return;

	if(strMenuList != '')
	{
		var arrMenuList	= strMenuList.split(',');

		for(var i=0; i<arrMenuList.length; i++)
		{
			arrMenuList[i]	= arrMenuList[i].split('|');
		}
	}
	else
		return;

	var arrPintListIndex			= new Array;
	var arrPintChildListBool	= new Array;
	var dwPrintCount		= 0;
	var strName				= '';
	var bDepth					= -1;

	for(var i=0; i<dwSiteMenuCount; i++)
	{
		strName	= arrSiteMenu[i]._strName;
		bDepth	= arrSiteMenu[i]._bDepth;

		for(var j=0; j<arrMenuList.length; j++)
		{
			if(strName == arrMenuList[j][0] && bDepth == parseInt(arrMenuList[j][1], 10))
			{
				arrPintListIndex[dwPrintCount]			= i;
				arrPintChildListBool[dwPrintCount]	= parseInt(arrMenuList[j][2], 10) == 0 ? false : true;
				dwPrintCount++;
				break;
			}
		}
	}

	g_dwMenuCount	= arrPintListIndex.length;
//------------------------------------------------------------------
	var dwMenuIndex			= -1;
	var strPrintSource		= '';

	strPrintSource	+= '	<ul class="site_topmenu_dropdown">\n';

	for(var i=0; i<arrPintListIndex.length; i++)
	{
		dwMenuIndex		= arrPintListIndex[i];

		if(arrSiteMenu[dwMenuIndex]._bUsed == 1 && arrSiteMenu[dwMenuIndex]._bShow == 1)
		{
			strPrintSource	+= '		<li'+ (i==0 ? ' class="first-child"' : (i==(arrPintListIndex.length - 1) ? ' class="last-child"' : '')) +'>\n';
			strPrintSource	+= '			<span class="menu_title" id="menu_top_'+ i +'"><a href="javascript:SiteLink('+ arrSiteMenu[dwMenuIndex]._dwIndex +')" title="'+ arrSiteMenu[dwMenuIndex]._strName +'"><d class="left"><span class="right">'+ arrSiteMenu[dwMenuIndex]._strName +'</span></span></a></span>\n';
//			strPrintSource	+= '			<span class="menu_title" id="menu_top_'+ i +'"><a href="javascript:SiteLink('+ arrSiteMenu[dwMenuIndex]._dwIndex +')" title="'+ arrSiteMenu[dwMenuIndex]._strName +'">'+ arrSiteMenu[dwMenuIndex]._strName +'</a></span>\n';

			if(arrSiteMenu[dwMenuIndex]._dwChildCount > 0 && arrPintChildListBool[i])
			{
				strPrintSource	+= '			<dl class="submenu'+ i +' topmenu_dropdown menu_sub_hide" id="menu_sub_'+ i +'">\n';
				
				for(var j=0; j<arrSiteMenu[dwMenuIndex]._dwChildCount; j++)
				{
					if(arrSiteMenu[dwMenuIndex]._arrChildren[j]._bUsed == 1 && arrSiteMenu[dwMenuIndex]._arrChildren[j]._bShow == 1)
					{
//						strPrintSource	+= '				<dd id="topmenu_sub_'+ arrSiteMenu[dwMenuIndex]._dwIndex +'"'+ (j==0 ? ' class="first-child"' : (j==(arrSiteMenu[dwMenuIndex]._dwChildCount - 1) ? ' class="last-child"' : '')) +'><a href="javascript:SiteLink('+ arrSiteMenu[dwMenuIndex]._arrChildren[j]._dwIndex +')" title="'+ arrSiteMenu[dwMenuIndex]._arrChildren[j]._strName +'"><span class="left"><span class="right">'+ arrSiteMenu[dwMenuIndex]._arrChildren[j]._strName +'</span></span></a></dd>\n';
						strPrintSource	+= '				<dd id="topmenu_sub_'+ arrSiteMenu[dwMenuIndex]._dwIndex +'"'+ (j==0 ? ' class="first-child"' : (j==(arrSiteMenu[dwMenuIndex]._dwChildCount - 1) ? ' class="last-child"' : '')) +'><a href="javascript:SiteLink('+ arrSiteMenu[dwMenuIndex]._arrChildren[j]._dwIndex +')" title="'+ arrSiteMenu[dwMenuIndex]._arrChildren[j]._strName +'">'+ arrSiteMenu[dwMenuIndex]._arrChildren[j]._strName +'</a></dd>\n';
//						strPrintSource	+= '				<dd id="topmenu_sub_'+ arrSiteMenu[dwMenuIndex]._dwIndex +'"'+ (j==0 ? ' class="first-child"' : (j==(arrSiteMenu[dwMenuIndex]._dwChildCount - 1) ? ' class="last-child"' : '')) +'><a href="">1234</a></dd>\n';
					}
				}

				strPrintSource	+= '			</dl>\n';
			}

			strPrintSource	+= '		</li>\n';
		}
	}

	strPrintSource	+= '	</ul>\n';

	var objTarget	= fnGetObject('site_topmenu');
	if(objTarget)
		objTarget.innerHTML		= strPrintSource;

	setTimeout(function (){ fnSettingTopMenu(); }, 300);
}



var g_dwSettingTopMenuCount		= 1;
function fnSettingTopMenu()
{
	var objTopMenu		= fnGetObject('site_topmenu');

	if(objTopMenu == null)
	{
		if(g_dwSettingTopMenuCount < 10)
		{
			setTimeout(function (){ fnSettingTopMenu(); }, 300);
			g_dwSettingTopMenuCount++;
		}
		else
		{
			alert('최상위 메뉴가 활성화가 되지 않았습니다.');
		}
		return;
	}

	for(var i=0; i<g_dwMenuCount; i++)
	{
		var objMenu		= fnGetObject('menu_top_'+ i);

		if(objMenu)
		{
			//objMenu.onmouseover		= function (){ fnTopMenuMouseOver(i); };
			//objMenu.onmouseout		= function (){ fnTopMenuMouseOut(i); }
			objMenu.onmouseover		= fnTopMenuMouseOver;
			objMenu.onmouseout		= fnTopMenuMouseOut;

			objMenu.show			= fnTopMenuMouseOver;
		}
	}
}

var g_dwPreMenuIdx		= -1;
function fnTopMenuMouseOver()
{
	var objMenu				= arguments.length > 0 ? (arguments[0].id ? arguments[0] : this ) : this;

	if(!objMenu)
		return;
//	var objMenu			= this;
	var dwMenuIdx		= parseInt(objMenu.id.replace(/menu_top_/i, ''), 10);
	var objPreMenu		= null;

	var objSubMenu		= fnGetObject('menu_sub_'+ dwMenuIdx);
	var objPreSubMenu	= null;

	if(g_dwPreMenuIdx >= 0)
	{
		objPreMenu		= fnGetObject('menu_top_'+ g_dwPreMenuIdx);
		objPreSubMenu	= fnGetObject('menu_sub_'+ g_dwPreMenuIdx);
	}

	if(dwMenuIdx != g_dwPreMenuIdx)
	{
		var strClassName		= '';
		if(objMenu != null)
		{
			strClassName		= objMenu.className;

			if(strClassName.search(/menu_button_over/gi) < 0)
			{
				if(strClassName.search(/menu_button_default/gi) >= 0)
				{
					strClassName	= strClassName.replace(/menu_button_default/gi, 'menu_button_over');
				}
				else
				{
					strClassName	+= ' menu_button_over'
				}
			}
			else
			{
				if(strClassName.search(/menu_button_default/gi) >= 0)
				{
					strClassName	= strClassName.replace(/menu_button_default/gi, '');
				}
			}

			objMenu.className	= strClassName;
		}

		if(objPreMenu != null)
		{
			strClassName		= objPreMenu.className;

			if(strClassName.search(/menu_button_default/gi) < 0)
			{
				if(strClassName.search(/menu_button_over/gi) >= 0)
				{
					strClassName	= strClassName.replace(/menu_button_over/gi, 'menu_button_default');
				}
				else
				{
					strClassName	+= ' menu_button_default'
				}
			}
			else
			{
				if(strClassName.search(/menu_button_over/gi) >= 0)
				{
					strClassName	= strClassName.replace(/menu_button_over/gi, '');
				}
			}

			objPreMenu.className	= strClassName;
		}

		if(objSubMenu != null)
		{
			strClassName		= objSubMenu.className;

			if(strClassName.search(/menu_sub_show/gi) < 0)
			{
				if(strClassName.search(/menu_sub_hide/gi) >= 0)
				{
					strClassName	= strClassName.replace(/menu_sub_hide/gi, 'menu_sub_show');
				}
				else
				{
					strClassName	+= ' menu_sub_show'
				}
			}
			else
			{
				if(strClassName.search(/menu_sub_hide/gi) >= 0)
				{
					strClassName	= strClassName.replace(/menu_sub_hide/gi, '');
				}
			}

			objSubMenu.className	= strClassName;
		}

		if(objPreSubMenu != null)
		{
			strClassName		= objPreSubMenu.className;

			if(strClassName.search(/menu_sub_hide/gi) < 0)
			{
				if(strClassName.search(/menu_sub_show/gi) >= 0)
				{
					strClassName	= strClassName.replace(/menu_sub_show/gi, 'menu_sub_hide');
				}
				else
				{
					strClassName	+= ' menu_sub_hide'
				}
			}
			else
			{
				if(strClassName.search(/menu_sub_show/gi) >= 0)
				{
					strClassName	= strClassName.replace(/menu_sub_show/gi, '');
				}
			}

			objPreSubMenu.className	= strClassName;
		}

		g_dwPreMenuIdx	= dwMenuIdx;
	}
}

function fnTopMenuMouseOut(dwMenuIdx)
{
}


// 상단 메뉴 이전 메뉴로 활성화 처리
function fnTopMenuOut()
{
	blsTopmenuStatus	= false;

	setTimeout(function (){ fnTopMenuOut_Proc(); }, 1500);
}

function fnTopMenuOut_Proc()
{
	if(blsTopmenuStatus)
		return;

	try
	{
		var dwShowMenu	= g_dwShowMenuIndex;	
	}
	catch (e)
	{
		var dwShowMenu	= -1;
	}

	var objMenu		= fnGetObject('menu_top_'+ (dwShowMenu - 1));
			
	if(objMenu)
	{
		fnTopMenuMouseOver(objMenu);
	}
}

function fnTopMenuOver()
{
	blsTopmenuStatus	= true;
}



function fnFamilySiteShowHide()
{
	var objFamilysite		= fnGetObject('familysitebox');
	
	if(objFamilysite != null)
	{
		var strClass		= objFamilysite.className;

		if(strClass.search(/hide/) >= 0)
		{
			strClass		= strClass.replace(/hide/, 'show');
		}
		else if(strClass.search(/show/) >= 0)
		{
			strClass		= strClass.replace(/show/, 'hide');
		}
		else
		{
			strClass		= strClass + ' show';
		}

		objFamilysite.className		= strClass;
	}
}