(function(){
	
	window.twitter_user = "EckyPro";
	
	$ = window.jQuery;
	
	var twitter = {
		
		init: function(){
			
			if($("#twitter").length < 1) return false;
			
			$.ajax({
			  type: "GET",
			  url: "js/twitter.php?"+Math.random(),
			  dataType: "xml",
			  success: this.parseTweets,
			  error: this.forceQuit
			});
			
		},
		
		forceQuit: function(){
			
			$("#twitter").html("Could not retrieve the latest tweet. Sorry.");
			
		},
		
		parseTweets: function(xml){
			
			// Got the data, make the UL's
			
			_item = $("rss > channel > item", xml);
			
			tweet = $("description", _item);
			date = $("pubDate", _item);
			link = $("link", _item);
			
			tweet = String(tweet[0].firstChild.nodeValue).replace(""+window.twitter_user+": ", "");
			
			$("#twitter").html("<a href=../Theme/js/\""+link[0].firstChild.nodeValue+"\" target=\"_blank\">"+tweet+"</a>");	
			
			date = new Date(date[0].firstChild.nodeValue);
			
			if($("#twitter_date").length > 0){
				
				$("#twitter_date").html(""+date.getDate()+"/"+(date.getMonth()+1)+", "+date.getHours()+":"+date.getMinutes());
				
			}
			
		}
			
		
	}
	
	$(document).ready(function(){
		
		window.twitter = twitter;
		
		twitter.init();
		
	});
	
})();