// ----------------------------------------------------------------------
// 
// Javascript for some rollover, DHTML, and HTML code generation
// 
//
// Version: 5.10
// 
// ----------------------------------------------------------------------

// ---- Configuration section -------------------------------------------

// image and buttons directories (change if site hierarchy changes)
var imgBase='/eCarey/images/';
var btnBase='/eCarey/buttons/';

var barMenuSpacer   = img(new Array( 'src', imgBase + 'eb_sep.gif'));
var esMenuSpacer    = img(new Array( 'src', imgBase + 'es_sep.gif'));
var fsMenuSpacer    = img(new Array( 'src', imgBase + 'fs_sep.gif'));
var horizMenuSpacer = img(new Array( 'src', imgBase + 'e_res_light_menu_sep.gif'));

var MAX_DROPDOWN_ITEMS = 50;


// ---- End of Configuration section ------------------------------------


// ---- Other Global variables ------------------------------------------

// standard attributes for a simple layout-assist table
var simpleTableAttrs = 
new Array('cellspacing','0', 'cellpadding','0', 'border','0');

var wideTableAttrs = 
new Array('width','100%', 'cellspacing','0', 'cellpadding','0', 'border','0');


// ---- "Symbol table" hashes for our various objects -------------------

var AllMenus            = new Object();
var AllMenuTabs         = new Object();

var MenuStyleGenerators = new Object();

var AllDropdownJumps    = new Object();

var AllSlideshows       = new Object();


if (document.all && !document.getElementById)
{
    document.getElementById = function(id) {
        return document.all[id];
    }
}

function _preloadImages() 
{
    for (menuKey in AllMenus)
    {
        var menu = AllMenus[menuKey];

        for (menuTabKey in menu.tabs)
        {
            var menuTab = menu.tabs[menuTabKey];

            // left nav buttons are the only ones we want to preload
            if (  (menuTab.standardImageName.indexOf('ln_')  >= 0 ) 
               || (menuTab.standardImageName.indexOf('lns_') >= 0 ) )
            {
                var stdImg = new Image();
                var hovImg = new Image();
                stdImg.src = menuTab.standardImageName;
                hovImg.src = menuTab.hoverImageName;
            }
        }
    }
}

function preloadImages() 
{
    // give page some time to load before preloading button images
    setTimeout("_preloadImages()", 1500);

}



var _tpNS = (document.all)?false:true;

function getOffsetLeft (el) {
    var sl = el;
    var ol = el.offsetLeft;
    var sh = 0;
    while ((el = el.offsetParent) != null)
    {
        ol += el.offsetLeft;
        if (el.offsetParent && el.offsetParent.offsetParent)
        {
            var scrollLeft = el.offsetParent.scrollLeft;
            if (!isNaN(scrollLeft))
            {
                sh -= scrollLeft;
            }
        }
    }

    el = sl;
    if (_tpNS)
    {
        while ((el = el.parentNode) != null)
        {
            if (el.parentNode && el.parentNode.parentNode
                && !(el.parentNode.tagName && 
                     el.parentNode.tagName.toUpperCase() == "BODY"))
            {
                var scrollLeft = el.parentNode.scrollLeft;
                if (!isNaN(scrollLeft) && scrollLeft > 0 )
                {
                    sh -= scrollLeft;
                }
            }
        }
    }
    return ol+sh;
}

function getElementLeft(id)
{
    var el = document.getElementById(id);

    return getOffsetLeft(el);
}

function imgURL(imgName)
{
    return imgBase + imgName;
}

function btnURL(id)
{
    return btnBase + id  + '.gif';
}
function btnHoverURL(id)
{
    return btnBase + id  + '_hov.gif';
}


function attrGen(addrNameValueList)
{
    var list = ' ';
    
    for (var i=0; i<addrNameValueList.length; i+=2)
    {
        list += ' ' + addrNameValueList[i] + '="' + addrNameValueList[i+1] + '"' ;
    }
    return list;
}

function div(attrs)
{
    var html  = '<div ' + attrGen(attrs) + '>';
    for (var i=1; i<div.arguments.length; i++)
    {
        html += ' ' + div.arguments[i];
    }   
    html += '</div>' ;
//	alert(html);
    return html;
}


function td(attrs)
{
    var html  = '<td ' + attrGen(attrs) + '>';
    for (var i=1; i<td.arguments.length; i++)
    {
        html += ' ' + td.arguments[i];
    }   
    html += '</td>' ;
//	alert(html);
    return html;
}

function anchor(attrs)
{
    var html  = '<a ' + attrGen(attrs) + '>';
    for (var i=1; i<anchor.arguments.length; i++)
    {
        html += ' ' + anchor.arguments[i];
    }   
    html += '</a>' ;
//	alert(html);
    return html;
}

// added '_tag' to name because 'select' seems to be a javascript keyword
function select_tag(attrs,options)
{
    var html  = '<select ' + attrGen(attrs) + '>';
    for (var i=0; i<options.length; i++)
    {
        html += ' ' + options[i];
    }   
    html += '</select>' ;
//	alert(html);
    return html;
}




