// floating menu
// 2006.03.13, CSH,


// to store all the menu items
var menu_garrMenuItem = new Array();

// browser version
var menu_browser_ie6up = null;
var menu_browser_ie55up = null;

// const
var menu_posUpperLeft = 1;
var menu_posUpperCenter = 2;
var menu_posUpperRight = 3;
var menu_posMiddleLeft = 4;
var menu_posMiddleCenter = 5;
var menu_posMiddleRight = 6;
var menu_posBottomLeft = 7;
var menu_posBottomCenter = 8;
var menu_posBottomRight = 9;



/////////////////////////////////////////
// Constructors
/////////////////////////////////////////

function menu_FloatMenu(arrActions, nShowMethod, sCreateHTML, nFading, placeDocument, selfWindowName, eventWindowName )
{
	// global event handler
	if ( placeDocument )
	{
		//placeDocument.detachEvent("onclick",menu_hideAllMenu);
		//placeDocument.attachEvent("onclick",menu_hideAllMenu);
		//document.detachEvent("onclick",menu_hideAllMenu);
		//document.attachEvent("onclick",menu_hideAllMenu);
	}
	else
	{
		//document.detachEvent("onclick",menu_hideAllMenu);
		//document.attachEvent("onclick",menu_hideAllMenu);
		removeEvent("onclick",menu_hideAllMenu);
		addEvent("onclick",menu_hideAllMenu);
	}

	// show method, relative to the point mouse clicked
	// 1=upper left, 2=upper middle, 3=upper right
	// 4=mid left, 5=center, 6=mid right
	// 7=lower left, 8=lower middle, 9=lower right
	this.objectName = "FloatMenu";

	this.nShowMethod = (nShowMethod) ? nShowMethod : 9;

	// points parent menu item, that is set when "addSubMenuById" called
	this.oParentMenuItem = null;

	// to store related avItem (only in root menu)
	this.oAvItem = null;

	// milli-second of fade out
	this.nFading = nFading ? nFading : 0.3;


	// document in which menu display dhtml object will be created
	this.placeDocument = placeDocument;
	// window name in which menu_FloatMenu object is created, to provide an access from placeDocument
	// for example) "self", iframe name
	this.selfWinodwName = ( selfWindowName == null ) ? "self" : selfWindowName;
	// window name in which menu display dhtml object's events occur
	this.eventWindowName = ( eventWindowName == null ) ? "self" : eventWindowName;

	// dhtml object in which menu display will be shown
	this.oMainMenu = null;

	// menu items
	this.arrActions = arrActions;

	// make html layout, use javascript statements for value
	this.defaultCreateHTML = sCreateHTML;

	// show
	this.updateShowHTML = menu_updateShowHTML;


	this.showMenu = menu_showMenu;
	this.hideMenu = menu_hideMenu;
	this.keepShow = menu_keepShow;
	this.bShowing = false;

	this.timerHideAll = null;

	this.gIndex = menu_registerMenuItem(this);

	// find action
	this.findAction = menu_findAction;

	this.addSubMenuById = menu_addSubMenuById;


	// extended information
	this.extInfo = null;

	// create dhtml object and shows it after document's readyState changes to "complete"
	menu_safeCreateMenu(this.gIndex);

	// browser's version check
	if ( menu_browser_ie55up == null )
		menu_checkBrowser();

}


function menu_safeCreateMenu(nIndex)
{
	var menu = menu_getMenuItemByIndex(nIndex);
	if ( menu == null )
		return;

	if ( typeof(this.placeDocument)=="object" && this.placeDocument ) {
		//if ( this.placeDocument.readyState == "complete") {
		if ( true ) {
			menu_safeCreateMenuObject(nIndex);
			menu_safeCreateMenuHTML(nIndex);
		} else {
			setTimeout("menu_safeCreateMenu(" + nIndex + ");",500);
		}
	} else {
		//if ( document.readyState == "complete") {
		if ( true ) {
			menu_safeCreateMenuObject(nIndex);
			menu_safeCreateMenuHTML(nIndex);
		} else {
			setTimeout("menu_safeCreateMenu(" + nIndex + ");",500);
		}
	}
}

function menu_safeCreateMenuObject(nIndex) {
	var menu = menu_getMenuItemByIndex(nIndex);
	if ( menu==null)
		return;

	var o;
	if ( menu.placeDocument ) {
		o = menu.placeDocument.createElement("<div hgobject='menu' style='background-color:white;'>");
		menu.placeDocument.body.appendChild(o);
	} else {
		//o = document.createElement("<div hgobject='menu' style='background-color:white;'>");
		o = document.createElement("div");
		o.hgobject = "menu";
		o.style.backgroundColor = "white";
		document.body.appendChild(o);
	}
	menu.oMainMenu = o;
}


function menu_safeCreateMenuHTML(nIndex) {
	var menu = menu_getMenuItemByIndex(nIndex);
	if ( menu==null)
		return;

	//if ( typeof(menu.oMainMenu) == "object" && menu.oMainMenu && (menu.oMainMenu.readyState=="complete") ) {
	if ( typeof(menu.oMainMenu) == "object" && menu.oMainMenu ) {
		if ( menu.defaultCreateHTML ) {
			var func = eval(menu.defaultCreateHTML);
			func(menu);
		} else {
			menu_createDefaultLayout(menu);
		}
	} else {
		setTimeout("menu_safeCreateMenuHTML(" + nIndex + ");",500);
	}
}

