//  functions to show and hide the dropdown menu

function CMN_ShowMenu(pThis) {
    jQuery(pThis)
			.next().css({ 'visibility': 'visible' })
			.css({ 'left': jQuery(pThis).position().left + 'px' });
}

function CMN_HideMenu(pThis, pEvent) {
    xSubMenu = jQuery(pThis).next();
    if ((pEvent.pageY < xSubMenu.offset().top) || (xSubMenu.children().length == 0)) {
        jQuery(pThis)
				.next().css({ 'visibility': 'hidden' });
    }
}

function CMN_HideSubMenu(pThis) {
    jQuery(pThis)
			.css({ 'visibility': 'hidden' });
}

//hash the email links

var gContactList = {'Rick Hubbard': 'mai#crick#akazoobie#dcom', 'Diane Diachishin': 'mai#cdiarich#afrontiernet#dnet', 'Patricia Shih': 'mai#cpatshih#apb#dnet'};

// on page load
$(document).ready(function () {

    // attach functions to event handlers to the menu anchors 
    jQuery('#menu div').each(function () {
        jQuery(this)
					.mouseleave(function () { CMN_HideSubMenu(this) })
					.prev()
					.mouseenter(function () { CMN_ShowMenu(this) })
					.mouseleave(function (event) { CMN_HideMenu(this, event) });
    });

    // set up the member login/pages link in the banner

    // find the path
    var xPath = '';
    var xPathParts = location.pathname.split("/");
    if (xPathParts.length >= 2) {
        var xPathPart = xPathParts[xPathParts.length - 2];
        var xPathFolders = new Array('members', 'conference', 'magic-penny');
        if (jQuery.inArray(xPathPart, xPathFolders) >= 0) {
            xPath = '../';
        };
    };

    // adjust the link
    var xCookieStr = '~' + document.cookie;
    if (xCookieStr.indexOf('CMN_Login=True') > 0) {
        jQuery('#banner-login').text('Member Pages').attr('href', xPath + 'members/main.aspx');
    } else {
        jQuery('#banner-login').text('Member Login').attr('href', xPath + 'login.aspx');
    };

    //attach the contact links
    jQuery('a.cmn-contact').mouseover(function () {
        xItem = gContactList[jQuery(this).text()];
        xItem = xItem.replace('#c', 'lto:');
        xItem = xItem.replace('#a', '@');
        xItem = xItem.replace('#d', '.');
        jQuery(this).attr('href', xItem);
    });

});
	


