Date.ext.locales['fr'] = {
	a: ['dim', 'lun', 'mar', 'mer', 'jeu', 'ven', 'sam'],
	A: ['dimanche', 'lundi', 'mardi', 'mercredi', 'jeudi', 'vendredi', 'samedi'],
	b: ['jan', 'fév', 'mar', 'avr', 'mai', 'jun', 'jui', 'aoû', 'sep', 'oct', 'nov', 'déc'],
	B: ['janvier', 'février', 'mars', 'avril', 'mai', 'juin', 'juillet', 'août', 'septembre', 'octobre', 'novembre', 'décembre'],
	c: '%a %d %b %Y %T %Z',
	p: ['', ''],
	P: ['', ''],
	x: '%d.%m.%Y',
	X: '%T'
};

function relative_time(ThenStr){
	var ThenArr = ThenStr.split(' ');
	var ThenStrIETF = ThenArr[0] + ', ' + ThenArr[2] + ' ' + ThenArr[1] + ' ' + ThenArr[5] + ' ' + ThenArr[3] + ' GMT' + ThenArr[4];
	var Then = new Date(ThenStrIETF);
	var Now = new Date();
	if (Then.getFullYear() != Now.getFullYear()) {
		return Then.strftime("le %d %B %Y");
	} else if (Then.getMonth() != Now.getMonth()) {
		return Then.strftime("le %d %B");
	} else if (Now.getDate() > Then.getDate() + 6) {
		return Then.strftime("le %d %B");
	} else if (Now.getDate() > Then.getDate() + 1) {
		return Then.strftime("%A dernier");
	} else if (Then.getDate() != Now.getDate()) {
		return Then.strftime("hier à %Hh%M");
	} else if (Now.getHours() > Then.getHours() + 1) {
		return Then.strftime("aujourd'hui à %Hh%M");
	} else {
		Delta = (Now.getTime() - Then.getTime()) / 1000;
		if (Delta < 60) {
			return "à l'instant";
		} else if (Delta < 120) {
			return "il y a environ une minute";
		} else if (Delta  < 3600) {
			return "il y a " + (parseInt(Delta / 60)).toString() + " minutes";
		} else if (Delta  < 7200) {
			return "il y a environ une heure";
		} else {
			return "il y a " + (parseInt(Delta / 3600)).toString() + " heures";
		}
	}
}

function parseURLs(text) {
	return text.replace(/((https?|s?ftp|ssh)\:\/\/[^"\s\<\>]*[^.,;'">\:\s\<\>\)\]\!])/g,function(F){return'<a href="'+F+'">'+F+"</a>"}).replace(/\B@([_a-z0-9]+)/ig,function(F){return F.charAt(0)+'<a href="http://www.twitter.com/'+F.substring(1)+'">'+F.substring(1)+"</a>"});
}

function loadTweets(carousel, state) {
	//$.getJSON("http://twitter.com/statuses/user_timeline/lesflibustiers.json?callback=?", null, function(data) {
        $.getJSON("http://api.twitter.com/1/statuses/user_timeline/lesflibustiers.json?count=10&callback=?", null, function(data) {
		$.each(data, function(index, value) {
			var date = $("<div/>").html(relative_time(value.created_at)).addClass('date-small');
			date.prepend("<span class='left' />").append("<span class='right'>")
			var tweet = $("<div />").html(parseURLs(value.text)).append(date);
			carousel.add(index + 1, tweet);
		});
		carousel.size(data.length);
		carousel.buttons()
	});
}
