	var tweets = new Array();
	$(document).ready(function() {
		var tweets = new Array();
		$.getJSON('http://www.amaretto.com.uy/t.php', function(data){
			$('#last_id').val(data.last_id);
			var lines = data.lines;
				$('#tweets').append('<li><p>'+convertText(lines[0].text)+'</p><p class="id"><strong>@'+lines[0].from_user+'</strong></p></li>');
$('#tweets').append('<li><p>'+convertText(lines[1].text)+'</p><p class="id"><strong>@'+lines[1].from_user+'</strong></p></li>');
/***/
$('#4sq').append('<li><p>'+convertText(lines[2].text)+'</p><p class="id"><strong>@'+lines[2].from_user+'</strong></p></li>');
$('#4sq').append('<li><p>'+convertText(lines[3].text)+'</p><p class="id"><strong>@'+lines[3].from_user+'</strong></p></li>');
/***/			
		});
/*    $.getJSON('http://www.amaretto.com.uy/4sq.php', function(data){      
      //$('#last_id').val(data.last_id);
      var lines = data.lines;
      var i = lines.pop();
      if (i != null)
        $('#4sq').append('<li><p>'+convertText(i.text)+'</p><p class="id"><strong>@'+i.from_user+'</strong></p></li>');
      i = lines.pop();
        if (i != null)        
      $('#4sq').append('<li><p>'+convertText(i[0].text)+'</p><p class="id"><strong>@'+i[1].from_user+'</strong></p></li>');      
    });		*/
		setInterval(lT, 30000);
		setInterval(loadTweet, 5000);	
	});

	function lT() {
		$.getJSON('http://www.amaretto.com.uy/t.php?id='+$('#last_id').val(), function(data){
			if ($('#last_id').val() != data.last_id && data.last_id != 0) {
				var lines = data.lines;
				$('#last_id').val(data.last_id);
				for (i = 0; i < lines.length; i++) {
					tweets.push(lines[i]);
				}
			}
		});
	}

	function loadTweet() {
		if (tweets.length != 0) {
			var item = tweets.pop();	
			var l = $("#tweets li:last"); 
			l.remove();
			$('#tweets').prepend('<li><p>'+convertText(item.text)+'</p><p class="id"><strong>'+item.from_user+'</strong></p></li>');
			var l = $("#tweets li:first");
			l.hide(0);
			l.fadeIn(500);
		}	
	}

	function convertText(text) {
		var c = replaceURLWithHTMLLinks(text);
		c = c.replace('00c1', '\xc1');
		c = c.replace('00c9', '\xc9');
		c = c.replace('00cd', '\xcd');
		c = c.replace('00d3', '\xd3');
		c = c.replace('00da', '\xda');
		c = c.replace('00e1', '\xe1');
		c = c.replace('00e9', '\xe9');
		c = c.replace('00ed', '\xed');
		c = c.replace('00f3', '\xf3');
		c = c.replace('00f4', '\xf4');
		c = c.replace('00d1', '\xd1');
		c = c.replace('00f1', '\xf1');
		return c;
	}	

	function replaceURLWithHTMLLinks(text) {
	  var exp = /(\b(https?|ftp|file):\/\/[-A-Z0-9+&@#\/%?=~_|!:,.;]*[-A-Z0-9+&@#\/%=~_|])/ig;
	  return text.replace(exp,"<a href='$1'>$1</a>");
	}

