window.onload = function() {

	// activate navigation
	(function() {
		var navigation = document.getElementById("navigation");
		var offset = navigation.offsetWidth;
		var items = navigation.getElementsByTagName("ul")[0];
		var menu = document.createElement("ul");
		menu.appendChild(document.createElement("li"));
		menu.firstChild.appendChild(document.createElement("a"));
		menu.firstChild.firstChild.href = "splash.html";
		menu.firstChild.firstChild.appendChild(document.createTextNode("menu"));
		menu.firstChild.className = "active";
		menu.style.zIndex = 2;
		navigation.insertBefore(menu,navigation.firstChild);

		
		var sliding = false;
		function slidein() {
			sliding = true;
			var dx = offset/5;
			var interval = setInterval(function() {
				if ((parseInt(items.style.marginLeft,10) || 0) >= 0) {
					items.style.marginLeft = 0;
					sliding = false;
					clearInterval(interval);
				}
				else {
					items.style.marginLeft = (parseInt(items.style.marginLeft,10) || 0) + dx + "px";
				}
			}, 50);
		}
		function slideout() {
			sliding = true;
			var dx = offset/5;
			
			var interval = setInterval(function() {
				if ((parseInt(items.style.marginLeft,10) || 0) <= -offset) {
					items.style.marginLeft = -offset + "px";
					sliding = false;
					clearInterval(interval);
					
					
				}
				else {
					items.style.marginLeft = (parseInt(items.style.marginLeft,10) || 0) - dx + "px";
				}
			}, 50);
		}



		menu.onclick = function() {
			if (sliding)
				return false;

			if (menu.firstChild.className == "active") {
				//items.style.marginLeft = -offset + "px";
				menu.firstChild.className = "";
				
				// animate for non-css-transition browsers
				slideout();
				
				
				return !/splash\.html$/.test(document.getElementById("content").contentWindow.location.href)
			}
			else {
				//items.style.marginLeft = "0px";
				menu.firstChild.className = "active";
				
				// animate for non-css-transition browsers
				slidein();

				return false;
			}
		};
		// cheap trick
		menu.onclick();
		//menu.onclick();
		
		
		// allow internal linking
		items.onclick = function(event) {
			var evt = event || window.event;
			var target = evt.target || evt.srcElement;
			
			while (target && target.nodeName.toUpperCase() != "A")
				target = target.parentNode;
			
			if (target)
				location.href = "#" + /\/([^.\/]+)\.html/.exec(target.href)[1];
		}
		var uri;
		if (location.hash) {
			switch (location.hash.substr(1)) {
				case "about":
					uri = "about.html";
					break;
				case "services":
					uri = "services.html";
					break;
				case "gallery":
					uri = "gallery.html";
					break;
				case "filmmakers":
					uri = "filmmakers.html";
					break;
				case "reviews":
					uri = "reviews.html";
					break;
				case "contact":
					uri = "contact.html";
					break;
				case "links":
					uri = "links.html";
					break;
				default:
					uri = "splash.html";
			}
			document.getElementById("content").setAttribute("src", uri);
		}
		
		
	})();




};


function preload() {
	var images = arguments;
	for (var i = 0; i < images.length; i++) {
		(function(img) {
			img.src = images[i];
		})(new Image());
	}
}