function img(attrs)
{
    return '<img '+ attrGen(attrs) + '/>';
}   




function SingleRowTable(attrs)
{
    var html = '<table ' + attrGen(attrs) + '>' + '<tbody> <tr> ';
    for (var i=1; i<SingleRowTable.arguments.length; i++)
    {
        html += SingleRowTable.arguments[i];
    }
    html += '</tr> </tbody> </table>';                      
    return(html);
}  

function MultiRowTable(attrs)
{
    var html = '<table ' + attrGen(attrs) + '>' + '<tbody> ';
    for (var i=1; i<MultiRowTable.arguments.length; i++)
    {
        html += '<tr>' + MultiRowTable.arguments[i] + '</tr>';
    }
    html += ' </tbody> </table>';                      
    return(html);
}  



function mtGetImgElement(menuTab)
{
    if (menuTab.buttonElement == 0)
    {
        menuTab.buttonElement = document.getElementById(menuTab.buttonId);
    }
    return menuTab.buttonElement;
}

function mtLookup(menuTabId)
{
    return AllMenuTabs[menuTabId];
}

function mtSetHoverImage(menuTab)
{
    mtGetImgElement(menuTab).src = menuTab.hoverImageName;
}

function mtSetStandardImage(menuTab)
{
    mtGetImgElement(menuTab).src = menuTab.standardImageName;
}

function mtGenKey(menuTab)
{
    return(menuTab.parentId + ':' + menuTab.id);
}


function setImage(imgId,imgName)
{
/* alert("in setImage: " + imgId + "  " + imgName); */
    document.getElementById(imgId).src = imgName; 
}
function get_setImage(imgId,imgName)
{
    var imgObj = document.getElementById(imgId);
    var was    = imgObj.src;
    imgObj.src = imgName;
    return was; 
}



// ----------- Special behaviours for menus ---------------------------



// ---- Horizontal menus ---
var visibleHorizSubMenuId='empty_sub';
var horizSubMenuTop = '';

function getHSMTop()
{
    if (horizSubMenuTop == '')
    {
        var referenceSM  = document.getElementById('horiz_sm');

        t = getPageOffsetTop(referenceSM);
//        y = t + referenceSM.offsetHeight;

// alert("t from getPageOffsetTop(): " + t);
// alert("referenceSM.offsetHeight: " + referenceSM.offsetHeight);
// alert("y (t + offsetHeight): " + y);
        // For IE, adjust position.

        //  if (browser.isIE) {
        //  if (1) {
        //    y += referenceSM.offsetParent.clientTop;
        //  }

        horizSubMenuTop = t + 'px';

// alert("horizSubMenuTop: " + horizSubMenuTop);
    }
    return horizSubMenuTop;
}

function activateHorizSubMenu(menuTab)
{
    var sm_was = document.getElementById(visibleHorizSubMenuId);
    var sm_is  = document.getElementById(menuTab.childId);
    
    visibleHorizSubMenuId = menuTab.childId;
    
    sm_was.style.visibility = "hidden";
    sm_was.style.display    = "none";

    sm_is.style.display     = "block";
    sm_is.style.visibility  = "visible";
//    sm_is.style.top       = getHSMTop();  trying to use position: relative, but $*%&^$ IE again...
}

function hideElement(id)
{
    var el = document.getElementById(id);
    if (el)
    {
        el.style.visibility = "hidden";
    }
}
function unHideElement(id)
{
    var el = document.getElementById(id);
    if (el)
    {
        el.style.visibility = "visible";
    }
}



var activeHMTab = 0;

function mouseOverHMT(menuTabId)
{
    var menuTab = AllMenuTabs[menuTabId];

    if (activeHMTab)
    {
        mtSetStandardImage(activeHMTab);
    }
    activeHMTab = menuTab;
    mtSetHoverImage(menuTab);

    activateHorizSubMenu(menuTab);
} 



// ---- Left-side navigation menus ----------------------------


var overLM           = false;
var activeLMTab      = 0;

function LN_HighlightMM(menuTabId)
{
    var menuTab = AllMenuTabs[menuTabId];

    activeLMTab = menuTab;
    mtSetHoverImage(menuTab);

    if (menuTab.childId != '')
    {
        unHideElement(menuTab.childId)
//        var sm_div              = document.getElementById(menuTab.childId);
//        sm_div.style.visibility = "visible";
    }
}

function LN_UnHighlightCurrentMM()
{
    if (activeLMTab)
    {
        mtSetStandardImage(activeLMTab);

        if (activeLMTab.childId != '')
        {
            hideElement(activeLMTab.childId);
        }
        activeLMTab = 0;
    }
}


function LN_TimeoutErase() {
    if ( ! overLM)
        LN_UnHighlightCurrentMM();
}

function LN_MouseOverTab(menuTabId) 
{
    LN_UnHighlightCurrentMM()
    LN_HighlightMM(menuTabId)
    overLM = true;
}

function LN_MouseOffTab() {
    overLM = false;
    window.setTimeout("LN_TimeoutErase();", 500);
}


function LN_MouseOverSubTab(menuTabId) {
    var menuTab = AllMenuTabs[menuTabId];

    overLM = true;
    mtSetHoverImage(menuTab);

//    mtGetImgElement(menuTab).style.border = '1px solid white';
}

