function getTwitters(username, feedsize)
{
	var result = null;
	var scriptUrl = "../site_resources/php/getTweets.php";
	$.ajax({
		url: scriptUrl,
		type: 'get',
		dataType: 'html',
		async: false,
		data: {
			username: username,
			size: feedsize
		},
		success: function(data) {
			result = data;
		},
		timeout: 3000,
		error: function(XMLHttpRequest, textStatus, errorThrown)
		{
			result = 'Fetching tweets failed. ' + errorThrown;
		}
	});
	return result;
}

// Initialize
$(function()
{
	$('.twitter-block').each(function()
	{
		// Construct object from configs
		var configs = eval( "(" + $(this).parent().find('.configs').html() + ")" );
		if (configs == null) return false;
		
		// Get the configured tweet response
		var tweets = getTwitters(configs.username, configs.size);
		
		// Apply the response to the display
		$('#' + configs.element + ' .twitter-block').replaceWith(tweets);
	})
});

