function countDown(){
  if(document.getElementById && document.createTextNode){
    var showText = "Wedding date countdown: ";
    var displayID = "displayDate";
    var endDate = new Date(2008, 5, 28, 14, 0, 0, 0);  // Year, Month, Day, Hour, Minute, Second, Millisecond
    var nowDate = new Date();
    var timeDifference = Math.floor( (endDate.getTime() - nowDate.getTime()) / 1000);  // Remove milliseconds - not needed
    delete nowDate;

    if(timeDifference > 0){
      var days = Math.floor(timeDifference / 86400);   timeDifference %= 86400;
      var hours = Math.floor(timeDifference / 3600);   timeDifference %= 3600;
      var mins = Math.floor(timeDifference / 60);      timeDifference %= 60;
      var secs = Math.floor(timeDifference);

      // Build time string.
      if(days > 0){ showText += days + ' day' + ((days == 1) ? ' ' : 's '); }
      if(hours > 0){ showText += hours + ' hour' + ((hours == 1) ? ' ' : 's '); }
      if(mins > 0){ showText += mins + ' minute' + ((mins == 1) ? ' ' : 's '); }
      showText += secs + ' second' + ((secs == 1) ? '' : 's');

    }else{
      showText = "We're married!";
    }

    // Show the text.
    var dateElement = document.getElementById(displayID);  // Get parent element
    var pTag = document.createElement('p');                // Create (p)aragraph tag
    var dateText = document.createTextNode(showText);      // Create text node
    pTag.appendChild(dateText);                            // Append text node to P tag

    // Replace the first child node if it exists, otherwise append the element.
    if(dateElement.hasChildNodes()){ dateElement.replaceChild(pTag, dateElement.firstChild); }
    else{ dateElement.appendChild(pTag); }

    setTimeout("countDown()", 1000);

  }
}

window.onload = function(){ countDown(); }
