function loading() {
	var string = "LOADING";
	var size = 60;
	//var top = (128 - size - 30) / 2;
	var top = -32;
	var bottom = -96;
	center = "style=\"width: 98%; text-align: center;\"";
	$('b1').innerHTML = "<div id=\"b1_text\" class=\"iconText\" style=\"left: 0px; font-size:" + size + "px;\"><div id=\"b1_itext\" style=\"position: relative; bottom: " + bottom + "px;\">" + string + "</div></div>";
	$('b2').innerHTML = "<div id=\"b2_text\" class=\"iconText\" style=\"left: -128px; font-size:" + size + "px;\"><div id=\"b2_itext\" style=\"position: relative; bottom: " + bottom + "px;\">" + string + "</div></div>";
	$('b3').innerHTML = "<div id=\"b3_text\" class=\"iconText\" style=\"left: -256px; font-size:" + size + "px;\"><div id=\"b3_itext\" style=\"position: relative; bottom: " + bottom + "px;\">" + string + "</div></div>";
	$('b4').innerHTML = "<div id=\"b4_text\" class=\"iconText\" style=\"left: -384px; font-size:" + size + "px;\"><div id=\"b4_itext\" style=\"position: relative; bottom: " + bottom + "px;\">" + string + "</div></div>";
	$('c1').innerHTML = "<div id=\"c1_text\" class=\"iconText\" style=\"left: 0px; font-size:" + size + "px;\"><div id=\"c1_itext\" style=\"position: relative; top: " + top + "px;\">" + string + "</div></div>";
	$('c2').innerHTML = "<div id=\"c2_text\" class=\"iconText\" style=\"left: -128px; font-size:" + size + "px;\"><div id=\"c2_itext\" style=\"position: relative; top: " + top + "px;\">" + string + "</div></div>";
	$('c3').innerHTML = "<div id=\"c3_text\" class=\"iconText\" style=\"left: -256px; font-size:" + size + "px;\"><div id=\"c3_itext\" style=\"position: relative; top: " + top + "px;\">" + string + "</div></div>";
	$('c4').innerHTML = "<div id=\"c4_text\" class=\"iconText\" style=\"left: -384px; font-size:" + size + "px;\"><div id=\"c4_itext\" style=\"position: relative; top: " + top + "px;\">" + string + "</div></div>";
	iterateMiddle(function() { e.grow(); });
}
function do_init() {
	hideAll();
	setTimeout(function() { init(); }, 1000);
}
function init() {
	iterate(function() {
		e.onmouseover = function() { rollOn(this); };
		e.onmouseout = function() { rollOff(this); };
		e.onclick = do_main;
		e.innerHTML = "<img class='glyph' src='images/tiles/" + splashContent[x][y] + ".png' />";
	});
	
	growTiles();
}
function do_main() {
	createCookie("visited", true);
	obfuscateEmail();
	hideAll();
	setTimeout(function() { main(); }, 1000);
}
function main() {
	iterateTop(function() {
		e.innerHTML = "<img class='glyph' src='images/tiles/" + mainContent[x][y] + ".png' />";
		e.onmouseout = function() { hoverTextOut(this); };
	});
	resetBottomRow(false);
	
	$('a1').onclick = function() { go("http://activefiction.herokugarden.com", this); };
	$('a2').onclick = function() { go("/lost/", this); };
	$('a3').onclick = function() { go("/midi/", this); };
	$('a4').onclick = function() { go("/old_rezich/", this); };
	$('b1').onclick = function() { go("http://twitter.com/adamrezich", this); };
	$('b2').onclick = function() { go("http://facebook.com/adamrezich", this); };
	$('b3').onclick = function() { go("http://blog.rezich.com", this); };
	$('b4').onclick = function() { go("http://steamcommunity.com/id/108", this); };
	$('c1').onclick = function() { go("http://wakoopa.com/unniloct", this); };
	$('c2').onclick = function() { go("http://friendfeed.com/adamrezich", this); };
	$('c3').onclick = function() { go("http://unniloct.deviantart.com", this); };
	$('c4').onclick = function() { go(obfuscatedEmail, this); };
	
	iterateBottom(function() {
		e.onclick = null;
		e.onmouseover = null;
		e.onmouseout = null;
	});
	
	$('a1').onmouseover = function() { hoverText(this, "ActiveFiction", "an epic website in the works", 78); };
	$('a2').onmouseover = function() { hoverText(this, "SwanHatch", "enter The Numbers every 108 minutes (old, wip)", 90); };
	$('a3').onmouseover = function() { hoverText(this, "MIDIDB", "poorly-written MIDI database", 105); };
	$('a4').onmouseover = function() { hoverText(this, "My Old Website", "it was pretty bad", 65); };
	$('b1').onmouseover = function() { hoverText(this, "Twitter", "<div style=\"font-size: 10pt; font-variant: normal; font-weight: normal; text-align: center; margin-bottom: 4px; width: 100%;\">" + $('twitter_div').innerHTML + "</div>", 90, true); };
	$('b2').onmouseover = function() { hoverText(this, "Facebook", "now with a 108% cooler URL!", 105); };
	$('b3').onmouseover = function() { hoverText(this, "MY BLOG", "that nobody reads", 90); };
	$('b4').onmouseover = function() { hoverText(this, "Steam Community", "i play videogames a lot", 60); };
	$('c1').onmouseover = function() { hoverText(this, "Wakoopa", "check out how i spend my time on my computer", 90); };
	$('c2').onmouseover = function() { hoverText(this, "FriendFeed", "social aggregation isn't as painful as it sounds", 90); };
	$('c3').onmouseover = function() { hoverText(this, "DeviantArt", "maybe i'll actually upload something sometime", 90); };
	$('c4').onmouseover = function() { hoverText(this, "E-MAIL ME", "and tell me how awesome this design is", 90); };
	
	growTiles();
}
function go(location, obj) {
	var newObj = $(obj).cloneNode(true);
	$(obj).parentNode.insertBefore(newObj, $(obj));
	newObj.style.zIndex = "500";
	newObj.style.background = "transparent";
	Position.absolutize($(newObj));
	$(newObj).puff();
	setTimeout(function() { $(newObj).parentNode.removeChild($(newObj)); window.location = location; }, 1000);
}