function LN_MouseOffSubTab(menuTabId) {
    var menuTab = AllMenuTabs[menuTabId];

    overLM = false;
    mtSetStandardImage(menuTab);
//     mtGetImgElement(menuTab).style.borderTop = '0px';
    LN_MouseOffTab();
}


// ---- Bar navigation menus --------------------------


function unHideAndPositionElement(id,t,l)
{
    var el = document.getElementById(id);
    if (el)
    {
//        el.style.top        = (t + 'px');
        el.style.left       = (l + 'px');
//        el.style.top        = t;
//        el.style.left       = l;
        el.style.visibility = "visible";
    }
}


var overBAR           = false;
var activeBARTab      = 0;

function BAR_HighlightMM(menuTabId)
{
    var menuTab = AllMenuTabs[menuTabId];

    activeBARTab = menuTab;

    if (menuTab.childId != '')
    {
        var childMenu = AllMenus[menuTab.childId];

//        var myTop      = getElementTop(menuTab.buttonId);
        var myLeft     = getElementLeft(menuTab.buttonId);
        var parentLeft = getElementLeft(menuTab.parentId);

        var childTop   = 0; // not actually using this right now

//        var childLeft = (myLeft - parentLeft);
        var childLeft = ( (myLeft - parentLeft) / 2 );

// alert("BAR_HighlightMM() parentLeft " + parentLeft + " / myLeft " + myLeft + " / childleft  " + childLeft);

        unHideAndPositionElement(menuTab.childId, childTop, childLeft);
//        unHideElement(menuTab.childId)
    }
}

function BAR_UnHighlightCurrentMM()
{
    if (activeBARTab)
    {
        if (activeBARTab.childId != '')
        {
            hideElement(activeBARTab.childId);
        }
        activeBARTab = 0;
    }
}


function BAR_TimeoutErase() {
    if ( ! overBAR)
        BAR_UnHighlightCurrentMM();
}

function BAR_MouseOverTab(menuTabId) 
{
    BAR_UnHighlightCurrentMM()
    BAR_HighlightMM(menuTabId)
    overBAR = true;
// alert("BAR_MouseOverTab( " + menuTabId + ")");
}

function BAR_MouseOffTab() {
    overBAR = false;
    window.setTimeout("BAR_TimeoutErase();", 1000);
// alert("BAR_MouseOffTab( )");
}


function BAR_MouseOverSubTab(menuTabId) {
    var menuTab = AllMenuTabs[menuTabId];
// alert("BAR_MouseOverSubTab( " + menuTabId + ")");

    overBAR = true;
// CONFIG - don't want hover images here
//    mtSetHoverImage(menuTab);
}

function BAR_MouseOffSubTab(menuTabId) {
    var menuTab = AllMenuTabs[menuTabId];

    overBAR = false;
// CONFIG - don't want hover images here
//    mtSetStandardImage(menuTab);
    BAR_MouseOffTab();
// alert("BAR_MouseOffSubTab( " + menuTabId + ")");
}

// ----------- Menu generation code ---------------------------

function createImageLink(menuTab)
{
	return anchor(new Array('href', menuTab.href),
             img(new Array( 'src', menuTab.standardImageName, 'alt', menuTab.alt, 'id', menuTab.buttonId))
            );
}

function createRolloverLink(menuTab, mouseOn, mouseOff)
{
    return anchor(new Array('href', menuTab.href, 'onmouseover', mouseOn, 'onmouseout', mouseOff, 'onclick', menuTab.onclick),
             img(new Array( 'src', menuTab.standardImageName, 'alt', menuTab.alt, 'id', menuTab.buttonId))
            );
}

function createTypicalRolloverLink(menuTab)
{
    var mouseOn  = "setImage('" + menuTab.buttonId + "','" + menuTab.hoverImageName + "')" ; 
    var mouseOff = "setImage('" + menuTab.buttonId + "','" + menuTab.standardImageName + "')" ;
    
    return createRolloverLink(menuTab, mouseOn, mouseOff); 
}


function generateSpacerTabs(count)
{
    var spacer = 
    '<td>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</td>';

    var html = '';

    for (var i=0; i<count; i++)
    {
        html += spacer;
    }
    return html;
}


// ---- Horizontal special Navigation menus --------------------------

function generateHorizSubTab(menuTab)
{
    var html  = '<td align="center" valign="top">' ;
    html += createTypicalRolloverLink(menuTab);
    html += '</td>' ;
// alert(html); 
    return(html);  
}

function generateHorizSubMenu(menu)
{
    var html = '';
    
    html += generateSpacerTabs(menu.preSpace);

    for (var i=0; i<menu.tabCount; i++)
    {
        html += generateHorizSubTab( menu.orderedTabs[i] );
    }   
    html += generateSpacerTabs(menu.postSpace);

    html = div(new Array('class','horiz_submenu', 'id',menu.id),
               SingleRowTable( wideTableAttrs, html ) 
              );
    
//	alert(html);
    return html;
}

