jQuery(document).ready(function() {
    // menu.js 
    //
    // This file sets up a show/hide function for the stories navigation. This 
    // creates menus that collapse into sections so the menu is not so long. Also,
    // this file notes which page you are on, and opens the appropriate menu for the 
    // page, so that it can be seamless when navigating. 
    //
    // version 1.0 created by Jeremy Morgan 10/19/2009

    var domain = document.domain;

    function showAfrica(action) {
        // this sets the menus so that only the africa section shows
        jQuery('#africa').show();
        jQuery('#americas').hide();
        jQuery('#asia').hide();
        jQuery('#europe').hide();

        if (action == 'go') {
            window.location.href = "http://" + domain + "/stories/innovating-egypt.aspx";
        }
        return false;
    }

    function showAmericas(action) {
        // this sets the menus so that only the americas section shows
        jQuery('#africa').hide();
        jQuery('#americas').show();
        jQuery('#asia').hide();
        jQuery('#europe').hide();

        if (action == 'go') {
            window.location.href = "http://" + domain + "/stories/innovating-brazil1.aspx";
        }
        return false;
    }

    function showAsia(action) {
        // this sets the menus so that only the asia section shows
        jQuery('#africa').hide();
        jQuery('#americas').hide();
        jQuery('#asia').show();
        jQuery('#europe').hide();

        if (action == 'go') {
            window.location.href = "http://" + domain + "/stories/innovating-china.aspx";
        }
        return false;
    }

    function showEurope(action) {
        // this sets the menus so that only the europe section shows
        jQuery('#africa').hide();
        jQuery('#americas').hide();
        jQuery('#asia').hide();
        jQuery('#europe').show();

        if (action == 'go') {
            window.location.href = "http://" + domain + "/stories/innovating-romania.aspx";
        }
        return false;
    }

    // This is for navigation. When we're on a subpage, we want to show the menu list
    // that page originates from, so we are highlighting that area. -JM

    switch (window.location.pathname) {

        // Africa 

        case '/stories/': showAfrica(); break;
        case '/stories/Default.aspx': showAfrica(); break;
        case '/stories/innovating-test.aspx': showAfrica(); break;
        case '/stories/innovating-egypt.aspx': showAfrica(); break;
        case '/stories/innovating-libya.aspx': showAfrica(); break;
        case '/stories/innovating-nigeria.aspx': showAfrica(); break;
        case '/stories/innovating-south-africa.aspx': showAfrica(); break;
        case '/stories/innovating-uganda1.aspx': showAfrica(); break;
        case '/stories/innovating-uganda2.aspx': showAfrica(); break;

        // Americas        
        case '/stories/innovating-brazil1.aspx': showAmericas(); break;
        case '/stories/innovating-brazil2.aspx': showAmericas(); break;
        case '/stories/innovating-brazil3.aspx': showAmericas(); break;
        case '/stories/innovating-chile.aspx': showAmericas(); break;
        case '/stories/innovating-guadalajara.aspx': showAmericas(); break;
        case '/stories/innovating-puebla.aspx': showAmericas(); break;
        case '/stories/innovating-mexico.aspx': showAmericas(); break;
        case '/stories/innovating-malinalco.aspx': showAmericas(); break;
        case '/stories/innovating-sacramento.aspx': showAmericas(); break;
        case '/stories/innovating-rancho-cordova.aspx': showAmericas(); break;

        // Asia	       
        case '/stories/innovating-china.aspx': showAsia(); break;
        case '/stories/innovating-lebanon.aspx': showAsia(); break;
        case '/stories/innovating-thailand.aspx': showAsia(); break;
        case '/stories/innovating-turkey.aspx': showAsia(); break;
        case '/stories/innovating-malaysia.aspx': showAsia(); break;
        case '/stories/innovating-vietnam.aspx': showAsia(); break;

        // Europe 

        case '/stories/innovating-romania.aspx': showEurope(); break;
        case '/stories/innovating-russia.aspx': showEurope(); break;
        case '/stories/innovating-macedonia.aspx': showEurope(); break;
    }

    // These are the functions that manually toggle the sections. This is set up
    // so if you click a section it will show, and if you click it again it will hide. 

    // toggles africa   
    jQuery('a#africa-toggle').click(function() {
        jQuery('#africa').toggle(400);
        showAfrica("go");
        return false;
    });

    // toggles americas
    jQuery('a#americas-toggle').click(function() {
        jQuery('#americas').toggle(400);
        showAmericas("go");
        return false;
    });

    // toggles asia
    jQuery('a#asia-toggle').click(function() {
        jQuery('#asia').toggle(400);
        showAsia("go");
        return false;
    });

    // toggles europe
    jQuery('a#europe-toggle').click(function() {
        jQuery('#europe').toggle(400);
        showEurope("go");
        return false;
    });


});


