var path = document.location.pathname;
$(document).ready(function() {
	/*
	$("a.storyGo").live("click", function(event) {
		if(typeof window.history.pushState == "function") {
			var $this = $(this);
			var url = $this.attr("href");
			var id = url.replace("/story/view/id/","");
			window.history.pushState({ id: id }, 'Viewing item #'+ id, url);
			path = url;
			$("#content").load(url);
			
			event.preventDefault();
		}
	});
	*/
	$("#menu a, #header h1 a, a.storyGo").live("click", function(event) {
		if(typeof window.history.pushState == "function") {
			var $this = $(this);
			var url = $this.attr("href");
			window.history.pushState({url:url}, 'Viewing item #', url);
			path = url;
			$("#content").load(url);
			event.preventDefault();
		}
	});
});
window.onpopstate = function(event) {
	// remove duplicate content loading at first load
	if(document.location.pathname != path) {
		$("#content").load(document.location.pathname);
		path = document.location.pathname;
	}
	/*
	// load index
	if(document.location.pathname == "/" && document.location.pathname != path) {
		$("#content").load("/index");
	}
	
	// ugh this is stupid :D
	if(document.location.pathname == "/add" && document.location.pathname != path) {
		document.location = "/add";
	}

	// load story
	if(event.state != null) {
		if(!isNaN(event.state.id)) {
			
			if(document.location.pathname == "/story/view/id/" + event.state.id && document.location.pathname != path) {
				$("#content").load("/story/ajax/id/" + event.state.id);
			}
		}
	}
	*/
};
