var riotList = {
	list: {},
	intervalo: null,
	nextToLoad: 0,
	init: function(){
		jQuery.ajax({
			url: '/_services/listTweets.php',
			success: function(data){
				jQuery('#riotList').html('').css({'background': '', 'height': 'auto'});
				riotList.list = data;
				riotList.intervalo = setInterval(function() {
					riotList.loadItem(riotList.nextToLoad);
					riotList.nextToLoad = riotList.nextToLoad + 1;
					
					// Se for o ultimo, apaga o intervalo
					if (riotList.nextToLoad >= riotList.list.length) {
						clearInterval(riotList.intervalo);
					}
				}, 100);
			},
			beforeSend: function() {
				jQuery('#riotList').attr('style', 'background: url(\'/img/loading.gif\') center center no-repeat; height: 200px;');
			}
		});
	},
	loadItem: function(n){
		riotList.lastLoaded = n;
		var htmlRet = '';
		htmlRet += '<p class="twitter" style="display: none">';
			if(riotList.list[n].type == 'tw') {
				htmlRet += '<a href="http://twitter.com/agenciariot" target="_blank"><img style="margin-bottom: -3px;" border="0" src="/img/ico_twitter.gif" alt="Twitter -" /></a>';
			} else {
				htmlRet += '<a href="http://www.facebook.com/agenciariot" target="_blank"><img style="margin-bottom: -3px;" border="0" src="/img/ico_facebook.gif" alt="Facebook -" /></a>';
			}
		htmlRet += unescape(riotList.list[n].content) + '<br /><span>' + riotList.list[n].elapsed + '</span></p>';
		jQuery('#riotList').prepend(htmlRet);
		jQuery('.twitter:eq(0)').slideDown(1000);
	}
}