// JavaScript Document

$(document).ready(function() {
	
	/* ******************** *
	 * CURRENT DATE			*
	 * ******************** */
	
	var m_names = new Array("January", "February", "March",
							"April", "May", "June", "July", "August", "September",
							"October", "November", "December");
	
	var d = new Date();
	var curr_date = d.getDate();
	var curr_month = d.getMonth();
	var curr_year = d.getFullYear();
	
	var curr_date_suffix = "";	
	switch (curr_date) {
		case 1:
			curr_date_suffix = "st";
			break;
		case 2:
			curr_date_suffix = "nd";
			break;
		case 3:
			curr_date_suffix = "rd";
			break;
		case 21:
			curr_date_suffix = "st";
			break;
		case 22:
			curr_date_suffix = "nd";
			break;
		case 23:
			curr_date_suffix = "rd";
			break;
		case 31:
			curr_date_suffix = "st";
			break;
		default:
			curr_date_suffix = "th";
			break;
	}
	
	document.getElementById("span_date").innerHTML = curr_date + curr_date_suffix + " " + m_names[curr_month] + " " + curr_year;
	
	/* ******************** *
	 * CURRENT LINK			*
	 * ******************** */
	 
	var hash = unescape(location.hash.substring(1));
	if(hash == "") {
		hash = "home";
	}
	
	var url = "pages/" + hash + ".html";
	
	$.ajax({
		url: url,
		success: function(msg) {
			document.getElementById("content_stuff").innerHTML = msg;
			document.getElementById("content_icon").innerHTML = "<img src='images/icon_" + hash + ".png' alt='" + hash + "' />";
			eval("load_" + hash + "()");
		},
		error: function(xhr, ajaxOptions, thrownError) {
			document.getElementById("content_stuff").innerHTML = xhr.status + " - " + xhr.statusText;
			document.getElementById("content_icon").innerHTML = "<img src='images/icon_" + hash + ".png' alt='" + hash + "' />";
		}
	});
	
});

function openLink(hash) {
	
	location.hash = hash;
	
	var url = "pages/" + hash + ".html";
	
	$.ajax({
		url: url,
		success: function(msg) {
			document.getElementById("content_stuff").innerHTML = msg;
			document.getElementById("content_icon").innerHTML = "<img src='images/icon_" + hash + ".png' alt='" + hash + "' />";
			eval("load_" + hash + "()");
		},
		error: function(xhr, ajaxOptions, thrownError) {
			document.getElementById("content_stuff").innerHTML = xhr.status + " - " + xhr.statusText;
			document.getElementById("content_icon").innerHTML = "<img src='images/icon_" + hash + ".png' alt='" + hash + "' />";
		}
	});
}

