var debateStamp = new Date("October 22, 2012 21:00:00 EDT");

var days = 1000*60*60*24;

var hours = 1000*60*60;

var mins = 1000*60;

var secs = 1000;

 

function paddItOut(x){

    if (x < 10) {

        return "0" + x;

    } else {

        return x;

    }

}

 

 

function calcCountdown(){

    var nowStamp = new Date();

    var countdown = debateStamp - nowStamp;

    var daysLeft = hoursLeft = minsLeft = secsLeft = 0;

    if (countdown > 0) {

        var daysLeft = Math.floor(countdown / days);

        var hoursLeft = Math.floor(countdown / hours) - daysLeft*24;

        var minsLeft = Math.floor(countdown / mins) - (daysLeft*24*60 + hoursLeft*60);

        var secsLeft = Math.floor(countdown / secs) - (daysLeft*24*60*60 + hoursLeft*60*60 + minsLeft*60);

        $("#countdays span").html(daysLeft);

        $("#counthours span").html(paddItOut(hoursLeft));

        $("#countmins span").html(paddItOut(minsLeft));

        $("#countsecs span").html(paddItOut(secsLeft));

    }

}

 

 

$(document).ready(function(){

    $.get('/inc/countdown.html', function(data) {

                   $('#countdown').append(data);

    }, "html");

    calcCountdown();

    setInterval("calcCountdown()",1000);

});