/* This tea counter is based on the tea council's calculation that
165,000,000 cups of tea are consumed in the UK every day */

function formatTime() {

/* to display the number correctly*/
function number_format(n) {
  var arr=new Array('0'), i=0; 
  while (n>0) 
    {arr[i]=''+n%1000; n=Math.floor(n/1000); i++;}
  arr=arr.reverse();
  for (var i in arr) if (i>0) //padding zeros
    while (arr[i].length<3) arr[i]='0'+arr[i];
  return arr.join();
}

  /* calculate the no of cups drunk in a second */
  tps = 165000000 / 24 / 60 / 60;
  /*get time data */
  now = new Date();
  hour = now.getHours();
  min = now.getMinutes();
  sec = now.getSeconds();
  
  /* calculate the seconds in the hour and minute*/
  sph = hour * 60 * 60;
  spm = min * 60;
  /* add these all together to get the no of seconds since midnight */
  ssm = sph + spm + sec;

  /* calculate the cups drunk since midnight */
  tint = parseInt(ssm * tps);
  tea = number_format(tint);
  document.clock.tea.value = tea;
 
  setTimeout("formatTime()", 1000);
}

window.onload=formatTime;