function generateHorizMainTab(menuTab)
{
    var mouseOn  = "mouseOverHMT('" + mtGenKey(menuTab) + "')" ;
    var mouseOff = "" ;
    
    var html  = '<td align="center" valign="top">' ;
    html += createRolloverLink(menuTab, mouseOn, mouseOff)
    html += '</td>' ;
    
// alert(html); 
    return(html);  
}

function generateHorizMainMenu(menu)
{
    var html = '';

    html += '<div class="horiz_menu_zone" id="horiz_m">' ;
    html += '<table width="100%" cellspacing="0" cellpadding="0" border="0"> <tbody>' ;
    html +=  '<tr>'  
    for (var i=0; i<menu.tabCount; i++)
    {
        if ((menu.separatorTag != '') && (i > 0))
        {
            html += '<td>' + menu.separatorTag + '</td>';
        }
        html += generateHorizMainTab( menu.orderedTabs[i] );
    }
    html +=  '</tr>' ;

    // !! Because of the way browsers lay out div blocks, the "empty_sub"
    // div block that is automatically created **MUST** be contiguous to
    // the submenu div blocks.  What this means in practice is that the
    // horiz submenus belonging to this horiz main menu must be inserted
    // by this routine.  (don't try to manually InsertMenuHere('HORIZ_SUBMENU',...))
    // 
    // We have a complete list of all associated submenus here, so just
    // work through the list, creating each submenu in the order found
    html +=  '<tr><td colspan="20">' ;
    html +=  '<div class="horiz_sm_zone" id="horiz_sm">' ;   
    
    // add the "empty_sub" div as a visible placeholder
    // NOTE: it *must* be first, because it is used as a position reference
    // for all the others (Hey, I _would_ have used position:absolute for
    // all these menus, but #&(*&#$ IE5 breaks proper z-index for those! Grrr!
    html +=  div(new Array('class', 'horiz_submenu', 'id','empty_sub'), '&nbsp;')

    for (var i=0; i<menu.tabCount; i++)
    {
        if (menu.orderedTabs[i].childId != '')
        {
            var childMenu = AllMenus[menu.orderedTabs[i].childId];
            html += generateHorizSubMenu( childMenu );
        }
    }
    html += '</div> </td> </tr>' ;
    html += '</tbody> </table>' ;
    html += '</div>' ;        
//	alert(html);
    return html;
}


// ---- Left Navigation menus --------------------------

function generateLeftNavTab(menuTab)
{
    var mouseOn  =  "LN_MouseOverTab('" + mtGenKey(menuTab) + "')" ; 
    var mouseOff =  "LN_MouseOffTab()" ;
    
    var html =  createRolloverLink(menuTab, mouseOn, mouseOff) ;

/* alert(html); */  
    return(html); 
}

function generateLeftNavSubTab(menuTab)
{
    var mouseOn   =  "LN_MouseOverSubTab('" + mtGenKey(menuTab) + "');" ; 
    var mouseOff  =  "LN_MouseOffSubTab('"  + mtGenKey(menuTab) + "');" ; 
    
    var html =  div(new Array('class', 'leftnav_sub_tab', 'id', menuTab.id),
                    createRolloverLink(menuTab, mouseOn, mouseOff) );

/* alert(html); */  
    return(html); 
}

function generateLeftNavSubMenu(menu)
{
    var html = '';
    
    for (var i=0; i<menu.tabCount; i++)
    {
        html += generateLeftNavSubTab( menu.orderedTabs[i] );
    }   
    html = div(new Array('class','leftnav_sub_block', 'id',menu.id), html );
    
//	alert(html);
    return html;

}

function generateLeftNavMenu(menu)
{
    var html = '';
    
    html += menu.separatorTag;
    for (var i=0; i<menu.tabCount; i++)
    {
        var menuTab = menu.orderedTabs[i];
        var subMenu = '';
        if (menuTab.childId != '')
        {
            var childMenu = AllMenus[menuTab.childId];
            subMenu = generateLeftNavSubMenu( childMenu );
        }

        html += div(new Array('class', 'leftnav_tab', 'id', menuTab.id),
                    generateLeftNavTab( menu.orderedTabs[i] ),
                    subMenu
                   );
        html += menu.separatorTag ;  
    }   
    html =  div(new Array('id', 'leftnav'), html);

//	alert(html);
    return html;
}


// ---- Bar Navigation menus --------------------------

function generateBARNavTab(menuTab)
{
    var mouseOn  =  "BAR_MouseOverTab('" + mtGenKey(menuTab) + "')" ; 
    var mouseOff =  "BAR_MouseOffTab()" ;
    
    var html =  createRolloverLink(menuTab, mouseOn, mouseOff) ;

// alert(html); 
    return(html); 
}

function generateBARNavSubTab(menuTab)
{
    var mouseOn   =  "BAR_MouseOverSubTab('" + mtGenKey(menuTab) + "');" ; 
    var mouseOff  =  "BAR_MouseOffSubTab('"  + mtGenKey(menuTab) + "');" ; 
    
    var html =  td(new Array('class', 'barnav_sub_tab', 'id', menuTab.id, 'align', 'center'),
                    createRolloverLink(menuTab, mouseOn, mouseOff) );

// alert(html); 
    return(html); 
}