function menu_updateShowHTML(x,y) {
	menu_safeCreateMenuHTML(this.gIndex);
	menu_safeShow(this.gIndex,x,y);
}

function menu_safeShow(nIndex,x,y) {
	var menu = menu_getMenuItemByIndex(nIndex);
	if ( menu==null)
		return;

	//if ( typeof(menu.oMainMenu) == "object" && menu.oMainMenu && (menu.oMainMenu.readyState=="complete") ) {
	if ( typeof(menu.oMainMenu)=="object" && menu.oMainMenu ) {
		menu.showMenu(x,y);
	} else {
		setTimeout("menu_safeShow(" + nIndex + "," + x + "," + y + ");",500);
	}
}

// find action
function menu_findAction(id) {
	if ( this.arrActions == null ) return null;

	for ( var i = 0 ; i < this.arrActions.length ; i++ ) {
		if ( this.arrActions[i].id == id ) {
			return this.arrActions[i];
		}
	}
	return null;
}

// register instance of menuItem
function menu_registerMenuItem(menuItem)
{
	menu_garrMenuItem[menu_garrMenuItem.length] = menuItem;
	return (menu_garrMenuItem.length-1);
}

// helper function
function menu_getMenuItem(oMainMenu)
{
	var menuItem;
	for ( var i = 0 ; i < menu_garrMenuItem.length ; i++ )
	{
		menuItem = menu_garrMenuItem[i];
		if (menuItem.oMainMenu == oMainMenu)
			return (menuItem);
	}
	return null;
}

function menu_getMenuItemByIndex(n)
{
	for ( var i = 0 ; i < menu_garrMenuItem.length ; i++ )
	{
		if (menu_garrMenuItem[i].gIndex == n)
			return (menu_garrMenuItem[i]);
	}
	return null;

}



// Constructor for Items in the menu

function menu_Action(id, sType, sTitle, sOnClick, bExpand, oSubMenuItem, bEnable, bSelected, urlBulletImgTag, urlHoverBulletImgTag, urlBarImg, urlExpandImgTag, urlDisabledExpandImgTag, styleTDDefault, styleTDHover, styleTDSelected, styleTDDisabled, styleTRDefault, styleTRHover, styleTRSelected, styleTRDisabled )
{
	// unique id
	this.id = id;

	// sType: "menu"|"bar"
	this.type = sType;
	this.title = sTitle;

	// call back function when clicked, note this is name !!
	this.onclick = sOnClick;

	this.expand = (bExpand != null) ? bExpand : false;
	this.oSubMenuItem = oSubMenuItem;

	this.enabled = (bEnable != null) ? bEnable : true;

	this.selected = (bSelected != null) ? bSelected : false;

	this.urlBulletImgTag = urlBulletImgTag ? urlBulletImgTag : "<img src=http://images.hangame.com/nhn/hangame/avatar/menu/drop_bullet.gif width=3 height=3 align=absmiddle>";
	this.urlHoverBulletImgTag = urlHoverBulletImgTag ? urlHoverBulletImgTag : this.urlBulletImgTag;
	this.urlBarImg = (urlBarImg) ? urlBarImg : "http://images.ijjimax.com/v2/common/popup/line_shortcut.gif";
	//this.urlExpandImgTag = (urlExpandImgTag) ? urlExpandImgTag : "<img src='http://images.hangame.com/nhn/hangame/ps/images/bubble_arrow.gif' width='4' height='7'>";
	this.urlExpandImgTag = (urlExpandImgTag) ? urlExpandImgTag : "<img src='http://images.ijjimax.com/v2/common/bu_arw07.gif' width='3' height='5'>";

	this.urlDisabledExpandImgTag = (urlDisabledExpandImgTag) ? urlDisabledExpandImgTag : urlExpandImgTag;

	this.styleTDDefault = (styleTDDefault != null) ? styleTDDefault : "font:normal 9px Verdana; color:#666666; cursor:pointer; padding:0px 0px 0px 7px;";
	this.styleTDHover = (styleTDHover != null) ? styleTDHover : "font:normal 9px Verdana; color:#333333; cursor:pointer; padding:0px 0px 0px 7px;";
	this.styleTDSelected = styleTDSelected;
	this.styleTDDisabled = (styleTDDisabled != null) ? styleTDDisabled : "font:normal 9px Verdana; color:gray; cursor:pointer; padding:0px 0px 0px 7px;";

	this.styleTRDefault = (styleTRDefault != null) ? styleTRDefault : "background-color:transparent;";
	this.styleTRHover = (styleTRHover != null) ? styleTRHover : "background-color:#FFEDB5;";
	this.styleTRSelected = styleTRSelected;
	this.styleTRDDisabled = (styleTRDisabled != null) ? styleDisabled : "background-color:transparent;";

}


function menu_addSubMenuById(id, oSubMenuItem) {
	if ( this.arrActions ) {
		var action = this.findAction(id);
		if ( action != null ) {
			action.bExpand = true;
			action.oSubMenuItem = oSubMenuItem;
		}
		oSubMenuItem.oParentMenuItem = this;
	}
}


