// only full-sized main windows include this file, so it's safe to do this here:
window.name = "main";

// this is needed for building /-relative vs. page-relative IMG URLs
var GC_SiteRoot = document.location.href.substr(0, document.location.href.indexOf('globalconnections'));
if (GC_SiteRoot.length < 2) {
	GC_SiteRoot = "/wgbh/";
}
GC_SiteRoot += 'globalconnections/';


// stubbed functions currently unused.  See nav-old.js for full functions.
function preloadNav() { }

function onNav(whichNav) { }

function offNav(whichNav) { }

function onTab(whichTab) { }

function offTab(whichTab) { }


var preloadedSubNav = false;
function preloadSubNav(subnav) {
	preloadedSubNav = false;
	if (document.images && subnav != null && subnav != "") {
		var subNavToPreload = new Array();
		var whichNav = "";

		// figure out which images we'll need
		if (subnav == "film") {
			whichNav = "film";
			var questions = new Array(
				"overview",
				"air",
				"buy",
				"clips",
				"credits",
				"transcript",
				"acrobat"
			);
			var prefixes = new Array(
				"liberia/images/subnav/film/subnav_film_"
			);
			var suffixes = new Array(
				"_on.gif",
				".gif",
				".gif"
			);
			for (var i = 0; i < questions.length; i++) {
				for (var j = 0; j < prefixes.length; j++) {
					subNavToPreload[subNavToPreload.length] = prefixes[j] + questions[i] + suffixes[j];
				}
			}
		} else if (subnav == "essays") {
			whichNav = "essa";
			var themes = new Array(
				"history",
				"uspolicy"
			);
			var prefixes = new Array(
				"liberia/images/subnav/essa/subnav_essa_"
			);
			var suffixes = new Array(
				"_on.gif",
				".gif"
			);
			for (var i = 0; i < themes.length; i++) {
				for (var j = 0; j < prefixes.length; j++) {
					subNavToPreload[subNavToPreload.length] = prefixes[j] + themes[i] + suffixes[j];
				}
			}
		} else if (subnav == "time") {
					whichNav = "time";
			var times = new Array(
				"time1",
				"time2",
				"time3",
				"time4"
			);
			var prefixes = new Array(
				"liberia/images/subnav/time/subnav_time_"
			);
			var suffixes = new Array(
				"_on.gif"
			);
			for (var i = 0; i < times.length; i++) {
				for (var j = 0; j < prefixes.length; j++) {
					subNavToPreload[subNavToPreload.length] = prefixes[j] + times[i] + suffixes[j];
				}
			}
		}
		
		
		



		// don't forget to cache the off state of the currently hot subnav
		if (hotSubNav != null && hotSubNav != "" && whichNav != "") {
			subNavToPreload[subNavToPreload.length] = "liberia/images/subnav/" + whichNav + "/subnav_" + whichNav + "_" + hotSubNav + ".gif";
		}

		// go ahead and preload them all
		var dummySubNavImages = new Array(subNavToPreload.length);
		for (var i = 0 ; i < subNavToPreload.length; i++ ) {
			dummySubNavImages[i] = new Image;
			dummySubNavImages[i].src = GC_SiteRoot + subNavToPreload[i];
		}
		preloadedSubNav = true;
	} // end if document.images
}





function onSubNav(whichNav, whichSubNav) {
	if (document.images && preloadedSubNav && whichSubNav != hotSubNav) {
		// whichNav like "ques" or "them"
		// whichSubNav like "economics" or "natresources"
		document["subnav_" + whichNav + "_" + whichSubNav].src = GC_SiteRoot + "liberia/images/subnav/" + whichNav + "/subnav_" + whichNav + "_" + whichSubNav + "_on.gif";
		if (hotSubNav && document["subnav_" + whichNav + "_" + hotSubNav]) {
			// turn off the currently-hot subnav so only one line shows up
			document["subnav_" + whichNav + "_" + hotSubNav].src = GC_SiteRoot + "liberia/images/subnav/" + whichNav + "/subnav_" + whichNav + "_" + hotSubNav + ".gif";
		}

	}
}

function offSubNav(whichNav, whichSubNav) {
	if (document.images && preloadedSubNav && whichSubNav != hotSubNav) {
		document["subnav_" + whichNav + "_" + whichSubNav].src = GC_SiteRoot + "liberia/images/subnav/" + whichNav + "/subnav_" + whichNav + "_" + whichSubNav + ".gif";
		if (hotSubNav && document["subnav_" + whichNav + "_" + hotSubNav]) {
			// turn the default subnav back on
			document["subnav_" + whichNav + "_" + hotSubNav].src = GC_SiteRoot + "liberia/images/subnav/" + whichNav + "/subnav_" + whichNav + "_" + hotSubNav + "_on.gif";
		}

	}
}




// hotNav would have been set by parent HTML page to current tab name
if (hotNav == null) {
	var hotNav = "";
}
if (hotSubNav == null) {
	var hotSubNav = "";
}
