// 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 == "questions") {
			whichNav = "ques";
			var questions = new Array(
				"uspolicy",
				"militant",
				"women",
				"types",
				"resource",
				"nations"
			);
			var prefixes = new Array(
				"mideast/images/subnav/ques/subnav_ques_",
				"mideast/images/inside/ques/quesL_",
				"mideast/images/inside/ques/quesR_"
			);
			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 == "themes") {
			whichNav = "them";
			var themes = new Array(
				"politics",
				"religion",
				"culture",
				"economics",
				"science",
				"geography"
			);
			var prefixes = new Array(
				"mideast/images/subnav/them/subnav_them_"
			);
			var suffixes = new Array(
				"_on.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 == "timeline") {
					whichNav = "time";
			var times = new Array(
				"1",
				"2",
				"3",
				"4",
				"5",
				"6"
			);
			var prefixes = new Array(
				"mideast/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] = "mideast/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 + "mideast/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 + "mideast/images/subnav/" + whichNav + "/subnav_" + whichNav + "_" + hotSubNav + ".gif";
		}

		if (whichNav == "ques" && document["photo_topright"] && document["question_text"]) {
			// gotta swap question images
			document["photo_topright"].src = GC_SiteRoot + "mideast/images/inside/ques/quesL_" + whichSubNav + ".gif";
			document["question_text"].src = GC_SiteRoot + "mideast/images/inside/ques/quesR_" + whichSubNav + ".gif";
		}

	}
}

function offSubNav(whichNav, whichSubNav) {
	if (document.images && preloadedSubNav && whichSubNav != hotSubNav) {
		document["subnav_" + whichNav + "_" + whichSubNav].src = GC_SiteRoot + "mideast/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 + "mideast/images/subnav/" + whichNav + "/subnav_" + whichNav + "_" + hotSubNav + "_on.gif";
		}

		if (whichNav == "ques" && document["photo_topright"] && document["question_text"]) {
			// gotta swap question images
			document["photo_topright"].src = GC_SiteRoot + "mideast/images/inside/ques/quesL_" + hotSubNav + ".gif";
			document["question_text"].src = GC_SiteRoot + "mideast/images/inside/ques/quesR_" + hotSubNav + ".gif";
		}

	}
}




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