// basic functions

function menu_getEventWindow(obj)
{
	return obj.ownerDocument.parentWindow;
}



function menu_showSubMenu(e,sSrcWindowName,oTD,nIndex)
{
	var menuItem;
	var oElem;

	/*
	if ( sSrcWindowName )
	{
		if ( sSrcWindowName == "parent" )
			oElem = parent.event.srcElement; //for speed
		else
			oElem = eval(sSrcWindowName).event.srcElement;
	}
	else
		oElem = event.srcElement;
	*/
	oElem = e.srcElement;

	while ( oElem )
	{
		if ( oElem.hgobject == "menu" )
			menuItem = menu_getMenuItem(oElem);
		oElem = oElem.parentElement;
	}

	if ( menuItem )
	{
		var t = oTD.offsetTop;
		var l = oTD.offsetLeft;
		var oSubMenuItem = menuItem.arrActions[nIndex].oSubMenuItem;

		if ( oSubMenuItem )
		{
			var pos = menu_getSubMenuPos(oSubMenuItem,oTD);
			x = pos[0];
			y = pos[1];
			oSubMenuItem.showMenu(x,y);
		}
		else
			menu_hideAllSubMenus(e,sSrcWindowName,oTD);
	}
}

function menu_hideAllSubMenus(e,sSrcWindowName, oTD)
{
	var menuItem;

	var oElem;
	/*
	if ( sSrcWindowName )
	{
		if ( sSrcWindowName == "parent" )
			oElem = parent.event.srcElement; //for speed
		else
			oElem = eval(sSrcWindowName).event.srcElement;
	}
	else
		oElem = event.srcElement;
	*/
	oElem = e.srcElement;

	while ( oElem )
	{
		if ( oElem.hgobject == "menu" )
			menuItem = menu_getMenuItem(oElem);
		oElem = oElem.parentElement;
	}

	if ( menuItem )
	{
		for ( var i = 0 ; i < menuItem.arrActions.length; i++ )
			if ( menuItem.arrActions[i].expand && menuItem.arrActions[i].oSubMenuItem )
				menuItem.arrActions[i].oSubMenuItem.hideMenu(true, false);
	}
}


function menu_getSubMenuPos(subMenuItem,oTD)
{
	var pos = new Array();

	var x = oTD.offsetLeft;
	var y = oTD.offsetTop;
	var w = oTD.offsetWidth;
	var h = oTD.offsetHeight;

	var p = oTD.parentElement;

	var xSubMenuMargin = 5;

	while ( p )
	{
		if ( oTD.tagName == "TD" && p.tagName != "TR" )
		{
			x += p.offsetLeft;
			y += p.offsetTop;
		}

		if ( p.hgobject == "menu" )
		{
			pos[2] = x;
			pos[3] = y;
			pos[4] = w;
			pos[5] = h;
			pos[6] = p.offsetLeft;
			pos[7] = p.offsetTop;
			pos[8] = p.offsetWidth;
			pos[9] = p.offsetHeight;

			var n = subMenuItem.nShowMethod;

			if ( n==1 || n==4 || n==7 )
				pos[0] = pos[6] - subMenuItem.oMainMenu.offsetWidth - xSubMenuMargin;

			if ( n==3 || n==6 || n==9 )
				pos[0] = pos[6] + pos[8] + xSubMenuMargin;

			if ( n==2 || n==5 || n==8 )
				pos[0] = pos[6] + pos[8]; // not properly defined

			if ( n==1 || n==2 || n==3 )
				pos[1] = y + h - subMenuItem.oMainMenu.offsetHeight;

			if ( n==4 || n==5 || n==6 )
				pos[1] = y + h/2 - subMenuItem.oMainMenu.offsetHeight/2;

			if ( n==7 || n==8 || n==9 )
				pos[1] = y;

			return pos;
		}
		p = p.parentElement;
	}

	return pos;

}


function menu_showMenu(x,y)
{
	var o = this.oMainMenu;

	// clear existing timer
	this.keepShow();

	if ( typeof(o.style.pixelLeft)=="undefined" ) {
		o.style.left = menu_calcX(this,x) + "px";
		o.style.top = menu_calcY(this,y) + "px";
	} else {
		o.style.pixelLeft = menu_calcX(this,x);
		o.style.pixelTop = menu_calcY(this,y);
	}

	if ( menu_browser_ie55up && this.nFading > 0 ) {
		o.filters[0].Apply();
		o.style.visibility = "visible";
		o.filters[0].Play();

	} else {
		o.style.visibility = "visible";
	}

	this.bShowing = true;
}

function menu_calcX(menuItem,eventX)
{
	var margin = 5;
	var n = menuItem.nShowMethod;

	if ( menuItem.oParentMenuItem )
		return eventX;

	if ( n==1 || n==4 || n==7 ) {
		if (eventX-menuItem.oMainMenu.offsetWidth < margin) {
			return eventX;
		}
		return (eventX-menuItem.oMainMenu.offsetWidth);
	}

	if ( n==2 || n==5 || n==8 ) {
		if (eventX-menuItem.oMainMenu.offsetWidth/2 < margin) {
			return eventX;
		} else if ( eventX-menuItem.oMainMenu.offsetWidth/2 > document.body.clientWidth - margin ) {
			return (eventX-menuItem.oMainMenu.offsetWidth);
		}
		return (eventX-menuItem.oMainMenu.offsetWidth/2);
	}

	if ( n==3 || n==6 || n==9 ) {
		if ( eventX + menuItem.oMainMenu.offsetWidth > document.body.clientWidth - margin ) {
			return eventX-menuItem.oMainMenu.offsetWidth;
		}
		return (eventX);
	}

}

