	function showtweet(tweet) {
		var tw = '';
		$.each(tweet, function() {
			tw += '<p>'+parse_my_tweet(this["text"])+'<em>'+parse_my_date(this["created_at"])+'</em></p>';
		});
		if( tw!='' ) {
			$('#twitter').append(tw);
			$('#twitter').fadeIn('slow');
		}
	}
	
	function parse_my_tweet(txt) {
		var liens = /((https?|s?ftp|ssh)\:\/\/[^"\s\<\>]*[^.,;'">\:\s\<\>\)\]\!])/gi;
		var users = /@(\w+)/gi;
		var hashtags = /#(\w+)/gi;

		txt = txt.replace(liens,'<a href="$1">$1</a>');
		txt = txt.replace(users,'@<a href="http://twitter.com/$1">$1</a> ');
		txt = txt.replace(hashtags,'<a href="http://search.twitter.com/search?q=%23$1">#$1</a> ');

		return txt;
	}
	
	function parse_my_date(ch) {
		var date = new Date;
		var now = new Date;
		date.setTime(Date.parse(ch));
		
		var ecart = ((now - date) / 1000);
		var ecart_min = Math.floor(ecart / 60);
		if (ecart_min == 0) { return '- il y a moins d\'une minute'; }
		if (ecart_min == 1) { return '- il y a une minute'; }
		if (ecart_min < 45) { return '- il y a ' + ecart_min + ' minutes'; }
		if (ecart_min < 90) { return '- il y a une heure'; }
		if (ecart_min < 1440) { return '- il y a ' + Math.floor(ecart_min / 60) + ' heures'; }
		if (ecart_min < 2880) { return '- hier'; }
		if (ecart_min < 43200) { return '- il y a ' + Math.floor(ecart_min / 1440) + ' jours'; }
		return '- il y a longtemps';
	}
	
	setTimeout(function() {
		$.ajax({
		'url': 'http://twitter.com/statuses/user_timeline/soundunited.json',
		'data': { count: 3 },
		'success': showtweet,
		'dataType': 'jsonp'});
	}, 999);