function growTiles() {
	var i = 0;
	iterate(function() {
		if (i > 0) e.grow({ delay: delay * i });
		else e.grow();
		i++;
	});
	setTimeout(function() { mainReady = true; }, delay * 0.015);
}

function hideAll() {
	if (loaded) {
		iterate(function() {
			e.fade({ duration: 0.5 });
		});
	}
	else {
		loaded = true;
		iterateMiddle(function() {
			e.fade({ duration: 0.5 });
		});
	}
}
function hoverText(el, string, string2, size, centered) {
	if (mainReady) {
		rollOn(el);
		clearTimeout(overTimer);
		var top = (128 - size - 30) / 2;
		var center = "";
		if (centered == true) center = "style=\"width: 98%; text-align: center;\"";
		$('d1').innerHTML = "<div id=\"d1_text\" class=\"iconText\" style=\"left: 0px; font-size:" + size + "px;\"><div id=\"d1_itext\" style=\"position: relative; top: " + top + "px;\">&nbsp;</div><div id=\"d1_stext\" class=\"iconTextSmall\"" + center + ">&nbsp;</div></div>";
		$('d2').innerHTML = "<div id=\"d2_text\" class=\"iconText\" style=\"left: -128px; font-size:" + size + "px;\"><div id=\"d2_itext\" style=\"position: relative; top: " + top + "px;\">&nbsp;</div><div id=\"d2_stext\" class=\"iconTextSmall\"" + center + ">&nbsp;</div></div>";
		$('d3').innerHTML = "<div id=\"d3_text\" class=\"iconText\" style=\"left: -256px; font-size:" + size + "px;\"><div id=\"d3_itext\" style=\"position: relative; top: " + top + "px;\">&nbsp;</div><div id=\"d3_stext\" class=\"iconTextSmall\"" + center + ">&nbsp;</div></div>";
		$('d4').innerHTML = "<div id=\"d4_text\" class=\"iconText\" style=\"left: -384px; font-size:" + size + "px;\"><div id=\"d4_itext\" style=\"position: relative; top: " + top + "px;\">&nbsp;</div><div id=\"d4_stext\" class=\"iconTextSmall\"" + center + ">&nbsp;</div></div>";
		
		iterateBottom(function() {
			e.style.background = "transparent";
		});
		
		if (reset_d[0]) clearTimeout(reset_d[0]);
		if (grow_d[0]) clearTimeout(grow_d[0]);
		
		iterateBottom(function() {
			$("d" + y + "_stext").hide();
			if (grow_d[y]) grow_d[y].cancel();
			if (appear_d[y]) grow_d[y].cancel();
			if (reset_d[y]) reset_d[y].cancel();
		});
		
		
		grow_d[0] = setTimeout(function() {
			iterateBottom(function() {
				$("d" + y + "_text").style.background = "url('images/tiles/symbols/blank.png') #eee";
			});
			/*$('d2_text').style.background = "url('images/tiles/symbols/blank.png') #eee";
			$('d3_text').style.background = "url('images/tiles/symbols/blank.png') #eee";
			$('d4_text').style.background = "url('images/tiles/symbols/blank.png') #eee";*/
			$('d1_itext').innerHTML = string;
			$('d2_itext').innerHTML = string;
			$('d3_itext').innerHTML = string;
			$('d4_itext').innerHTML = string;
			$('d1_stext').innerHTML = string2;
			$('d2_stext').innerHTML = string2;
			$('d3_stext').innerHTML = string2;
			$('d4_stext').innerHTML = string2;
		}, delay * 4000);
		
		grow_d[1] = new Effect.Grow('d1_text', { duration: 0.5 });
		grow_d[2] = new Effect.Grow('d2_text', { duration: 0.5, delay: delay * 1 });
		grow_d[3] = new Effect.Grow('d3_text', { duration: 0.5, delay: delay * 2 });
		grow_d[4] = new Effect.Grow('d4_text', { duration: 0.5, delay: delay * 3 });
		
		iterateBottom(function() {
			appear_d[y] = new Effect.Appear('d' + y + '_stext', { duration: 0.5, delay: delay * 3 + 0.55 });
		});
	}
}
function hoverTextOut(e) {
	if (mainReady) {
		rollOff(e);
		overTimer = setTimeout(function() { resetBottomRow(true); }, delay * 4);
	}
}
function resetBottomRow(full) {
	if (reset_d[0]) clearTimeout(reset_d[0]);
	if (grow_d[0]) clearTimeout(grow_d[0]);
	
	iterateBottom(function() {
		if (grow_d[y]) grow_d[y].cancel();
		if (appear_d[y]) grow_d[y].cancel();
		if (reset_d[y]) reset_d[y].cancel();
	});
	
	reset_d[0] = setTimeout(function() {
		iterateBottom(function() {
			e.style.background = "#eee";
			e.innerHTML = "<img class='glyph' src='images/tiles/symbols/bottom.png' />";
		});
	}, delay * 4000);
	
	if (full) {
		var i = 0;
		iterateBottom(function() {
			if (i > 0) reset_d[y] = new Effect.Grow(e, { duration: 0.5, delay: delay * i });
			else reset_d[y] = new Effect.Grow(e, { duration: 0.5 });
		});
	}
}
function rollOn(e) {
	if (r_off[e]) r_off[e].cancel;
	r_on[e] = new Effect.Morph(e, {
		style: "background: #ffb;",
		duration: 0.2
	});
}
function rollOff(e) {
	if (r_on[e]) r_on[e].cancel;
	r_off[e] = new Effect.Morph(e, {
		style: "background: #eee;",
		duration: 0.6
	});
}
function createCookie(name, value, days) {
	if (days) {
		var date = new Date();
		date.setTime(date.getTime()+(days*24*60*60*1000));
		var expires = "; expires="+date.toGMTString();
	}
	else var expires = "";
	document.cookie = name+"="+value+expires+"; path=/";
}
function readCookie(name) {
	var nameEQ = name + "=";
	var ca = document.cookie.split(';');
	for (var i=0; i < ca.length; i++) {
		var c = ca[i];
		while (c.charAt(0)==' ') c = c.substring(1,c.length);
		if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
	}
	return null;
}
function eraseCookie(name) {
	createCookie(name, "", -1);
}
function row(x) {
	return String.fromCharCode(x+96);
}
function iterate(z) {
	for (x=1; x<=4; x++) {
		for (y=1; y<=4; y++) {
			e = $(row(x) + y);
			z(e);
		}
	}
}
function iterateTop(z) {
	for (x=1; x<=3; x++) {
		for (y=1; y<=4; y++) {
			e = $(row(x) + y);
			z(e);
		}
	}
}
function iterateMiddle(z) {
	for (x=2; x<=3; x++) {
		for (y=1; y<=4; y++) {
			e = $(row(x) + y);
			z(e);
		}
	}
}
function iterateBottom(z) {
	var x = 4;
	for (y=1; y<=4; y++) {
		e = $(row(x) + y);
		z(e);
	}
}
function obfuscateEmail() {
	// Email obfuscator script 2.1 by Tim Williams, University of Arizona
	// Random encryption key feature by Andrew Moulden, Site Engineering Ltd
	// This code is freeware provided these four comment lines remain intact
	// A wizard to generate this code is at http://www.jottings.com/obfuscator/
	coded = "qPqc@Ub0YiO.i2c"
	key = "v2cd8arXN4kOb61tziPwqUGxfQIFpMj0YRALsn9KJDVHBZ3Tom7uCyEgSWhe5l"
	shift = coded.length
	obfuscatedEmail = ""
	for (i=0; i<coded.length; i++) {
		if (key.indexOf(coded.charAt(i))==-1) {
			ltr = coded.charAt(i)
			obfuscatedEmail += (ltr)
		}
		else {     
			ltr = (key.indexOf(coded.charAt(i))-shift+key.length) % key.length
			obfuscatedEmail += (key.charAt(ltr))
		}
	}
	obfuscatedEmail = "mailto:" + obfuscatedEmail;
}