function generateBARNavSubMenu(menu)
{
    var html = '';
    
    for (var i=0; i<menu.tabCount; i++)
    {
        if ((menu.separatorTag != '') && (i > 0))
        {
            html += td(new Array(), menu.separatorTag);
        }
        html += generateBARNavSubTab( menu.orderedTabs[i] );
    }   
    html = div(new Array('class','barnav_sub_block', 'id',menu.id), 
               SingleRowTable(simpleTableAttrs, html) 
              );
    
//	alert(html);
    return html;
}

function generateBARNavMenu(menu)
{
    var html = '';
    var sub_html = '';
    var main_html = '';
    var hasSubMenus = false;

    main_html += generateSpacerTabs(menu.preSpace);
    for (var i=0; i<menu.tabCount; i++)
    {
        if ((menu.separatorTag != '') && (i > 0))
        {
            main_html += td(new Array(), menu.separatorTag);
        }
        main_html += td(new Array('align', 'center'), 
                        generateBARNavTab(menu.orderedTabs[i]) 
                        );
    }   
    main_html += generateSpacerTabs(menu.postSpace);

    main_html = div(new Array('class','barnav', 'id',menu.id), 
                 SingleRowTable(simpleTableAttrs, main_html) 
                 );

    for (var i=0; i<menu.tabCount; i++)
    {
        var menuTab = menu.orderedTabs[i];

        if (menuTab.childId != '')
        {
            var childMenu = AllMenus[menuTab.childId];
            sub_html += generateBARNavSubMenu( childMenu );
            hasSubMenus = true;
        }
    }   

    if (hasSubMenus)
    {
        sub_html = div(new Array('class','barnav_sub_spaceholder', 'id',(menu.id + '_subarea')), 
                       sub_html 
                       );

        if (menu.invertSubMenus)
            html = sub_html + main_html;
        else
            html = main_html + sub_html;
    }
    else
    {
        html = main_html;
    }

    return html;
}



// --- Menu Generation function lookup tables ------------------------

MenuStyleGenerators['LEFTNAV']             = generateLeftNavMenu;
MenuStyleGenerators['LEFTNAV_SUBMENU']     = generateLeftNavSubMenu;
MenuStyleGenerators['BARNAV']              = generateBARNavMenu; 
MenuStyleGenerators['BARNAV_SUBMENU']      = generateBARNavSubMenu;
// MenuStyleGenerators['BARNAV']              = generateBarNavMenu;    
// MenuStyleGenerators['BARNAV_SUBMENU']      = ouch('BARNAV_SUBMENU');
MenuStyleGenerators['HORIZ_MENU']          = generateHorizMainMenu;                         
MenuStyleGenerators['HORIZ_SUBMENU']       = generateHorizSubMenu;


// ---- Menu (object) Creation functions------------------------------------

function Menu(style,id,separatorTag,onclick)
{
    if (! MenuStyleGenerators[style])
    {
        alert("Menu " + id + " has invalid style: " + style);
        return;
    }
    var newMenu = new Object();
    newMenu.style          = style;
    newMenu.id             = id;
    newMenu.separatorTag   = separatorTag;
    newMenu.onclick   	   = onclick;
    newMenu.tabs           = new Object();  // will be filled in by submenu create function
    newMenu.tabCount       = 0
    newMenu.orderedTabs    = new Array(30);  // nav menu should not exceed this length anyway 
    newMenu.preSpace       = 0;
    newMenu.postSpace      = 0;
    newMenu.invertSubMenus = false;
    
    AllMenus[id] = newMenu;
}

// Button images may get re-used, and since we also use the button base name
// to create the buttonId, we need to make the Id unique every time.
var ButtonIdUniqueNumber = 1;

function MenuTab(parentId, id, alt, href, onclick)
{
    var fixedArgCount = 5;
    
    var parentMenu = AllMenus[parentId];
    if (! parentMenu)
    {
        alert("MenuTab " + id + " has no parent Menu: '" + parentId);
        return;
    }
    if (parentMenu.tabs[id])
    {
        alert("Attempting to redefine MenuTab " + id + " in Menu: '" + parentId);
        return;
    }

    var newMenuTab = new Object();
    newMenuTab.parentId           = parentId;
    newMenuTab.id                 = id;
    newMenuTab.alt                = alt;
    newMenuTab.href               = href;
    newMenuTab.onclick            = onclick;
    newMenuTab.buttonId           = id + '_b' + ButtonIdUniqueNumber;
    ButtonIdUniqueNumber++;

    newMenuTab.standardImageName  = btnURL(id);
    newMenuTab.hoverImageName     = btnHoverURL(id);
    newMenuTab.buttonElement      = 0;
    
    if (MenuTab.arguments.length > fixedArgCount)
    {
        newMenuTab.childId = MenuTab.arguments[fixedArgCount]; 
    } else
    {
        newMenuTab.childId = '' 
    }
    
    parentMenu.tabs[id] = newMenuTab;
    // normally the .tabs[] hash would be enough, but we want 
    // to emit the menu tabs in the order that they were found.
    parentMenu.orderedTabs[ parentMenu.tabCount++ ] = newMenuTab;

    AllMenuTabs[ mtGenKey(newMenuTab) ] = newMenuTab;
}