function menu_calcY(menuItem,eventY)
{
	var margin = 5;
	var n = menuItem.nShowMethod;

	if ( menuItem.oParentMenuItem )
		return eventY;

	if ( n==1 || n==2 || n == 3 ) {
		if ( eventY - menuItem.oMainMenu.offsetHeight < margin ) {
			return eventY;
		}
		return (eventY-menuItem.oMainMenu.offsetHeight);
	}

	if ( n==4 || n==5 || n == 6 ) {
		if (eventY-menuItem.oMainMenu.offsetHeight/2 < margin ) {
			return eventY;
		} else if (eventY-menuItem.oMainMenu.offsetHeight/2 > document.body.clientHeight - margin ) {
			return (eventY-menuItem.oMainMenu.offsetHeight);
		}
		return (eventY-menuItem.oMainMenu.offsetHeight/2);

	}

	if ( n==7 || n==8 || n == 9 ) {
		if ( eventY + menuItem.oMainMenu.offsetHeight > document.body.clientHeight - margin ) {
			return (eventY-menuItem.oMainMenu.offsetHeight);
		}
		return (eventY);
	}

}


function menu_hideMenu(bFading,bCascade)
{
	var menuItem = this;

	while ( menuItem )
	{
		if ( !menuItem.timerHideAll && bFading )
			menuItem.timerHideAll = setTimeout("menu_hideMenuReal(" + menuItem.gIndex + ");",500);
		else
			menu_hideMenuRealImmediately(menuItem);

		if ( bCascade )
			menuItem = menuItem.oParentMenuItem;
		else
			menuItem = null;
	}

	if ( bCascade )
	{
		var arrActions = this.arrActions;

		for ( var i = 0 ; i < arrActions.length ; i++ )
		{
			if ( arrActions[i].expand && arrActions[i].oSubMenuItem )
				arrActions[i].oSubMenuItem.hideMenu(bFading,false);
		}
	}

}

function menu_hideMenuReal(menuItemIndex)
{
	var menuItem = menu_getMenuItemByIndex(menuItemIndex);

	if ( menuItem && menuItem.oMainMenu )
	{
		menuItem.bShowing = false;

		if ( menuItem.timerHideAll )
			clearTimeout(menuItem.timerHideAll);
		menuItem.timerHideAll = null;

		if ( menu_browser_ie55up && menuItem.nFading > 0 )
		{
			menuItem.oMainMenu.filters[0].Apply();
			menuItem.oMainMenu.style.visibility = "hidden";
			menuItem.oMainMenu.filters[0].Play();
		}
		else
			menuItem.oMainMenu.style.visibility = "hidden";
	}
}

function menu_hideMenuRealImmediately(menuItem)
{
	if ( menuItem && menuItem.oMainMenu )
		menuItem.oMainMenu.style.visibility = "hidden";
}

function menu_keepShow()
{
	var menuItem = this;

	while ( menuItem )
	{
		if ( menuItem.timerHideAll )
		{
			clearTimeout(menuItem.timerHideAll);
			menuItem.timerHideAll = null;
		}
		menuItem = menuItem.oParentMenuItem;
	}
}

function menu_hideAllMenu()
{
	var menuItem;
	for ( var i = 0 ; i < menu_garrMenuItem.length ; i++ )
		menu_hideMenuRealImmediately(menu_garrMenuItem[i]);
}


// event handler
function menu_ShowArea_OnMouseLeave()
{
	var menuItem;
	var oElem;

	if ( this.eventWindowName )
	{
		if ( this.eventWindowName == "parent" )
			oElem = parent.event.srcElement; //for speed
		else
			oElem = eval(this.eventWindowName).event.srcElement;
	}
	else
		oElem = event.srcElement;

	if ( oElem.hgobject == "menu" )
		menuItem = menu_getMenuItem(oElem);

	menuItem = menu_getMenuItem(this);

	if ( menuItem )
		menuItem.hideMenu(true,true);
}



function menu_ShowArea_OnMouseEnter()
{
	var menuItem;
	var oElem;

	if ( this.eventWindowName )
	{
		if ( this.eventWindowName == "parent" )
			oElem = parent.event.srcElement; //for speed
		else
			oElem = eval(this.eventWindowName).event.srcElement;
	}
	else
		oElem = event.srcElement;

	if ( oElem.hgobject == "menu" )
		menuItem = menu_getMenuItem(oElem);

	menuItem = menu_getMenuItem(this);

	if ( menuItem )
		menuItem.keepShow();
}


function menu_clickDummy(eventWindowName)
{
	if ( eventWindowName )
		eval(eventWindowName).event.cancelBubble = true;
	else
		event.cancelBubble = true;
}


