
var targetDate = "11/28/2006 9:00 AM";
var format = "%%D%% days %%H%% hrs %%M%% mins %%S%% sec";
var endString = "The Expedition Has Begun!";
var countStep = -1;

function calcAge(secs,num1,num2){s=((Math.floor(secs/num1))%num2).toString();if(s.length<2){s="0"+s;}return s;}
function createWrapper(){var countdown=document.getElementById("countdown");var span=document.createElement("span");span.id="cd";countdown.appendChild(span);}

function CountBack(secs) {
  var countdown=document.getElementById("countdown");
  var span=document.getElementById('cd');
  if (span){
    var text='';    
    if(secs<0){text=endString;}
    else { 
      text=format.replace(/%%D%%/g,calcAge(secs,86400,100000));
      text=text.replace(/%%H%%/g,calcAge(secs,3600,24));
      text=text.replace(/%%M%%/g,calcAge(secs,60,60));
      text=text.replace(/%%S%%/g,calcAge(secs,1,60));
    }    
    if(span.childNodes.length>0){span.removeChild(span.firstChild);span.appendChild(document.createTextNode(text));}
    else{span.appendChild(document.createTextNode(text));}
    if(secs>0){setTimeout("CountBack(" + (secs+countStep) + ")", SetTimeOutPeriod);}
  }
}

createWrapper();
countStep = Math.ceil(countStep);
var SetTimeOutPeriod = (Math.abs(countStep)-1)*1000 + 990;
var dthen = new Date(targetDate);
var dnow = new Date();
var ddiff=(countStep>0)?(new Date(dnow-dthen)):(new Date(dthen-dnow));
gsecs = Math.floor(ddiff.valueOf()/1000);
CountBack(gsecs);
