/*

	/global/nav.js
	
*/

window.onload = Window_load;
window.onresize = Window_size;

var bg = null;
var doc = null;
var proj = null;
var gallery = null;
var large = null;

function Window_load() {
	doc = document.getElementById("Foreground");
	bg = document.getElementById("Background").childNodes[0];
	proj = document.getElementById("Projects");
	gallery = document.getElementById("Gallery");
	
	/* Firefox does not properly update during resize */
	if (navigator.userAgent.indexOf("Firefox") != -1) {
		window.setTimeout("Firefox_size()", 10);
	}
	Window_size();
	if (proj) InitProjListing();
	if (gallery) InitGallery();
}

function Window_size() {
	if (bg.offsetWidth < doc.offsetWidth) {
		bg.style.height = "auto";
		bg.style.width = "100%";
	}
	if (bg.offsetHeight < doc.offsetHeight) {
		bg.style.width = "auto";
		bg.style.height = "100%";
	}
	if (bg.style.width != "100%") {
		bg.style.left = (((doc.offsetWidth - bg.offsetWidth) / 2) * 1) + "px";
	} else {
		bg.style.left = 0;
	}
}

function Firefox_size() {
	window.setTimeout("Firefox_size()", 10);
	Window_size();
}

function ViewProject() {
	location.href = this.href;
}

function InitProjListing() {
	var links = proj.getElementsByTagName("a");
	for (var i=0; i<links.length; i++) {
		links[i].onclick = ViewProject;
	}
}

function InitGallery() {
	large = document.getElementById("LargePhoto");
	var photos = gallery.getElementsByTagName("a");
	for (var i=0; i<photos.length; i++) {
		photos[i].onclick = ViewLarge;
	}
}

function ViewLarge() {
	large.style.backgroundImage = "url('" + this.getAttribute("full") + "')";
}

