
localImageDir = imageDir + 'nav/';

function rollOverButton(menu, nav_obj, state, overridestate) {
    nav_obj.name = menu + '_' + nav_obj.name;

    if( ! state ) {
        this.roll = nav_obj.name + '_over';
        this.roll_src = localImageDir + this.roll + '.gif';
        this.preload = newImage(this.roll_src);
    } else {
        nav_obj.name = nav_obj.name + '_over';
		this.roll_src = localImageDir + this.roll + '.gif';
        this.preload = newImage(this.roll_src);
    }
    this.name_src = localImageDir + nav_obj.name + '.gif';
    this.link_root = hostRoot;

    ext = '';
    if(nav_obj.name == 'gnav_order') {
		// we don't really need order.php to be secure, and the *./clearwire.com ssl issue making this an issue.  - jes
        //this.link_root = prodRoot;
    }
    this.html = '<img id="' + nav_obj.name + '" src="' + this.name_src + '" ';
    this.html += 'alt="' + nav_obj.alt + '" name="' + nav_obj.name + '" border="0">';
	if( ! state ) {
        anchor_wrap = '<a ';
        if( ! state ) {
            anchor_wrap += 'onmouseover="' + "changeImages('" + nav_obj.name + "','" + this.roll_src + "');return true" + '" ';
            anchor_wrap += 'onmouseout="' + "changeImages('" + nav_obj.name + "','" + this.name_src + "');return true" + '" ';
        }
        anchor_wrap += 'href="' + this.link_root + nav_obj.link + '">' + this.html + '</a>';
        this.html = anchor_wrap;
    } else {
		anchor_wrap = '<a ';
        if( ! state ) {
            anchor_wrap += 'onmouseover="' + "changeImages('" + nav_obj.name + "','" + this.roll_src + "');return true" + '" ';
            anchor_wrap += 'onmouseout="' + "changeImages('" + nav_obj.name + "','" + this.name_src + "');return true" + '" ';
        }
        anchor_wrap += 'href="' + this.link_root + nav_obj.link + '">' + this.html + '</a>';
        this.html = anchor_wrap;
	}
    //alert("rob:" + menu + "," + nav_obj.name + "," + state + "=" + this.html);
}

/*================================================================
 *          Name: HubNav
 *   Description: Produces plain <a> navs from a nav configuration
 *         Input: none
 *        Output: none
 *        Return: html string for output
 * Special Logic: Nav Configuration for Hub nav has:
 *      1. no rollover capability
 *      2. no lnav
 *      3. full links (due to external linkage)
 *================================================================ */
