$(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
		$('#africa').show();
		$('#americas').hide();
		$('#asia').hide();
		$('#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
		$('#africa').hide();
		$('#americas').show();
		$('#asia').hide();
		$('#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
		$('#africa').hide();
		$('#americas').hide();
		$('#asia').show();
		$('#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
		$('#africa').hide();
		$('#americas').hide();
		$('#asia').hide();
		$('#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/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;

		// Europe      
		case '/stories/innovating-romania.aspx': showEurope(); break;
		case '/stories/innovating-russia.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   
	$('a#africa-toggle').click(function() {
		$('#africa').toggle(400);
		showAfrica("go");
		return false;
	});

	// toggles americas
	$('a#americas-toggle').click(function() {
		$('#americas').toggle(400);
		showAmericas("go");
		return false;
	});

	// toggles asia
	$('a#asia-toggle').click(function() {
		$('#asia').toggle(400);
		showAsia("go");
		return false;
	});

	// toggles europe
	$('a#europe-toggle').click(function() {
		$('#europe').toggle(400);
		showEurope("go");
		return false;
	});


});

