var target = new Date("February 27, 2012 9:00:00"); // fair start time

function update_countdown() {
  diff = target - (new Date());
  if (diff<=0) diff=0; // if target is in past, display zeroes
  dday=Math.floor(diff/(60*60*1000*24));
  dwks=Math.floor(dday/7); dday=dday-dwks*7;
  dhrs=Math.floor((diff%(60*60*1000*24))/(60*60*1000));
  dmin=Math.floor(((diff%(60*60*1000*24))%(60*60*1000))/(60*1000));
  dsec=Math.floor((((diff%(60*60*1000*24))%(60*60*1000))%(60*1000))/1000);
  fields=[ Math.floor(dwks/10), dwks%10,
           Math.floor(dday/10), dday%10,
           Math.floor(dhrs/10), dhrs%10,
           Math.floor(dmin/10), dmin%10,
           Math.floor(dsec/10), dsec%10 ];
  $('table#countdown table td').each(function(index){
    $(this).text(fields[index]);
  });
  if (diff<=0) {
    // action when countdown zeroes out:
    $('table#countdown tr').html('<td class="title"><p style="text-align:center;">The <strong> 2011 FWRSEF</strong> is now underway!</p></td>');
    return; // if timer at zero, don't bother updating timer again
  }
  setTimeout("update_countdown()",1000)
}

$(document).ready(function() {
  $('table#countdown table td').html('0'); // zero out all fields
  $('table#countdown td.title p').html('Countdown to the<br/><strong>2012 FWRSEF</strong>');
  update_countdown();
});

