var Construct = new function ConstructObject() {
	this.hash;
	this.model;
	this.method;
	
	this.init = function() {
		Construct.parseHash();
		Construct.load();
	};
	
	this.parseHash = function() {
		Construct.hash		= document.location.hash.replace(/^#\/?/, "");
		Construct.hash_args	= Construct.hash.replace(/\/$/, "").split(/\//);
	};
	
	this.load = function() {
		switch(Construct.hash_args[0]) {
			case "press":
				press_release_id = Construct.hash_args[1];
				if(/^[\d]+$/.test(press_release_id)) {
					getPressRelease(press_release_id);
				}
				break;
			case "news":
				news_item_id = Construct.hash_args[1];
				if(/^[\d]+$/.test(news_item_id)) {
					getNews(news_item_id);
				}
				break;
			default:
				// foo
		}
	};
};

String.prototype.capitalize = function() {
	return this.replace(/\w+/g, function(a) {
		return a.charAt(0).toUpperCase() + a.substr(1);
	});
};

function postData(cname, cnumber, corganization, cemail, csubject, ccomments) {
	$.ajax({
		type: "POST",
		url: "post.contact.php",
		data: {
			name: cname,
			number: cnumber,
			org: corganization,
			email: cemail,
			subject: csubject,
			comments: ccomments
		},
		success: function(response) {
			// foo
		}
	});
}

function getPressRelease(press_release_id) {
	window.location.hash = "/press/" + press_release_id;
	$.ajax({
		type: "GET",
		url: "/press_release.php",
		dataType: "xml",
		data: { id: press_release_id },
		success: function(xml) {
			$("#dither").css({ display: "block", height: $(document).height() }).fadeTo(1, 0.95);
			$("#popover .title").text($(xml).find("title").text());
			$("#popover .date").text($(xml).find("date").text());
			$("#popover .content").html($($(xml).find("body").text()));
			$("#popover").css({ display: "block", heght: $("#popover .content").outerHeight() });
		}
	});
}

function getNews(news_item_id) {
	window.location.hash = "/news/" + news_item_id;
	$.ajax({
		type: "GET",
		url: "/news_item.php",
		dataType: "xml",
		data: { id: news_item_id },
		success: function(xml) {
			var short = $(xml).find("short").text();
			var long = $(xml).find("long").text();
			
			$("#dither").css({ display: "block", height: $(document).height() }).fadeTo(1, 0.95);
			$("#popover .title").text($(xml).find("title").text());
			$("#popover .date").text($(xml).find("date").text());
			$("#popover .content").html(!!long ? $(long) : $(short));
			$("#popover").css({ display: "block", heght: $("#popover .content").outerHeight() });
		}
	})
}

$(document).ready(function() {
	$("#dither, #popover .links a.close").click(function() {
		$("#dither").css({ display: "none" });
		$("#popover").css({ display: "none" });
		return false;
	});
	
	Construct.init();
});

var so = new SWFObject("home.swf", "sotester", "900", "800", "8", "#242424");
so.addParam("wmode", "transparent");
so.write("flashcontent");