/**
 * Handles the Twitter feed.
 *
 * @module FrancesTwiddy
 * @class Twitter
 * @author Dan Whitfield
 */
 
var Twitter = 
{
	/**
	 * Get the data and initiate the formatting.
	 * 
	 * @method initialise
	 * @public
	 * @param {Object} element
	 * @param {String} tagName
	 */
	initialise: function(element, tagName)
	{
		Utils.debugConsole("initialising twitter class");
		this._getTwitterJSON(element, tagName);
	},
	
	
	/**
	 * Make the Twitter request.
	 * 
	 * @method _getTwitterJSON
	 * @private
	 * @param {Object} element
	 * @param {String} tagName
	 */
	_getTwitterJSON: function(element, tagName)
	{
		var that = this;
		
		Utils.debugConsole("making request to twitter");
		
		$.getJSON('http://twitter.com/status/user_timeline/FrancesTwiddy.json?count=5&callback=?', function(data)
		{
			Utils.debugConsole("twitter data received");
			
			that._createListItems(data, element, tagName);
		});
	},
	
	
	/**
	 * Format the HTML and inject into the specified element.
	 * 
	 * @method _createListItems
	 * @private
	 * @param {Object} data
	 * @param {Object} element
	 * @param {String} tagName
	 */
	_createListItems: function(data, element, tagName)
	{
		Utils.debugConsole("formatting tweets");
		
		var tweetList = "";
		var totalTweets = data.length;
		
		for(var i = 0; i < totalTweets; i++)
		{
			var tweet = data[i];
			tweetList += "<" + tagName + ">" + tweet.text + "</" + tagName + ">";
		}
		
		$(element).html(tweetList);
	}
};