function HubNav() {
    this.html = '';
    for(var i = 0; i < HubNav.length; i++) {
        nav_obj = HubNav[i];
        if( nav_obj.display == 'true' ) {
            this.html += '<a href="' + nav_obj.link + '">' + nav_obj.alt + '</a>';
        }
    }
}
function BlankMenu() {
    var gnav_html;
    var lnav_html;
    var signin_html;
    var footer_html;
    var logo_html;

    this.gnav_html = '';
    this.lnav_html = '';
    this.signin_html = '';
    this.footer_html = '';
    this.logo_html = '<a href="' + hostRoot + 'index.php"><img src="' + localImageDir + 'logo_cw.gif" alt="Clearwire Wireless Broadband" border="0"></a>';
}
/*
   Main Site Nav
*/
function NavMenu(curr_gnav, curr_lnav) {
    var gnav_html;
    var lnav_html;
    var signin_html;
    var footer_html;
    var logo_html;

    // Process prequal cookie if it exists
    this.signin_html = "My Account Login";
    if(pqcookie != -1) {
        if(pqcookie["first_name"] && pqcookie["first_name"] != '') {
            this.signin_html = "Welcome " + pqcookie["first_name"];
        }
    }

    this.signin_html = '<font size="-2" color="gray" face="Verdana, Arial, Helvetica, sans-serif"><a href="' + prodRoot + 'my_account/signin.php">' + this.signin_html + '</a> <font color="#b4b4b4">&#8226;</font> <a href="' + hostRoot + 'store/get_stores.php" onclick="popUp(this.href,\'console\',450,600);return false;" target="newWin">Store Locator</a> <font color="#b4b4b4">&#8226;</font> 1.888.CLEARWIRE</font>';
    this.logo_html = '<a href="' + hostRoot + 'index.php"><img src="' + localImageDir + 'logo_cw.gif" alt="Clearwire Wireless Broadband" border="0"></a>';
    this.lnav_html = '';
    this.gnav_html = '';

    for(var i = 0; i < MainNav.length; i++) {
        g_obj = MainNav[i];
        gstate = '';
        //alert("g_opj.name: " + g_obj.name + "\ng_obj.display: " + g_obj.display);
        if(curr_gnav && g_obj.name == curr_gnav) {
            gstate = 'over';
            for(var j in g_obj.lnav) {
                l_obj = g_obj.lnav[j];
                //alert("Doing g_obj.lnav[" + j + "], name=" + l_obj.name);
                lstate = '';
                if(curr_lnav && l_obj.name == curr_lnav) {
                    lstate = 'over';
                }
                l_obj.name = g_obj.name + '_' + l_obj.name;
                l_button = new rollOverButton('lnav',l_obj, lstate);
                //alert("Button html: " + l_button.html + "\n\nBeing added to lnav_html: " + this.lnav_html);
                this.lnav_html = this.lnav_html + l_button.html;
            }
        }
        if(g_obj.display == 'true') {
            button = new rollOverButton('gnav', g_obj, gstate);
            this.gnav_html = this.gnav_html + button.html;
        }
    }
    this.footer_html = getFooter();
}
/*
   MyAccount Site Nav
   1. Significantly different than the corp nav in that all lnavs must be processed
      to produce the jump menu for MyAccount
*/
function MAMenu(curr_mnav, curr_lnav) {
    //alert("MAMenu called with" + curr_mnav);
    var mnav_html;
    var lnav_html;
    var signin_html;
    var footer_html;
    var logo_html;
    var jump_html;
    var jump_js = "if(this.options[this.selectedIndex].value==''){this.selectedIndex=0;}else{window.location=this.options[this.selectedIndex].value;}";

    this.signin_html = '<font size="-2" color="gray" face="Verdana, Arial, Helvetica, sans-serif"><a href="' + hostRoot + 'index.html">Home</a> | <a href="' + prodRoot + 'my_account/signout.php">My Account Logout</a></font>';
    this.logo_html = '<a href="' + hostRoot + 'index.html"><img src="' + localImageDir + 'cw_left_short.gif" alt="Clearwire Wireless Broadband" height="85" width="230" border="0"></a>';
    this.lnav_html = '';
    this.mnav_html = '';
    this.jump_html = '<span class="field-label"><strong><br />&nbsp;&nbsp;Jump To:</strong></span>';
    this.jump_html += '<select name="jumpSelectMenu" onChange="' + jump_js + '" class="list">';
    //alert("MyAccountNav.length == " + MyAccountNav.length);

    for(var i = 0; i < MyAccountNav.length; i++) {
        m_obj = MyAccountNav[i];
        if(curr_mnav && m_obj.name == curr_mnav) {
            doLnav = true;
        } else {
            doLnav = false;
        }
        if(m_obj.display == 'true') {
            mstate = '';
            //alert("m_opj.name: " + m_obj.name + "\nm_obj.display: " + m_obj.display);
            this.jump_html += '<option value=""></option>';
            this.jump_html += '<option value="' + hostRoot + m_obj.link + '"';
            if( doLnav ) {
                if( ! curr_lnav || curr_lnav == 'home' ) {
                    // There isn't a current lnav or it's the home page
                    // make the jumpMenu selected item this mnav
                    this.jump_html += ' selected';
                }
                mstate = 'over';
                this.lnav_html = '<p>';
            }
            this.jump_html += '> ' + m_obj.alt.toUpperCase() + '</option>';
            for(var j in m_obj.lnav) {
                l_obj = m_obj.lnav[j];
                //alert("Doing m_obj.lnav[" + j + "], name=" + l_obj.name);
                if( l_obj.display == 'true') {
                    this.jump_html += '<option value="' + hostRoot + l_obj.link + '"';
                    if( doLnav ) {
                        // Only add this to the lnav html if this is the current m_nav and the lnav display is true
                        l_button = l_obj.alt;
                        if( ! curr_lnav || l_obj.name != curr_lnav ) {
                            // if this isn't the current lnav (page your on) then add the link
                            l_button = '<a class="side" href="' + hostRoot + l_obj.link + '">' + l_button + '</a>';
                        } else if( curr_lnav && l_obj.name == curr_lnav ) {
                            this.jump_html += ' selected';
                        }
                        this.lnav_html += l_button + '<br />';
                    }
                    this.jump_html += '> - ' + l_obj.alt + '</option>';
                }
            }
            if(doLnav) {
                this.lnav_html += '</p>';
            }
            button = new rollOverButton('mnav', m_obj, mstate, 1);
            this.mnav_html = this.mnav_html + button.html;
        }
    }
    this.jump_html += '</select>';
    //alert('Jump Select:' + this.jump_html);
    this.footer_html = getFooter();
}

