﻿var TITLE = 0;
var FILENAME = 1;
var SUBMENU = 2;

var navMenu = [
        ["Home", "index.htm"],
        [
            "Core Practice Areas", "core_practice_areas.htm", new Array(
				["Overview", "core_practice_areas.htm"],
                ["Reputation and Branding", "rb_overview.htm"],
                ["Corporate Communications", "cc_overview.htm"],
                ["CSR and Sustainability", "csrsus_overview.htm"],
                ["Issues Management", "im_overview.htm"],
                ["Stakeholder Engagement", "se_overview.htm"],
                ["Case Studies", "case_studies.htm"]
            )
        ],
        [
            "About Us", "about_us.htm", new Array(
                ["Chairman&rsquo;s Message", "chairman_message.htm"],
                ["Board of Directors", "board_directors.htm"],
                ["GlobeScan Team", "globescan_team.htm"],
                ["Clients", "clients.htm"],
                ["Research Partners", "partners.htm"],
                ["Affiliations", "affiliations.htm"],
                ["Quality Assurance", "quality_assurance.htm"]
            )
        ],
        [
            "Syndicated Research", "syndicated_research.htm", new Array(
                ["Overview", "syndicated_research.htm"],
                ["GlobeScan Radar", "radar_overview.htm"],
                ["The Sustainability Survey", "sose_overview.htm"],
                ["Research Findings", "findings"]
                //["Research Findings", "rf_overview.htm"]
            )
        ],
        ["Contact Us", "contact_us.htm"],
		["Careers", "careers.htm"],
        ["News Center", "news_center.htm"]
    ];

var menu = createMenu(navMenu, true);



/* On ready
------------------------------------------------*/
jQuery(document).ready(function () {
    jQuery('#navContainer').html(menu);

    // remove the right margin of the last nav element to avoid wrapping
    var lastItem = jQuery('#navContainer>ul>li:last');
    lastItem.css('margin-right', 0);

    jQuery('#navContainer ul.sf-menu').superfish({
        speed: 300,
        delay: 1000,
        dropShadows: false
        //breaks sub-sub drop down menus in IE6
        //animation: { opacity: 'show', height: 'show' }
    });
});


/* Functions
------------------------------------------------*/
function createSubMenu(title, fileName, pageList) {
    var contents = createLink(title, fileName);
    contents += createMenu(pageList, false);
    return createListItem(contents);
}

function createMenu(pageList, isRoot) {
    if (pageList == null) {
        alert('empty sub menu');
    }

    var list = '';

    if (isRoot) {
        list += '<ul class="sf-menu">';
    } else {
        list += '<ul>';
    }

    for (var i = 0; i < pageList.length; i++) {
        var page = pageList[i];

        if (page.length > 2) {
            list += createSubMenu(page[TITLE], page[FILENAME], page[SUBMENU]);
        } else {
            list += createLinkListItem(page[TITLE], page[FILENAME]);
        }
    }
    list += '</ul>';
    return list;
}

function createLinkListItem(pageTitle, pageFileName) {
    var a = createLink(pageTitle, pageFileName);
    var li = createListItem(a);
    return li;
}

function createListItem(innerHtml) {
    return '<li>' + innerHtml + '</li>';
}

function createLink(title, fileName) {
    return '<a href="' + fileName + '">' + title + '</a>';
}