function menu_checkBrowser()
{
	var agt=navigator.userAgent.toLowerCase();

	var is_major = parseInt(navigator.appVersion);
	var is_minor = parseFloat(navigator.appVersion);

	// *** BROWSER VERSION ***
	// Note: On IE5, these return 4, so use is_ie5up to detect IE5.
	var is_ie     = ((agt.indexOf("msie") != -1) && (agt.indexOf("opera") == -1));

	var is_ie3    = (is_ie && (is_major < 4));
	var is_ie4    = (is_ie && (is_major == 4) && (agt.indexOf("msie 4")!=-1) );
	var is_ie4up  = (is_ie && (is_major >= 4));
	var is_ie5    = (is_ie && (is_major == 4) && (agt.indexOf("msie 5.0")!=-1) );
	var is_ie5_5  = (is_ie && (is_major == 4) && (agt.indexOf("msie 5.5") !=-1));
	var is_ie5up  = (is_ie && !is_ie3 && !is_ie4);
	var is_ie5_5up =(is_ie && !is_ie3 && !is_ie4 && !is_ie5);
	var is_ie6    = (is_ie && (is_major == 4) && (agt.indexOf("msie 6.")!=-1) );
	var is_ie6up  = (is_ie && !is_ie3 && !is_ie4 && !is_ie5 && !is_ie5_5);

	menu_browser_ie6up = is_ie6 && is_ie6up;
	menu_browser_ie55up = is_ie5_5 || is_ie5_5up || is_ie6 || is_ie6up;

}


function menu_createDefaultLayout(menuItem)
{
	var s = "";
	var arrActions;
	var action;
	var tdmouseenter, tdmouseleave, tdmouseover, tdmouseclick;
	var trmouseenter, trmouseleave;

	arrActions = menuItem.arrActions;

	var selfWindowNameDot = (menuItem.selfWinodwName=="self") ? "" : (menuItem.selfWinodwName+".");
	var onClickFunc;
	var re = /'/g;

		s += "		 <table width='160' border='0' cellspacing='0' cellpadding='0' style='border:1px solid #E0E0E0;'>\n";
		//s += "		  <tr> \n";
		//s += "		   <td  background='http://images.hangame.com/nhn/hangame/avatar/menu/drop_frameblink.gif' style='padding:0 0 0 0' colspan='4'><img src='http://images.hangame.com/nhn/hangame/avatar/menu/drop_frameblink.gif' width='1' height='1'></td>\n";
		//s += "		  </tr>\n";
		s += "		  <tr> \n";
		//s += "		   <td width='1' background='http://images.hangame.com/nhn/hangame/avatar/menu/drop_frameblink.gif'><img src='http://images.hangame.com/nhn/hangame/avatar/menu/drop_frameblink.gif' width='1' height='1'></td>\n";
		s += "		   <td width='100%' align='center'>\n";
		s += "		    <table width='90%' border='0' cellspacing='0' cellpadding='0'>\n";
		s += "		     <tr> \n";
		s += "		      <td><img src='http://images.hangame.com/nhn/hangame/avatar/menu/drop_zeroblink.gif' width='7' height='7'></td>\n";
		s += "		     </tr>\n";

	for ( var i = 0 ; i < arrActions.length ; i++ )
	{
		action = arrActions[i];
		tdmouseenter = " onmouseenter='this.style.cssText=\"" + (action.enabled ? action.styleTDHover : action.styleTDDisabled) + "\";' ";
		tdmouseleave = " onmouseleave='this.style.cssText=\"" + (action.enabled ? action.styleTDDefault : action.styleTDDisabled) + "\";' ";
		trmouseenter = " onmouseenter='this.style.cssText=\"" + (action.enabled ? action.styleTRHover : action.styleTRDisabled) + "\"; ";
		//trmouseenter += " this.children[0].innerHTML=\"" + action.urlHoverBulletImgTag.replace(/'/g,"\\'") + "\";' ";
		trmouseenter += " this.children[0].innerHTML=\"" + action.urlHoverBulletImgTag + "\";' ";
		trmouseleave = " onmouseleave='this.style.cssText=\"" + (action.enabled ? action.styleTRDefault : action.styleTRDisabled) + "\"; ";
		trmouseleave += " this.children[0].innerHTML=\"" + action.urlBulletImgTag + "\";' ";

		tdmouseover = (action.expand && action.enabled) ? (" onmouseover='" + selfWindowNameDot + "menu_showSubMenu(\"event," + menuItem.eventWindowName + "\",this," + i + ");this.style.textDecoration=\"underline\";' ") : (" onmouseover='" + selfWindowNameDot + "menu_hideAllSubMenus(\"event," + menuItem.eventWindowName + "\",this);this.style.textDecoration=\"underline\";' ");
		tdmouseout = " onmouseout='this.style.textDecoration=\"none\";' ";
		onClickFunc = (action.onclick == null) ? "" : action.onclick + "(" + menuItem.gIndex + ")";
		onClickFunc = onClickFunc.replace(re,"\"");
		tdmouseclick = action.onclick ? " onclick='" + selfWindowNameDot + onClickFunc + ";' " : " onclick='" + selfWindowNameDot + "menu_clickDummy(\"" + menuItem.eventWindowName + "\");' ";

		if ( action.type == "menu" )
		{
			//s += "<tr " + trmouseenter + trmouseleave + "><td style=\"" + ((action.enabled) ? action.styleTDDefault : action.styleTDDisabled) + "\"" + tdmouseenter + tdmouseleave + tdmouseover + tdmouseclick + ">" + action.urlBulletImgTag + " " + action.title + "</td><td width='9' height='7'>" + ( (action.expand) ? " " + action.urlExpandImgTag : "" ) + "</td></tr>\n";
			s += "     <tr " + trmouseenter + trmouseleave + "> \n";
			s += "      <td style='font-family:Verdana; font-size:9px; margin:0px; color:#464646; letter-spacing:-1px; cursor:pointer; padding:3 0 3 0' " + tdmouseclick + tdmouseover + tdmouseout + ">" + action.urlBulletImgTag + "</td>\n";
			s += "      <td style='font-family:Verdana; font-size:9px; margin:0px; color:#464646; letter-spacing:-1px; cursor:pointer; padding:3 0 3 0' " + tdmouseclick + tdmouseover + tdmouseout + ">" + action.title + "</td>\n";
			if ( action.expand )
				s += "<td>" + action.urlExpandImgTag + "</td>\n";
			else
				s += "<td>&nbsp;</td>\n";
			s += "     </tr>			\n";
		}
		else if ( action.type == "bar" )
		{
			//s += "<tr><td height='1' colspan='2' background='http://images.hangame.com/nhn/hangame/ps/images/bubble_dotline.gif'></td></tr>\n";
			s += "     <tr> \n";
			s += "      <td colspan='3' background='http://images.hangame.com/nhn/hangame/avatar/menu/drop_lineblink.gif'><img src='http://images.hangame.com/nhn/hangame/avatar/menu/drop_lineblink.gif' width='1' height='1'></td>\n";

			s += "     </tr>\n";
		}
	}

	s += "     <tr> \n";
	s += "      <td><img src='http://images.hangame.com/nhn/hangame/avatar/menu/drop_zeroblink.gif' width='7' height='7'></td>\n";
	s += "     </tr>\n";
	s += "    </table>\n";
	s += "   </td>\n";
	//s += "   <td width='1' background='http://images.hangame.com/nhn/hangame/avatar/menu/drop_frameblink.gif'><img src='http://images.hangame.com/nhn/hangame/avatar/menu/drop_frameblink.gif' width='1' height='1'></td>\n";
	s += "  </tr>\n";
	//s += "  <tr> \n";
	//s += "   <td colspan='4' background='http://images.hangame.com/nhn/hangame/avatar/menu/drop_frameblink.gif'><img src='http://images.hangame.com/nhn/hangame/avatar/menu/drop_frameblink.gif' width='1' height='1'></td>\n";
	//s += "  </tr>\n";
	s += " </table>\n";
	//s += "</div>\n";


	oDiv = menuItem.oMainMenu;

	oDiv.style.position = "absolute";
	oDiv.style.left = "0px";
	oDiv.style.top = "0px";
	oDiv.style.visibility = "hidden";
	oDiv.style.backgroundColor = "white";
	oDiv.style.border = "0px";
	oDiv.style.padding = "0px 0px 0px 0px";
	if ( menuItem.nFading > 0 )
		oDiv.style.filter ="progid:DXImageTransform.Microsoft.Fade(duration=" + menuItem.nFading + ")";

	oDiv.style.filter += "progid:DXImageTransform.Microsoft.DropShadow(OffX=3,OffY=3,Color='#EEEEEE',Positive='true')";


	oDiv.onmouseleave = menu_ShowArea_OnMouseLeave;
	oDiv.onmouseenter = menu_ShowArea_OnMouseEnter;
	// to get correct event object in event handler function
	oDiv.eventWindowName = menuItem.eventWindowName;


	oDiv.innerHTML = s;

}