function MenuSpacers(menuId, spaces)
{
    var menu = AllMenus[menuId];
    if (! menu)
    {
        alert("Applying MenuSpacer to unknown Menu: '" + menuId + "'");
        return;
    }

    if (menu.tabCount == 0)
    {
        menu.preSpace  = spaces;
    } else
    {
        menu.postSpace = spaces;
    }
}

function MenuInvertSubMenu(menuId)
{
    var menu = AllMenus[menuId];

    if (! menu)
    {
        alert("Applying MenuInvertSubMenu() to unknown Menu: '" + menuId + "'");
        return;
    }
    menu.invertSubMenus = true;
}


function InsertMenuHere(menuId)
{
    var menu = AllMenus[menuId];
    if (! menu)
    {
        alert("Attempting to insert a nonexistent Menu: '" + menuId + "'");
        return;
    }
    document.write( MenuStyleGenerators[ menu.style ](menu) );
    if(menuId=='left_nav')
    	document.write(careySearch());
// var out = MenuStyleGenerators[ menu.style ](menu);
// alert( out );
// document.write( out  );	
}

function careySearch()
{
    var html  = '<table border="0" cellspacing="0" cellpadding="0">' + 
		'<tr>' + 
			'<td>' + 
			'<form name="careySearch" action="/eCarey/SearchCarey.jsp">' + 
			'<table border="0" cellspacing="0" cellpadding="0">' + 
				'<tr>' + 
					'<td colspan="2" align="left" style="color: #d5dbe2; font-family:Arial; font-size:12px;font-weight:bold;border-top:solid white 1px; padding:10px 0 0 10px">' + 
					'Search</td>' + 
				'</tr><tr>' + 
					'<td valign="top" align="left" style="padding:0 0 0 10px">' + 
					'<input type="hidden" name="s" value="SS">' +
						'<input name="q" size="14" maxlength="30" style="font-size: 8pt;" type="text"></td>' + 
					'<td align="left" valign="bottom" style="padding:0 17px 0 7px">' + 
					'<input type="image" src="/eCarey/buttons/btn_go.gif" alt="Go" onClick="search();"/>' + 
					'</td>' + 
				'</tr>' + 
			'</table>' + 
			'</form>' + 
			'</td>' + 
		'</tr>' + 
	'</table>';

	html='';
	return html;
}

function search() {
document.careySearch.action = '/eCarey/SearchCarey.jsp';
}



// ---- Slideshow functions  ---------------------------------------

function nextSlide(id)
{
    var slideShow = AllSlideshows[id];

    if ( ! slideShow.imgElement)
    {
        slideShow.imgElement = document.getElementById(id);
    }

    slideShow.currentIndex++;
    if (slideShow.currentIndex >= slideShow.slides.length)
        slideShow.currentIndex = 0;

    var slide = slideShow.slides[ slideShow.currentIndex ];

    if (slide.image.complete)  // whole image downloaded?
    {
        slideShow.imgElement.src = slide.image.src;

        setTimeout(slideShow.timerCommand, slideShow.timeout);
    }
    else
    {
        // sorry, image hasn't finished downloading yet - 
        // we'll try again in .5 seconds
        setTimeout(slideShow.timerCommand, 500);
        slideShow.currentIndex--;  // come back to this same image again
    }
}


function aSlide(imageName)
{
    var slide = new Object();

    slide.image = new Image();
    slide.image.src = imgURL(imageName);

    return slide;
}


function Slideshow(id, displayTime, allImages)
{
    // Step one:  create slideshow object
    var slideShow = new Object();

    if (displayTime == 0)  // can't have zero timeout - browser will bog down
        displayTime = 1;   // really should warn programmer here - fast slides are a clue, anyway

    // displayTime is specified in seconds; window timers use milliseconds; convert
    slideShow.timeout      = (displayTime * 1000);
    slideShow.imgElement   = 0;  // <IMG> Element - won't know this 'til later
    slideShow.timerCommand = "nextSlide('" + id + "')";
    slideShow.currentIndex = (-1);
    slideShow.slides       = new Array(allImages.length);

    for (var i=0; i<allImages.length; i++)
    {
        slideShow.slides[i] = aSlide( allImages[i] );
    }

    AllSlideshows[id] = slideShow;    // remember so nextSlide can find this show

    // Step two: place image tag into document
    var html = img(new Array( 'src', slideShow.slides[0].image.src, 'id', id));

// alert("Slideshow, image html: " + html);
    document.write( html );

    // Step three: kick off timer for moving on to next slide
      // NOTE: try setInterval instead, then nextSlide function won't need to restart timeout!
    setTimeout(slideShow.timerCommand, slideShow.timeout);
}



// ---- Dropdown jump functions  ---------------------------------------


