
function formatDate(d) {
	d_arr = d.split("T");
	date = d_arr[0];
	date = date.split("-");
	var month_names = ["","January", "February", "March","April", "May", "June","July", "August", "September","October", "November", "December"];
	m_month = stripLeading(date[1]);
	m_day = stripLeading(date[2]);
	m_year = date[0];
	date = month_names[m_month]+" "+m_day+", "+m_year;
	return date;
}

function stripLeading(d) {
	match = d.match(/^(0*)(\d*)/);
	if (match) {
		d = match[2];
	}
	return d;
}

var statuses = new Array();
var index = 0;

$(document).ready(function() {
	var twitter = $(".twitter");
	var newscontent = $(".newscontent");
	
	twitter.html("Loading...");
	newscontent.html("Loading...");

	function setTwitterHtml() {
		twitter.html("");
		for (var i = 0; i < statuses.length; i++) {
			twitter.append("<div style='padding:3px 0;border-bottom: 1px dotted #666666;'>" + statuses[i] + "</div>");
		}
	}

	$.getJSON("http://twitter.com/statuses/user_timeline/apluscomputer.json?callback=?",
		function(data) {
			for (var i = 0; i < data.length && i < 3; i++) {
				statuses.push(data[i].text);
			}

			setTwitterHtml();
		}
	);
	
	$.getJSON("http://apluscomputerservicesblog.blogspot.com/feeds/posts/default?alt=json-in-script&max-results=1&orderby=published&callback=?",
		function(data) { 
			for (var i = 0; i < data.feed.entry.length; i++) {
				var item = data.feed.entry[i];

				$(".newstitle").text(item.title.$t);
				$(".newsdate").text(formatDate(item.published.$t));
				newscontent.html(item.content.$t);
			}
			
			var welcome_area = $(".welcomearea");
			var news_area = $(".newsarea");
			if (welcome_area.height() > news_area.height()) {
				welcome_area.css("border-right", "1px solid #666666");
			} else {
				news_area.css("border-left", "1px solid #666666");
			}
		}
	);
});
