var tweet = function(data) {
	window.twitterData = data;
};

// Wed Aug 04 23:48:36 +0000 2010
var parseTwitterDate = function(stamp) {
	var months = {
		'Jan': '01', 'Feb': '02', 'Mar': '03', 'Apr': '04', 'May': '05', 'Jun': '06',
		'Jul': '07', 'Aug': '08', 'Sep': '09', 'Oct': '10', 'Nov': '11', 'Dec': '12'
	};
	
	var day = stamp.substr(8, 2);
	var month = months[stamp.substr(4, 3)];
	var year = stamp.substr(26, 4);
	var hour = stamp.substr(11, 2);
	var minute = stamp.substr(14, 2);
	
	return day + '/' + month + '/' + year + ' - ' + hour + 'h' + minute;
}

window.addEvent('domready', function() {
	try {
		window.tweetCount = 0;
		window.twitterData.each(function (tweet) {
			if (window.tweetCount == 4) return;
			window.tweetCount ++;
			var zebra = window.tweetCount % 2 ? 'odd' : 'even';
			var div = new Element('div', {
				'class': 'tweet ' + zebra
			});
			var p = new Element('p', {
				'html': tweet.text
			}).inject(div);
			var small = new Element('small', {
				'html': parseTwitterDate(tweet.created_at)
			}).inject(div);
			$('twitter').adopt(div);
		});
	} catch (err) {
	}
});