document.onselectstart = function() { return false; };
if (window.sidebar) {
	document.onmousedown = function() { return false; };
	document.onclick = function() { return true; };
}

splashContent = Array();
splashContent[1] = Array();
splashContent[2] = Array();
splashContent[3] = Array();
splashContent[4] = Array();
splashContent[1][1] = "letters/a";
splashContent[1][2] = "letters/d";
splashContent[1][3] = "letters/a";
splashContent[1][4] = "letters/m";
splashContent[2][1] = "letters/period";
splashContent[2][2] = "letters/r";
splashContent[2][3] = "letters/e";
splashContent[2][4] = "letters/z";
splashContent[3][1] = "letters/i";
splashContent[3][2] = "letters/c";
splashContent[3][3] = "letters/h";
splashContent[3][4] = "letters/period";
splashContent[4][1] = "letters/c";
splashContent[4][2] = "letters/o";
splashContent[4][3] = "letters/m";
splashContent[4][4] = "symbols/enter";

mainContent = Array();
mainContent[1] = Array();
mainContent[2] = Array();
mainContent[3] = Array();
mainContent[4] = Array();
mainContent[1][1] = "symbols/activefiction";
mainContent[1][2] = "symbols/swanhatch";
mainContent[1][3] = "symbols/mididb";
mainContent[1][4] = "symbols/old";
mainContent[2][1] = "symbols/twitter";
mainContent[2][2] = "symbols/facebook";
mainContent[2][3] = "symbols/blog";
mainContent[2][4] = "symbols/steam";
mainContent[3][1] = "symbols/wakoopa";
mainContent[3][2] = "symbols/friendfeed";
mainContent[3][3] = "symbols/deviantart";
mainContent[3][4] = "symbols/email";

