$(document).ready(function () { init(); });

function init() {
//	$.get("getcache.php", null, function(data, textStatus, jqXHR) { $("#statustext").html($(".latest-status .entry-content", data)[0].innerText); }, "text");
//	$.get("getfeed.php", null, function(data, textStatus, jqXHR) { 
//		var status = $(".latest-status .entry-content", data)[0].innerText;
//		$("#statustext").html(status);
//		$.post("cache.php", { "status": status }, null, null); 
//	}, "html");

	$.getJSON("http://twitter.com/status/user_timeline/antstandring.json?count=1&callback=?", function(data) { 
		$("#statustext").html(data[0].text); 
		$(".loading").removeClass("loading");
	}).fail(function () { 
		$(".loading").removeClass("loading");
		$("#statustext").html("working hard somewhere on something important"); 
	});
	
	// display any content divs that are set to open
	$(".open").css("display", "block");

	// add button behaviours
	$(".email").html("astandring@yahoo.co.uk");
	$(".menuitem a").click(function() { toggle($(this)); });
	$(".email").click(function() { window.open("mailto:astandring@yahoo.co.uk", "_self"); });
	$(".email").hover(function() { $(this).css("opacity", "0.65");}, function(){ $(this).css("opacity", "1"); });
}

function toggle(node) {
	console.log(node);
	var divSelector = "div#"+node[0].id+"panel";
	if($(divSelector).hasClass("open")) {
		node.removeClass("active");
		$(divSelector).removeClass("open");
		$(divSelector).slideUp("fast");
	} else {
		node.addClass("active");
		$(divSelector).addClass("open");
		$(divSelector).slideDown("slow");
	}
	node.css("opacity", "1");
}

function twitterCallback(o) {
	console.log(o[0]);
	console.log(o[0].text);
	console.log($(".menuitem"));
	$(".loading").removeClass("loading");
	$("#statustext").html(o[0].text);
}
		