function JumpToPageIn(id)
{
    // we gave the <select> tag the name=(our DropdownJump id)
    var selectElement = document.getElementById(id);
    // ...same as the actual DropdownJump object
    var dropdownJump  = AllDropdownJumps[id];

    var jumpIndex = selectElement.selectedIndex;

    if (jumpIndex == dropdownJump.descIndex)
        return;

// alert('in JumpToPageIn(' + id + ') - selectedIndex is ' + jumpIndex);
    parent.location.href= dropdownJump.hrefSet[ jumpIndex ];
}
  

function DropdownJump(id,descriptive,style)
{
    var fixedArgCount = 2;
    
    var newDropdownJump = new Object();
    newDropdownJump.id        = id;
    newDropdownJump.ItemCount = 0;
    newDropdownJump.descIndex = 1;
    newDropdownJump.descText  = descriptive;
    newDropdownJump.textSet   = new Array(MAX_DROPDOWN_ITEMS);
    newDropdownJump.hrefSet   = new Array(MAX_DROPDOWN_ITEMS);
    newDropdownJump.style     = style;
    AllDropdownJumps[id]      = newDropdownJump;
}


function DropdownJumpItem(parentId, text, href)
{
    var parentDropdownJump = AllDropdownJumps[parentId];
    if (! parentDropdownJump)
    {
        alert("DropdownJumpItem " + id + " has no parent DropdownJump: '" + parentId);
        return;
    }

// !! Should check that not exceeding MAX_DROPDOWN_ITEMS here!    

    parentDropdownJump.textSet[ parentDropdownJump.ItemCount ] = text;
    parentDropdownJump.hrefSet[ parentDropdownJump.ItemCount ] = href;
    parentDropdownJump.ItemCount++;
}

// DO NOT FORGET to put this inside a <FORM> InsertDropdownJumpHere(id) </FORM> tag
function InsertDropdownJumpHere(id)
{
    var dropdownJump = AllDropdownJumps[id];
    if (! dropdownJump)
    {
        alert("Attempting to insert a nonexistent DropdownJump: '" + id);
        return;
    }
    dropdownTextList  = new Array(dropdownJump.ItemCount + 1);
    
    for (var i=0; i<dropdownJump.ItemCount; i++)
    {
        dropdownTextList[i] = '<option value="' + i + '">' + dropdownJump.textSet[i];
    }
    dropdownJump.descIndex = dropdownJump.ItemCount;
    dropdownTextList[dropdownJump.descIndex] = 
        '<option value="' + dropdownJump.descIndex + '" selected="selected">' + dropdownJump.descText;

    var onchangeAction = "JumpToPageIn('" + id + "')";
    
    // !! CHECK to see which attr is needed - name? or id?  right now, using both to be sure
    // attr should be onchange
    var html = select_tag(new Array('name', id, 'id', id, 'onchange', onchangeAction, 'style', dropdownJump.style),
                          dropdownTextList
                          );
// alert(html);
    document.write( html );
}








Menu( 'LEFTNAV', 'left_nav', '');
MenuTab('left_nav', 'btn_left_nav_1a-difference', 'The Carey Difference', '/eCarey/M1_0_AWorldofDifference.html', '', 'a_world_sub');
MenuTab('left_nav', 'btn_left_nav_2a-network', 'Carey Global Network', '/eCarey/M10_1_GlobalServicesNetwork.html','');
MenuTab('left_nav', 'btn_left_nav_3a-services', 'Chauffered Services', '/eCarey/M2_0_ChauffeuredServices.html', '','chauff_serv_sub');
MenuTab('left_nav', 'btn_left_nav_4a-corp_trav', 'Corporate Travel', '/eCarey/M5_0_BusinessTravel.html','');
MenuTab('left_nav', 'btn_left_nav_5a-me', 'Meetings & Events', '/eCarey/M3_0_MeetingsandEvents.html','');
MenuTab('left_nav', 'btn_left_nav_6a-trav_agent', 'Travel Agents', '/eCarey/M7_0_TravelAgentCenter.html','');
MenuTab('left_nav', 'btn_left_nav_7a-fleet', 'Carey Fleet', '/eCarey/M9_1_CareyFleet.html','');
MenuTab('left_nav', 'btn_left_nav_8a-care', 'Customer Care', '/eCarey/M8_0_CustomerCareCenter.html','', 'cust_care_sub');
MenuTab('left_nav', 'btn_left_nav_9a-care', 'Carey Rewards Club', '/eCarey/RC1_0_CareyRewardsClub.html','');

Menu( 'LEFTNAV_SUBMENU', 'a_world_sub', '');
MenuTab('a_world_sub', 'btn_subnav_1-1a_service', 'Culture of Service', '/eCarey/M1_3_PersonalizedServices.html','');
MenuTab('a_world_sub', 'btn_subnav_1-2a_truth', 'The Ten Truths', '/eCarey/M1_2_TheTenTruths.html','');
MenuTab('a_world_sub', 'btn_subnav_1-3a_reservat', 'Global Reservation Center', '/eCarey/M1_2_GlobalReservationSystem.html','');
MenuTab('a_world_sub', 'btn_subnav_1-4a_chauffeur', 'Certified Professional Chauffeurs', '/eCarey/M1_1_CertifiedProfessionalChauffeurs.html','');
MenuTab('a_world_sub', 'btn_subnav_1-5a_me', 'Meet & Greet Service', '/eCarey/M1_4_MeetandGreetService.html','');
MenuTab('a_world_sub', 'btn_subnav_1-6a_car', 'The Carey Car', '/eCarey/fleet/Executive_Sedan.html','window.open(\'/eCarey/fleet/Executive_Sedan.html\', \'CareyFleet\', \'resizable=yes,scrollbars=yes,width=500,height=500\'); return false');
MenuTab('a_world_sub', 'btn_subnav_1-7a_quality', 'Quality Assurance', '/eCarey/M8_2_QualityAssuranceProgram.html','');