// All functions below this point taken from CSScriptLib.js with modifications

function changeImagesArray(array) {
    var d = document; var img;
    for (i=0;i<array.length;i+=2) {
        img = null; var n = array[i];
        if (d.images) {
            if (d.layers) {img = findElement(n,0);}
            else {img = d.images[n];}
        }
        if (!img && d.getElementById) {img = d.getElementById(n);}
        if (!img && d.getElementsByName) {
            var elms = d.getElementsByName(n);
            if (elms) {
                for (j=0;j<elms.length;j++) {
                    if (elms[j].src) {img = elms[j]; break;}
                }
            }
        }
        if (img) {img.src = array[i+1];}
    }
}
function changeImages() {
	changeImagesArray(changeImages.arguments);
}
function newImage(arg) {
	if (document.images) {
		rslt = new Image();
		rslt.src = arg;
		return rslt;
	}
    return false;
}
function getFooter() {
    footer_link_pre = '<a class="footerlink" href="' + hostRoot;
    legal_popup = 'onclick="popUp(this.href,\'console\',400,600);return false;" target="newWin">'
    footer_link_post = '</a> &#8226; ';
    footer_html = footer_link_pre + 'index.php">Home' + footer_link_post;
	footer_html += footer_link_pre + 'products/gallery.php">Products' + footer_link_post;
    footer_html += footer_link_pre + 'wireless-broadband/overview.php">Wireless Broadband' + footer_link_post;
    footer_html += footer_link_pre + 'internet-phone-service/overview.php">Internet Phone Service' + footer_link_post;
    footer_html += footer_link_pre + 'wireless-broadband/getstarted.php">Service Plans' + footer_link_post;
    footer_html += footer_link_pre + 'store/service_areas.php">Coverage Areas' + footer_link_post;
	footer_html += footer_link_pre + 'store/order.php">Order Now' + footer_link_post;
    footer_html += footer_link_pre + 'support/support.php">Support<br />';
    footer_html += footer_link_pre + 'company/about.php">About Clearwire' + footer_link_post;
    footer_html += footer_link_pre + 'company/news/main.php">News Room' + footer_link_post;
    footer_html += footer_link_pre + 'company/careers.php">Careers' + footer_link_post;
    footer_html += footer_link_pre + 'company/contact.php">Contact Us' + footer_link_post;
    footer_html += footer_link_pre + 'support/sitemap.php">Site Map</a><br /><br />';
    footer_html += footer_link_pre + 'company/legal/copyright.htm" ' + legal_popup + '&copy; 2006 Clearwire US LLC. All rights reserved' + footer_link_post;
    footer_html += footer_link_pre + 'company/legal/terms.htm" ' + legal_popup + 'Terms of Service' + footer_link_post;
	footer_html += footer_link_pre + 'company/legal/911.htm" ' + legal_popup + '911 Information' + footer_link_post;
    footer_html += footer_link_pre + 'company/legal/privacy.htm" ' + legal_popup + 'Privacy Policy<br />';
	footer_html += footer_link_pre + 'company/legal/governance.htm" ' + legal_popup + 'Corporate Governance' + footer_link_post;
    footer_html += footer_link_pre + 'company/legal/main.htm" ' + legal_popup + 'Legal</a>';
    return footer_html;
}
