(function($){
	$(function(){
		$.ajax({
			cache: false,
			dataType: "json",
			error: function (xhr, status, error) {
				$("#tweets .loading").html("Error loading tweets...");
			},
			success: function (data, status, xhr) {
				var container = $("#tweets");
				container.find(".loading").remove();
				var tweets = container.find("ul");
				var i, li, img, p, tweet;
				for (i = 0; i < data.length; i++) {
					tweet = data[i];
					li = $("<li>");
					img = $("<img>").attr("src", tweet.account.profile_image);
					p = $("<p>").html(tweet.html);
					li.append(img).append(p);
					tweets.append(li);
				}
			},
			type: "GET",
			url: "tweets/"
		});
	});
}(jQuery));
