// Copyright Andy Lavery, 2009.  All rights reserved.
//
// Month setting: 0=January, 2=March, 11=December
// Hour is in 24 hour format. 0=12am, 15=3pm etc
// format: dateFuture = new Date(year,month-1,day,hour,min,sec)
// 6AM GMT on March 1, 2010 == 12AM Central on March 1, 2010
// Date(Year, Month-1, Day, Hour, Min, Sec)
function FireCount() {
    var dateFuture = new Date(2010,8,1,7,0,0);  // Time in GMT
    // var dateFuture = new Date(2009,8,26,22,33,0);

    // Adjust the date for the current timezone.
    var curdate = new Date();
    var gmtHours = -curdate.getTimezoneOffset()/60 - 1; // subtract 1 to get #hours from gmt.
    // E.g., for Eastern, gmtHours would be -5
    // E.g., for Central, gmtHours would be -6
    // E.g., for Mountain, gmtHours would be -7
    // E.g., for Pacific, gmtHours would be -8

    dateNow = new Date(); // Current Date
    amount = dateFuture.getTime() - dateNow.getTime();	//calc milliseconds between dates
    amount = Math.floor(amount/1000);                   //kill the "milliseconds" so just secs
    amount = amount + gmtHours * 60 * 60;	        //add GMT offset in seconds

    // If time is already past we will leave everything set to zero.
    days=0;
    hours=0;
    mins=0;
    secs=0;

    var fireAgain = false;
    if(amount > 0){
        fireAgain = true;

        days=Math.floor(amount/86400); // 86400 seconds == 1 day
        amount=amount%86400;
    
        hours=Math.floor(amount/3600); // 3600 seconds == 1 hour
        amount=amount%3600;

        mins=Math.floor(amount/60);    // 60 seconds == 1 minute
        amount=amount%60;

        secs=Math.floor(amount);
    }

    hoursPrefix = "";
    if (hours < 10) {
        hoursPrefix = "0";  // Make single digit hours have two digits
    }

    minsPrefix = "";
    if (mins < 10) {
        minsPrefix = "0";   // Make single digit minutes have two digits
    }

    secsPrefix = "";
    if (secs < 10) {
        secsPrefix = "0";   // Make single digit minutes have two digits
    }

    document.getElementById('countdownDays').innerHTML=days;
    document.getElementById('countdownHours').innerHTML= hoursPrefix +  hours;
    document.getElementById('countdownMins').innerHTML= minsPrefix + mins;
    document.getElementById('countdownSecs').innerHTML= secsPrefix + secs;

    if(fireAgain){
        setTimeout("FireCount()", 1000);
    }
}