Menu( 'LEFTNAV_SUBMENU', 'chauff_serv_sub', '');
MenuTab('chauff_serv_sub', 'btn_subnav_3-1a_airport', 'Airport Services', '/eCarey/M2_1_AirportServices.html');
MenuTab('chauff_serv_sub', 'btn_subnav_3-2a_fbo', 'FBO Services', '/eCarey/M2_2_FBOServices.html');
MenuTab('chauff_serv_sub', 'btn_subnav_3-3a_charter', 'Hourly Charters', '/eCarey/M2_3_HourlyCharters.html');
MenuTab('chauff_serv_sub', 'btn_subnav_3-4a_road', 'Road Show Services', '/eCarey/M4_0_RoadShow.html');
MenuTab('chauff_serv_sub', 'btn_subnav_3-5a_city', 'City-to-City Services', '/eCarey/M2_4_CitytoCity.html');
MenuTab('chauff_serv_sub', 'btn_subnav_3-6a_tours', 'Tours and Sightseeing', '/eCarey/M2_6_ToursandSightseeing.html');
MenuTab('chauff_serv_sub', 'btn_subnav_3-7a_occasion', 'Special Occasions', '/eCarey/M2_7_SpecialOccasions.html');

Menu( 'LEFTNAV_SUBMENU', 'cust_care_sub', '');
MenuTab('cust_care_sub', 'btn_subnav_8-1a_report', 'Service Incident Report', '/eCarey/M8_4_ServiceIncidentReport.html');
MenuTab('cust_care_sub', 'btn_subnav_8-2a_survey', 'Customer Satisfaction Survey', '/eCarey/M8_3_CustomerSatisfactionSurvey.html');

Menu( 'BARNAV', 'head_nav', barMenuSpacer);
MenuTab( 'head_nav', 'e_tel_c', 'Phone: 1-800-336-4646', '/eCarey/E5_0_ContactUs.html','');
MenuTab( 'head_nav', 'e_about_c', 'About Carey', '/eCarey/E1_0_AboutCarey.html','', 'e_about_sub');
MenuTab( 'head_nav', 'e_trav_partners_c', 'Travel Partners', '/eCarey/E2_0_TravelPartners.html','');
MenuTab( 'head_nav', 'e_careers_c', 'Careers', '/eCarey/E3_0_Careers.html','');
MenuTab( 'head_nav', 'e_news_c', 'News', '/eCarey/E4_0_NewsandEvents.html','');
MenuTab( 'head_nav', 'e_contact_c', 'Contact Us', '/eCarey/E5_0_ContactUs.html','');
// MenuSpacers('head_nav', 2);

Menu( 'BARNAV_SUBMENU', 'e_about_sub', esMenuSpacer);
MenuTab('e_about_sub', 'es_our_mission', 'Mission', '/eCarey/E1_1_OurMission.html','');
MenuTab('e_about_sub', 'es_comp_hist', 'History', '/eCarey/E1_3_CompanyHistory.html','');
MenuTab('e_about_sub', 'es_exec_team', 'Executive Team', '/eCarey/E1_4_ManagementTeam.html','');

Menu( 'BARNAV', 'foot_nav', barMenuSpacer);
MenuTab( 'foot_nav', 'f_faq', 'FAQ', '/eCarey/A1_0_FrequentlyAskedQuestions.html','');
MenuTab( 'foot_nav', 'f_sitemap', 'Sitemap', '/eCarey/A2_0_SiteMap.html','');
MenuTab( 'foot_nav', 'f_privacy', 'Privacy Policy', '/eCarey/A3_0_PrivacyPolicy.html','');
MenuTab( 'foot_nav', 'f_terms', 'Terms and Conditions', '/eCarey/A4_0_TermsandConditions.html','', 'f_terms_sub');
// MenuTab( 'foot_nav', 'f_legal', 'Legal', '/eCarey/A5_0_Legal.html',''),
MenuTab( 'foot_nav', 'f_copyright', 'Copyright', '/eCarey/A6_0_Copyright.html','');

MenuInvertSubMenu('foot_nav');

Menu( 'BARNAV_SUBMENU', 'f_terms_sub', fsMenuSpacer);
MenuTab('f_terms_sub', 'fs_web_terms', 'Web Terms', '/eCarey/A4_1_WebTermsandConditions.html','');
MenuTab('f_terms_sub', 'fs_service_terms', 'Carey Terms', '/eCarey/A4_2_CareyServiceTermsandConditions.html','');
