google.load("feeds", "1");
function initialize() {
  var feed = new google.feeds.Feed("http://twitter.com/statuses/user_timeline/4591161.rss");
  feed.setResultFormat(google.feeds.Feed.XML_FORMAT);
  feed.setNumEntries(3);
  feed.load(function(result) {
	var container = document.getElementById("tweets");
	if (!result.error) {
	  var items = result.xmlDocument.getElementsByTagName("item");
	  if (items.length > 0) {
	  for (var i = 0; i < items.length; i++) {
	  
		var titleElement = items[i].getElementsByTagName("title")[0];
		var title = titleElement.firstChild.nodeValue;
		var thetitle = title.substring(10);
		thetitle = thetitle.replace(/(\bhttp:\/\/\S+(\/|\b))/gi,"<a href=\"$1\">$1</a>");
		thetitle = thetitle.replace(/[@]+[A-Za-z0-9-_]+/gi, function(u) { var username = u.replace("@",""); return u.link("http://twitter.com/"+username); })
		
		var linkElement = items[i].getElementsByTagName("link")[0];
		var thelink = linkElement.firstChild.nodeValue;
		
		var pubdateElement = items[i].getElementsByTagName("pubDate")[0];
		var pubdate = pubdateElement.firstChild.nodeValue;
		var thedate = pubdate.substring(5,16);
		var thetime = pubdate.substring(17,22);

		var theitem = document.createElement("li");
		theitem.innerHTML = thetitle + ' ';
		var permalink = document.createElement('a'); 
		permalink.setAttribute('href', thelink);
		permalink.setAttribute('class', 'nowrap date permatweet');
		permalink.setAttribute('title','Tweet\'s permalink');
		permalink.innerHTML = thetime + ', ' + thedate;
		theitem.appendChild(permalink);
		container.appendChild(theitem);
	  }
	  } else {  }
	}
  });
}
google.setOnLoadCallback(initialize);