// helper

function menu_XYCoord(x,y) {
	this.x = x;
	this.y = y;
}

function menu_calcXY(e) {
	if ( typeof(window.screenLeft)=="number" ) {
		x = e.screenX - window.screenLeft + document.body.scrollLeft;
		y = e.screenY - window.screenTop + document.body.scrollTop;
	} else {
		x = e.clientX;
		y = e.clientY;
	}
	//x = e.x + document.body.scrollLeft;
	//y = e.y + document.body.scrollTop;

	return new menu_XYCoord(x,y);
}

function menu_memberIdInfo(showMemberId, selfMemberId) {
	this.showMemberId = showMemberId;
	this.selfMemberId = selfMemberId;
}


function menu_defaultShow(e, menuObj) {
	// get clicked coordinate
	var coord = menu_calcXY(e);
	// cancel bubble
	try {
		e.cancelBubble = true;
		e.stopPropagation();
	} catch (e) { //
	}
	// safe show, instead of showMenu(x,y);
	menu_safeShow(menuObj.gIndex, coord.x, coord.y);
}

////////////////////////////////////////////
// Default Implmentations - override this
////////////////////////////////////////////


// global variable
var mainMenu; // menu object
var mainMenuSelf;

function menu_showPersonalMenu(e,showMemberId, selfMemberId, menuPos)
{
	if ( menuPos==null || typeof(menuPos)!="number" ) {
		menuPos = menu_posBottomRight;
	}

	// check menu object and create
	if ( showMemberId==selfMemberId ) {
		if ( typeof(mainMenuSelf) != "object" )
			mainMenuSelf = new menu_FloatMenu(menu_createActions_PersonalMenuHisOwn(),menuPos);
		// save extended information
		mainMenuSelf.extInfo = new menu_memberIdInfo(showMemberId, selfMemberId);
		// show
		menu_defaultShow(e,mainMenuSelf);
	} else {
		if ( typeof(mainMenu) != "object" )
			mainMenu = new menu_FloatMenu(menu_createActions_PersonalMenu(),menuPos);
		// save extended information
		mainMenu.extInfo = new menu_memberIdInfo(showMemberId, selfMemberId);
		// show
		menu_defaultShow(e,mainMenu);
	}

}

