﻿var period = 60000;
var countDownPage = "GetTournamentCountDown.aspx";

$(function() {
    _getRemainingTime();
});

function _getRemainingTime() {
    var start = Date.parse($("#tournamentCountDown").attr("theDate"));
    var diff = start - new Date().getTime();
    var minutes = 1000 * 60;
    var hours = minutes * 60;
    var days = hours * 24;
    var d = Math.floor(diff / days);
    diff = diff - (days * d);    
    var h = Math.floor(diff / hours);
    diff = diff - (hours * h);
    var m = Math.floor(diff / minutes);
    if (d < 0) {
        d = h = m = 0;
    }
    $("#tournamentCountDown div").eq(0).text(d + " Days");
    $("#tournamentCountDown div").eq(1).text(h + " Hours");
    $("#tournamentCountDown div").eq(2).text(m + " Mins");    
    if (d == 0 && h == 0 && m == 0) {
        $.get(countDownPage, function(data) {
            $("#tournamentCountDown").attr("theDate", data);
        });
        
    }
    setTimeout('_getRemainingTime()', period);
}
