


// To make the Upcoming Events page visible, set this line to true. To hide it, set this line to false.
var show_upcoming_events = true;

/*

This script defines an array representing the site navigation outline, then builds the left-side navigation menu based on that array and the current page URL.

The site outline is an array of page objects.

pageObject format:

	{	name: "Page Name", URL: "page URL",
		subPages: [{pageObject}, {pageObject}, etc...] }

*/

var site_outline = [
	
	{	name: "The Film & More", 			URL: "description.htm",
		subPages: [
			{ name: "Film Description",		URL: "description.htm" },
			{ name: "Transcript",			URL: "transcript.htm" },
			{ name:	"Further Reading",		URL: "further_reading.htm" },
			{ name: "Credits",				URL: "credits.htm" },
			{ name: "Acknowledgements",		URL: "acknowledgements.htm" },
			{ name: "Poster",				URL: "poster.htm" }
		] },
	
	{	name: "Special Features",			URL: "design_competition.htm",
		subPages: [
			{ name:	"Design Competition",	URL: "design_competition.htm" }
		] },
	
	{	name: "Timeline",					URL: "timeline.htm" },
	
	{	name: "Gallery",					URL: "gallery.htm",
		subPages: [
			{ name: "Historical",			URL: "historical_photos.htm" },
			{ name:	"Construction",			URL: "construction_photos.htm" },
			{ name:	"Current Photos", 		URL: "current_photos.htm" },
			{ name:	"Behind the Scenes",	URL: "behind_the_scenes.htm" }
		] },
	
	{	name: "Teacher's Guide",			URL: "teachersGuide/index.html" },
	
	{	name: "Buy the DVD",				URL: "buy_dvd.htm" },
	
	{	name: "Civil Pictures",				URL: "http://www.civilpictures.org", newWindow:true },
	
	{	name: "View Trailer",				URL: "trailer.htm", newWindow:true }
];

if (show_upcoming_events) site_outline[0].subPages.push({ name: "Upcoming Events",	URL: "events.htm" });

function currentSection() {
	for (var i in site_outline) {
		if (window.location.href.indexOf(site_outline[i]['URL']) != -1) return site_outline[i];
		if (site_outline[i].subPages != undefined) {
			for (j in site_outline[i].subPages) {
				if (window.location.href.indexOf(site_outline[i].subPages[j]['URL']) != -1) return site_outline[i];
			}
		}
	}
	return -1;
}

function writeNavOption(pageObj) {
	var LI = document.createElement("li");
	var linkText = document.createTextNode(pageObj.name);
	if (pageObj['URL'] != undefined && window.location.href.indexOf(pageObj['URL']) == -1) {
		var A = document.createElement("a");	
		LI.appendChild(A);
		A.href = pageObj.URL;
		if (pageObj['newWindow']) A.target="_blank";
		A.appendChild(linkText);
	} else {
		LI.appendChild(linkText);
	}
	if (currentSection() == pageObj) {
		if (pageObj['subPages'] != undefined) {
			var subUL = document.createElement("ul");
			for (var subPage=0; subPage<pageObj.subPages.length; subPage++) {
				var subOption = writeNavOption(pageObj.subPages[subPage]);
				subUL.appendChild(subOption);
			}
			LI.appendChild(subUL);
		}
	}
	return LI;
}

function buildNav() {
	var navUL = document.createElement("ul");
	document.getElementById("site_nav").appendChild(navUL);	
	for (var section=0; section<site_outline.length; section++) {
		var navOption = writeNavOption(site_outline[section]);
		navUL.appendChild(navOption);
		
		if (section<site_outline.length-1) {
			var sep = document.createElement("div");
			sep.className = "nav_seperator";
			navUL.appendChild(sep);
		}
	}
}

buildNav();
