
var cur, hash = window.location.hash;
var domready = 0;

function appendInfo() {
	var modDates = {'home':'Thursday, January 1, 2009 at 5:14PM EST','contact':'Thursday, January 1, 2009 at 5:14PM EST','links':'Thursday, January 1, 2009 at 5:14PM EST','scouting':'Thursday, January 1, 2009 at 5:14PM EST','gallery':'Thursday, January 1, 2009 at 5:14PM EST'};

	var node = $('container').firstChild;
	while (node) {
		if (node.id && node.id != "nav") {
			var copy = document.createElement("div");
			copy.id = "copy:"+node.id;
			copy.className = "copy";
			copy.innerHTML = "Copyright &copy; 2002-2009";
			node.appendChild(copy);

			var lastmod = document.createElement("div");
			lastmod.className = "lastmod";
			lastmod.innerHTML = "Last modified " + (modDates[node.id] ? modDates[node.id] : modDates['home']);
			node.appendChild(lastmod);
		}
		node = node.nextSibling;
	}
}

function hashListener() {
	if (hash != window.location.hash) {
		hash = window.location.hash;
		if (!hash) {
			fadeTo("home");
		} else {
			fadeTo(hash.substring(1));
		}
	}
	setTimeout("hashListener()", 100);
}

function fadeIn(el) {
	var div = $(el).setStyles({display:'block', opacity: 0});
	new Fx.Style(div, 'opacity', {duration: 1000} ).start(1);
}

function fadeOut(el) {
	var div = $(el).setStyle('display', 'block');
	new Fx.Style(div, 'opacity', {duration: 1000} ).start(0);
}

function fadeTo(el) {
	if (lock()) { setTimeout("fadeTo('"+el+"')", 200); return; }
	if (document.getElementById(el) != null) {
		new Fx.Style($('navLinks'), 'opacity', {duration: 250}).start(.3);
		setTimeout("new Fx.Style($('navLinks'), 'opacity', {duration: 250}).start(1)", 1550);

		fadeOut(cur);
		setTimeout("fadeIn('"+el+"')", 1000);
		setTimeout("document.title = 'daverston.net - " + el + "'", 1000);
		cur = el;
	} else {
		fadeTo("err");
	}
}

function lock() {
	return ($(cur).style.opacity != 1);
}

function init() {
	if (domready) return;

	domready = 1;
	if (document.getElementById(cur) == null) cur = "err";

	if (hash) { cur = hash.substring(1); } else { cur = "home"; }
	hashListener();

	document.title = "daverston.net - " + cur;

	appendInfo();
	fadeIn(cur);
}

window.addEvent('domready', function(){
	init();
});
