

function is_null (a) {
  return a.length == 0;
}

function is_zero (a) {
  return a == 0;
}

function cons (a, b) {
  return [a].concat (b);
}

function car (a) {
  return a.slice (0, 1);
}

function cdr (a) {
  return a.slice (1);
}

function quotient (a, b) {
  return Math.floor (a / b);
}

function modulo (a, b) {
  return a % b;
}

function time_left (times, splits) {
  if (is_null (splits)) {
    return times;
  } else {
    var time  = car (times);
    var split = car (splits);
    return time_left (cons (quotient (time, split), 
                            cons (modulo (time, split), 
                                  cdr (times))),
                      cdr (splits));
  }
}


function countdown_output_loop (date) {
  if (is_zero (date)) {
    countdown_display_function (countdown_end_message);
  } else {
    var new_date = date - 1;
    var time = time_left ([date], [60, 60, 24]);
    var output_str = countdown_display_format.replace(/%d/g, time[0])
                                             .replace(/%h/g, time[1])
                                             .replace(/%m/g, time[2])
                                             .replace(/%s/g, time[3]);
    
    countdown_display_function (output_str);
    setTimeout ('countdown_output_loop (' + new_date + ')', 1000);
  }
}


function countdown_intiate () {
  var start_date = new Date (countdown_start_date).valueOf ();
  var end_date   = new Date (countdown_end_date).valueOf ();
  countdown_output_loop (Math.floor((end_date - start_date) / 1000));
}


function countdown_display_function (str) {
  document.getElementById("countdown_display_element").innerHTML = str;
}



/*

<span id='countdown_display_element' style='color: navy'>&nbsp;</span>
<script language="JavaScript" src="http://www.burningkingdoms.com/countdown.js?7"></script>
<script>countdown_intiate ();</script>

*/

