// setting properties
var TWITTER_SCREEN_NAME = "puntgroc"; // Screen name of twitter account you want to get last tweets
var tweets=5; // How many tweets
var speed=10; // in seconds


// do not touch under here unless you know what to do
//var URL="/templates/PUBLIC/js/php/proxy.php?url=http://api.twitter.com/1/statuses/user_timeline.rss?screen_name=";
var URL="http://www.gimnaspuntgroc.com/templates/PUBLIC/js/proxy.php";
var links=new Array();
var id=0;


// load tweets via RSS
function loadTweets()
{
	//$("#widget_title").text("Last Tweets by "+TWITTER_SCREEN_NAME);
	//$("#counter").text(id+1+"/"+tweets);

	$.ajax({
			type: "GET",
			//url: URL+TWITTER_SCREEN_NAME,
			url: URL,
			dataType: "xml",
			success: function(xml) 
			{
				$(xml).find('item').each(function(value)
				{
					if(value < tweets)
					{
						//$("#tweets").append('<div id="ciao" style="position:absolute; width:550px; left:'+value*570+'px;">'+$(this).find("title").text()+'<br/><strong>'+$(this).find("pubDate").text()+'</strong></div>');
						var str = $(this).find("title").text();
						
						$("#tweets").append('<div id="ciao" style="position:absolute; width:585px; left:'+value*605+'px;">' + str.replace("puntgroc:", "") + '</div>');
						links[value]=$(this).find("link").text();
					}
				});
				
				$("#container").css("background","none");
				//addListeners();
				startTimer();
			}
	});
}


// add mouse events
function addListeners()
{
	$("#tweets").click(function()
	{
	    $(location).attr("href",links[id]);
	});
}


// start timer
function startTimer()
{
	var t=setTimeout("increaseID()",speed*1000);
}


// increase id
function increaseID()
{
	id++;
	
	if(id >= links.length)
		id=0;
	
	$("#holder").animate({"left": "-"+id*605+"px"}, 3000);
	//$("#counter").text(id+1+"/"+tweets);
	
	startTimer();
}