function menu_showFlashPersonalMenu(e,showMemberId, selfMemberId)
{
	// check menu object and create

	if ( showMemberId==selfMemberId ) {
		if ( typeof(mainMenuSelf) != "object" )
			mainMenuSelf = new menu_FloatMenu(menu_createActions_FlashPersonalMenuHisOwn(),menu_posBottomRight);
		// save extended information
		mainMenuSelf.extInfo = new menu_memberIdInfo(showMemberId, selfMemberId);
		// show
		menu_defaultShow(e,mainMenuSelf);
	} else {
		if ( typeof(mainMenu) != "object" )
			mainMenu = new menu_FloatMenu(menu_createActions_FlashPersonalMenu(),menu_posBottomRight);
		// save extended information
		mainMenu.extInfo = new menu_memberIdInfo(showMemberId, selfMemberId);
		// show
		menu_defaultShow(e,mainMenu);
	}
}


// menu item
function menu_createActions_PersonalMenu(menuItem) {
	//menu_Action(id, sType, sTitle, sOnClickFuncName, bExpand, oSubMenuItem, bEnable, bSelected, urlBulletImgTag, urlHoverBulletImgTag, urlBarImg, urlExpandImgTag, urlDisabledExpandImgTag, styleTDDefault, styleTDHover, styleTDSelected, styleTDDisabled, styleTRDefault, styleTRHover, styleTRSelected, styleTRDisabled )
	// i18n
	var arrActions = null;
	if ( typeof(getLangCode)=="function" && getLangCode()=="es" ) {
		arrActions = new Array(
					new menu_Action("1","menu","Componer un Mensaje !!","menu_sendAMessage",false,null,true,true,"<img src=http://images.ijjimax.com/v2/common/ico_pop022.gif>","<img src=http://images.ijjimax.com/v2/common/ico_pop021.gif>"),
					new menu_Action("","bar"),
					new menu_Action("2","menu","Añadir a la La Lista de Amigos","menu_addToMyBuddyList",false,null,true,true,"<img src=http://images.ijjimax.com/v2/common/ico_pop032.gif>","<img src=http://images.ijjimax.com/v2/common/ico_pop031.gif>"),
					new menu_Action("3","menu","Añadir a la La Lista de Bloqueo","menu_addToMyBlockList",false,null,true,true,"<img src=http://images.ijjimax.com/v2/common/ico_pop042.gif>","<img src=http://images.ijjimax.com/v2/common/ico_pop041.gif>")
				);
	} else {
		arrActions = new Array(
					new menu_Action("1","menu","Compose a Message","menu_sendAMessage",false,null,true,true,"<img src=http://images.ijjimax.com/v2/common/ico_pop022.gif>","<img src=http://images.ijjimax.com/v2/common/ico_pop021.gif>"),
					new menu_Action("","bar"),
					new menu_Action("2","menu","Add to My Buddy List","menu_addToMyBuddyList",false,null,true,true,"<img src=http://images.ijjimax.com/v2/common/ico_pop032.gif>","<img src=http://images.ijjimax.com/v2/common/ico_pop031.gif>"),
					new menu_Action("3","menu","Add to My Block List","menu_addToMyBlockList",false,null,true,true,"<img src=http://images.ijjimax.com/v2/common/ico_pop042.gif>","<img src=http://images.ijjimax.com/v2/common/ico_pop041.gif>")
				);
	}
	return (arrActions);
}

function menu_createActions_PersonalMenuHisOwn(menuItem) {
	//menu_Action(id, sType, sTitle, sOnClickFuncName, bExpand, oSubMenuItem, bEnable, bSelected, urlBulletImgTag, urlHoverBulletImgTag, urlBarImg, urlExpandImgTag, urlDisabledExpandImgTag, styleTDDefault, styleTDHover, styleTDSelected, styleTDDisabled, styleTRDefault, styleTRHover, styleTRSelected, styleTRDisabled )
	var arrActions = new Array(
				new menu_Action("1","menu","Update My Avatar","menu_editAvatar",false,null,true,true,"<img src=http://images.ijjimax.com/v2/common/ico_pop022.gif>","<img src=http://images.ijjimax.com/v2/common/ico_pop021.gif>"),
				new menu_Action("2","menu","View My Messages","menu_openMessageBox",false,null,true,true,"<img src=http://images.ijjimax.com/v2/common/ico_pop042.gif>","<img src=http://images.ijjimax.com/v2/common/ico_pop041.gif>")
			);
	return (arrActions);
}