mainURL = Array();
mainURL[1] = Array();
mainURL[2] = Array();
mainURL[3] = Array();
mainURL[4] = Array();
mainURL[1][1] = "http://activefiction.herokugarden.com";
mainURL[1][2] = "/swanhatch/";
mainURL[1][3] = "/midi/";
mainURL[1][4] = "/old_rezich/";
mainURL[2][1] = "http://twitter.com/adamrezich";
mainURL[2][2] = "http://facebook.com/people/@/766832641";
mainURL[2][3] = "http://blog.rezich.com";
mainURL[2][4] = "http://steamcommunity.com/id/108";
mainURL[3][1] = "http://wakoopa.com/unniloct";
mainURL[3][2] = "http://friendfeed.com/adamrezich";
mainURL[3][3] = "http://unniloct.deviantart.com";
mainURL[3][4] = "mailto:adam@rezich.com";

grow_d = Array();
grow_d[0] = null;
grow_d[1] = null;
grow_d[2] = null;
grow_d[3] = null;
grow_d[4] = null;

reset_d = Array();
reset_d[0] = null;
reset_d[1] = null;
reset_d[2] = null;
reset_d[3] = null;
reset_d[4] = null;

appear_d = Array();
appear_d[1] = null;
appear_d[2] = null;
appear_d[3] = null;
appear_d[4] = null;

overTimer = null;
delay = 0.02;

r_on = Array();
r_off = Array();

obfuscatedEmail = "#";

mainReady = false;

loaded = false;