/**
 * @fileoverview 实现子菜单的显示或隐藏功能。<br>当鼠标移入（或移出）菜单“Jobseeker”或“Employer”时，显示（或隐藏）其子菜单。
 * @version 1.0
 */

/**
 * 打开指定链接的方法。
 * @param {String} link 链接
 */
function openLink(link)
{
    /* 在模板里已有 contextPath 的定义。 */
    location.href = contextPath + link;
}

/**
 * 控制子菜单是否可显示，默认值为false。
 * @type boolean
 */
var canShow = false;

/**
 * 根据父菜单显示具体的子菜单内容。
 * @param {String} visitor 子菜单名称
 */
function showVisitorSubMenu(visitor)
{
    if (typeof(visitorMenu) == "undefined") return;

    if (visitor == "employer")
    {
        var employerSubMenuContent = '<span id="visitorSubMenuContain"><a href="javascript:openLink(\'/employer/register/register!jspChannel.action?path=/home/employer/tiles/join.jsp\');">Join Now</a>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<a href="javascript:openLink(\'/employer/security/login.jsp.action\');">Employer Login</a>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<a href="javascript:openLink(\'/home/viewJSP!jspChannel.action?path=/home/employer/resources/tiles/resources.jsp&currentHomeMenuID=2\');">Resources</a></span>'

        visitorMenu.repack(['subMenu'], [employerSubMenuContent]);
        showSubMenuContain();
        canShow = true;
    }
    else if (visitor == "seeker")
    {
        var seekerSubMenuContent = '<span id="visitorSubMenuContain"><a href="javascript:openLink(\'/seeker/register/register!jspChannel.action?path=/home/seeker/tiles/join.jsp\');">Join Now</a>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<a href="javascript:openLink(\'/home/search/search!initAdvancedSearch.action\');">Job Search</a>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<a href="javascript:openLink(\'/seeker/security/login.jsp.action\');">Member Login</a>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<a href="javascript:openLink(\'/home/viewJSP!jspChannel.action?path=/home/talentMarket/tiles/talentMarket.jsp\');">Talent Market</a>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<a href="javascript:openLink(\'/home/viewJSP!jspChannel.action?path=/home/seeker/resources/tiles/resources.jsp\');">Resources</a></span>'

        visitorMenu.repack(['subMenu'], [seekerSubMenuContent]);
        showSubMenuContain();
        canShow = true;
    }
    else
    {
        visitorMenu.repack(['subMenu'], ['']);
        canShow = false;
    }
}

/**
 * 隐藏子菜单框架。
 */
function hideSubMenuContain()
{
    document.all.subMenuContain.style.visibility = "hidden";
    var menuContainObj = document.all.menuContain;

    if (canShow)
    {
        menuContainObj.onmouseout = function(){showSubMenuContain();};
        canShow = false;
    }
    else
    {
        menuContainObj.onmouseout = function(){hideSubMenuContain();};
    }
}

/**
 * 显示子菜单框架。
 */
function showSubMenuContain()
{
    document.all.subMenuContain.style.visibility = "visible";
    document.all.menuContain.onmouseout = function(){hideSubMenuContain();};
}

/**
 * 页面加载时先创建一个空内容的visitorMenu，以加快鼠标初次放到父菜单调用showVisitorSubMenu()显示子菜单的响应速度。
 * @type String
 * @return 退出方法。
 */
function initSubMenu()
{
    if (typeof(visitorMenu) == "undefined")
    {
        setTimeout("initSubMenu()", 2);
    }

    showVisitorSubMenu('');
    return;
}

/* 执行初始方法。 */
initSubMenu();
