var myCountdown = new Array();


var repeat = false;





function checkPlural(noun, value) {


  noun = ((value == 1)) ? noun : (noun += "s");


  return noun;


}





function doCountdown() {


  for (i = 0; i < myCountdown.length; i++) {


    if ( myCountdown[i].isRaffleSellout )


    {


    	updateDisplay( myCountdown[i].aftersellout, myCountdown[i].tagID );


        suppressSecondLine = true;


    }


    else if ( !myCountdown[i].expired ) 


    {


      var localFinalCutoff = new Date( finalDrawCutoffDate );


      var currentDate = new Date();


      var eventDate = myCountdown[i].eventDate;


      var timeLeft = new Date();


      var eventMessage = myCountdown[i].afterevent;


      timeLeft = eventDate - currentDate;


      msPerDay = 24 * 60 * 60 * 1000;


      msPerHour = 60 * 60 * 1000;


      msPerMin = 60 * 1000;


      msPerSec = 1000;


      daysLeft = Math.floor(timeLeft / msPerDay);


      hoursLeft = Math.floor((timeLeft % msPerDay) / msPerHour);


      minsLeft = Math.floor(((timeLeft % msPerDay) % msPerHour) / msPerMin);


      secsLeft = Math.floor((((timeLeft % msPerDay) % msPerHour) % msPerMin) / msPerSec);


      day = checkPlural("day", daysLeft);


      hour = checkPlural("hour", hoursLeft);


      minute = checkPlural("minute", minsLeft);


      second = checkPlural("second", secsLeft);


      if ((daysLeft == 0) && (hoursLeft < 24) /*&& (minsLeft == 0) && (secsLeft == 0)*/) {


        updateDisplay(myCountdown[i].onevent, myCountdown[i].tagID);


        repeat = true;


        suppressSecondLine = true;


      }


      else 


      {


        if (daysLeft <= -1) 


        {


          updateDisplay(eventMessage, myCountdown[i].tagID);


          suppressSecondLine = true;


	  myCountdown[i].expired = true;


	  repeat = false;


        }


        else 


        {


          updateDisplay(myCountdown[i].event + " " + daysLeft + " " + day + " " + hoursLeft + " " + hour + " " + minsLeft + " " + minute, myCountdown[i].tagID);


          repeat = true;


          suppressSecondLine = false;


        }


      }


    }


  }


  if ( repeat ) 


  {


    repeat = false;


    window.setTimeout("doCountdown()", 1000);


  }


  else {


    return;


  }


}





function addCountdown(countdown) {


  myCountdown[myCountdown.length] = countdown;


  return;


}





function Countdown() {


  this.tagID = "";


  this.eventDate = new Date();


  this.event = "";


  this.onevent = "";


  this.afterevent = "";


  this.aftersellout = "";


  this.expired = false;


  this.isRaffleSellout = false;


}





var mycountdown = new Countdown();


var localAppCutoff = new Date( appreciationDrawCutoffDate );


var localEBCutoff = new Date ( earlyBirdDrawCutoffDate );


var localFinalCutoff = new Date( finalDrawCutoffDate );


var oneDayInThePast = new Date( now ) - ( 1000 * 60 * 60 * 24 );
var rightNow = new Date( now );






with (mycountdown) {


  tagID = "mycountdowndiv";


  


  if ( rightNow <= localAppCutoff )


  {


  	eventDate = localAppCutoff;


	onevent = "Appreciation Draw Eligibility ends at midnight!!";


	afterevent = "Appreciation Draw Eligibility is now closed.";


  }


  else if ( rightNow <= localEBCutoff )


  {


  	eventDate = localEBCutoff;


	onevent = "Early Bird Drawing Eligibility ends at midnight!!";


	afterevent = "Early Bird Drawing Eligibility is now closed.";


  }


  else


  {


  	eventDate = localFinalCutoff;


	onevent = "Final Drawing Eligibility ends at midnight!!";


	afterevent = "Final Drawing Eligibility is now closed.";


  }


  


  isRaffleSellout = isSellout;


  aftersellout = "The Health Wealth Raffle is sold out."; 


  event = "";


}


addCountdown(mycountdown);
