var currenttimestamp = 0;

function update(timestamp)
{
	$("#livestate").html('Chargement des nouvelles informations en cours');

	jQuery.get("content.php", {ts: timestamp}, function (data) {

		var searchTimestamp = data.match("timestamp:([0-9]+)");
		if (searchTimestamp)
			var currentTimestamp = searchTimestamp[1];
		else
			var currentTimestamp = timestamp;
			
		if (data.match("newstuff"))
		{
			flashLiveContent();
			$("#live").prepend(data);
		}

		decremente(9, currentTimestamp);
	});
}

function decremente(temps, timestamp)
{
	if (temps > 0)
	{
		$("#livestate").html('(Rechargement automatique des informations dans ' + temps + ' secondes) ');
		setTimeout(function() {decremente(temps - 1, timestamp)}, 1000);
	}
	else
		update(timestamp);
}

function flashLiveContent()
{
	$("#live").animate({ paddingLeft: "30px", paddingRight: "-25px" }, 100)
	.animate({ paddingLeft: "-20px", paddingRight: "30px" }, 100)
	.animate({ paddingLeft: "20px", paddingRight: "-15px" }, 100)
	.animate({ paddingLeft: "-10px", paddingRight: "20px" }, 100)
	.animate({ paddingLeft: "", paddingRight: "" }, 100);
}