function menu_createActions_FlashPersonalMenu(menuItem) {
	//menu_Action(id, sType, sTitle, sOnClickFuncName, bExpand, oSubMenuItem, bEnable, bSelected, urlBulletImgTag, urlHoverBulletImgTag, urlBarImg, urlExpandImgTag, urlDisabledExpandImgTag, styleTDDefault, styleTDHover, styleTDSelected, styleTDDisabled, styleTRDefault, styleTRHover, styleTRSelected, styleTRDisabled )
	var arrActions = new Array(
				new menu_Action("1","menu","Report Abuse","menu_reportAbuse",false,null,true,true,"<img src=http://images.ijjimax.com/v2/common/ico_pop012.gif>","<img src=http://images.ijjimax.com/v2/common/ico_pop011.gif>"),
				new menu_Action("","bar"),
				new menu_Action("2","menu","Compose a Message","menu_sendAMessage",false,null,true,true,"<img src=http://images.ijjimax.com/v2/common/ico_pop022.gif>","<img src=http://images.ijjimax.com/v2/common/ico_pop021.gif>"),
				new menu_Action("","bar"),
				new menu_Action("3","menu","Add to My Buddy List","menu_addToMyBuddyList",false,null,true,true,"<img src=http://images.ijjimax.com/v2/common/ico_pop032.gif>","<img src=http://images.ijjimax.com/v2/common/ico_pop031.gif>"),
				new menu_Action("4","menu","Add to My Block List","menu_addToMyBlockList",false,null,true,true,"<img src=http://images.ijjimax.com/v2/common/ico_pop042.gif>","<img src=http://images.ijjimax.com/v2/common/ico_pop041.gif>")
			);
	return (arrActions);
}

function menu_createActions_FlashPersonalMenuHisOwn(menuItem) {
	return menu_createActions_PersonalMenuHisOwn(menuItem);
}

function menu_openGDiary(gIndex) {
	var menuItem = menu_getMenuItemByIndex(gIndex);
	if ( menuItem !=null && typeof(menuItem)=="object" ) {
		var showMemberId = menuItem.extInfo.showMemberId; //menuItem.extInfo.selfMemberId
		openSimpleFrameWindow("http://" + getServiceDomain("game." + domainName) + '/viewProfile.nhn?showMemberId=' + showMemberId , '_gameDiary', 500, 400);
	}
}

function menu_sendAMessage(gIndex) {
	if ( !menu_checkLogin() ) return;
	var menuItem = menu_getMenuItemByIndex(gIndex);
	if ( menuItem !=null && typeof(menuItem)=="object" ) {
		var showMemberId = menuItem.extInfo.showMemberId; //menuItem.extInfo.selfMemberId
		openSimpleFrameWindow("http://" + getServiceDomain("message." + domainName) + '/message.nhn?m=sendMessage&popup=Y&toid=' + showMemberId , '_blank', 401, 400);
	}
}

function menu_addToMyBuddyList(gIndex) {
	if ( !menu_checkLogin() ) return;
	var menuItem = menu_getMenuItemByIndex(gIndex);
	if ( menuItem !=null && typeof(menuItem)=="object" ) {
		var showMemberId = menuItem.extInfo.showMemberId; //menuItem.extInfo.selfMemberId
		openSimpleFrameWindow("http://" + getServiceDomain("message." + domainName) + '/buddy.nhn?m=addBuddy&popup=Y&buddyid=' + showMemberId , '_blank', 341, 176);
	}
}

function menu_addToMyBlockList(gIndex) {
	if ( !menu_checkLogin() ) return;
	var menuItem = menu_getMenuItemByIndex(gIndex);
	if ( menuItem !=null && typeof(menuItem)=="object" ) {
		var showMemberId = menuItem.extInfo.showMemberId; //menuItem.extInfo.selfMemberId
		openSimpleFrameWindow("http://" + getServiceDomain("message." + domainName) + '/setting.nhn?m=addBlock&blockid=' + showMemberId , '_blank', 341, 176);
	}
}

function menu_editAvatar(gIndex) {
	var menuItem = menu_getMenuItemByIndex(gIndex);
	if ( menuItem !=null && typeof(menuItem)=="object" ) {
		top.location.href = "http://" + getServiceDomain("avatar." + domainName) + '/index.nhn';
	}
}

function menu_openMessageBox(gIndex) {
	if ( !menu_checkLogin() ) return;
	var menuItem = menu_getMenuItemByIndex(gIndex);
	if ( menuItem !=null && typeof(menuItem)=="object" ) {
		//var showMemberId = menuItem.extInfo.showMemberId; //menuItem.extInfo.selfMemberId
		top.location.href = "http://" + getServiceDomain("message." + domainName);
 	}
}

function menu_reportAbuse(gIndex) {
	if ( !menu_checkLogin() ) return;
	var menuItem = menu_getMenuItemByIndex(gIndex);
	if ( menuItem !=null && typeof(menuItem)=="object" ) {
		var showMemberId = menuItem.extInfo.showMemberId; //menuItem.extInfo.selfMemberId
		//alert("report abuse ");
	}
}

function menu_checkLogin() {
	if ( typeof(isLogin)=="function" && !isLogin() ) {
		alert("You must be signed in to use this feature. Please sign in.");
		return false;
	}
	return true;
}

