var timer;
var JUMP=10;
$(function() {
  startTicking();
});

function onLoaded() {
  startTicking();
}

function startTicking() {
  clearTimeout(timer); // shouldn't be necessary
  secondsLeft = 7*JUMP; // will become 60 immediately
  $("#countdown").html("Checking for updates in approximately <span id='updateCountdown'>60</span> seconds.");
  onTick();
}

function onTick() {
  secondsLeft-=JUMP;
  if (secondsLeft==0) {
    $(".posts").load(document.location.href+"?justtweets=1", null, onLoaded);
    $("#countdown").html("Now updating ...");
    return;
  }
  $("#updateCountdown").html(secondsLeft);
  timer = setTimeout(onTick, JUMP*1000);
}
