var Site = {

	start: function() {
		Site.twitter();
	},
	
	twitter: function() {
		var twitter_post = document.id('twitter-post');
		
		Site.loading(twitter_post);
		
		var myTwitterRequest = new Request.JSONP({
			url: 'http://twitter.com/statuses/user_timeline/jiceb.json',
			data: {
				count: '1'
			},
			noCache: false,
			onComplete: function(myTweets) {
				twitter_post.empty();
				myTweets.each(function(tweet) {
					var myElement = new Element('p',{
						html: Site.linkefy(tweet.text)
					}).injectInside(twitter_post);
	
				});
			}
		}).send();		
	},
	
	linkefy: function(text) {
		text = text.replace(/@([^ ]\w*)/g,"<a class=\"username\" href=\"http://twitter.com/$1\">@$1</a>");
	    text = text.replace(/\#([^ ]\w*)/g,"<a class=\"hashtag\" href=\"http://search.twitter.com/search?q=%23$1\">#$1</a>");
	    text = text.replace(/ http:\/\/([^ ]*)/g," <a href=\"http://$1\">http://$1</a>");
	
	    return text;
	},

	loading: function(element) {
		element.set('html', '<img src="/v2/spinner.gif" class="loading" alt="Chargement ..." />') ;
	}	

}

window.addEvent('domready', Site.start);