// Roubada de senhornegocio.com.br
var ticks = 0;
function countdown()
{
  if ($('#tempo-restante').length) {
    setInterval(function(){
      var s = segundos--;
      if (s < 0) s = 0;
      
      var h = Math.floor(s / 3600);
      s -= h * 3600;
      var m = Math.floor(s / 60);
      s -= m * 60;
      
      $('#tempo-hora').html(digits(h));
      $('#tempo-minuto').html(digits(m));
      $('#tempo-segundo').html(digits(s));
      
      if (ticks++ > 500) window.location.href = window.location.href;
      
    }, 1000);
  }
}

function digits(_d)
{
  _d += '';
  if (_d.length == 1) _d = '0' + _d;
  
  var r = '';
  r += '<span class="digit d'+_d.charAt(0)+'">'+_d.charAt(0)+'</span>';
  r += '<span class="digit d'+_d.charAt(1)+'">'+_d.charAt(1)+'</span>';
  
  return r;
}
