/**
* Local Clock script (c) cityofcairns.com
*/

window.onload=LC_Display;
window.onunload=LC_Unload;

var LC_TZOFFSET = 10;     // GMT +10:00
var LC_CLOCKID  = 'ClockDisplay';

var LC_Ref = 0;

function LC_GetLocalTime() {
  var LT = new Date();
  var LT = new Date(LT.getUTCFullYear(), LT.getUTCMonth(), LT.getUTCDate(), LT.getUTCHours() + LC_TZOFFSET, LT.getUTCMinutes(), LT.getUTCSeconds());
  return LT;
}

function LC_MonthName(LC_Mo) {
  var LC_Months = new Array(
    "Jan",
    "Feb",
    "Mar",
    "Apr",
    "May",
    "Jun",
    "Jul",
    "Aug",
    "Sep",
    "Oct",
    "Nov",
    "Dec"
  );
  return LC_Months[LC_Mo];
}

function LC_FormatTime(LT) {
    // 
    // var num_2_word = function(number, map) {
    //   var map = {1: 'one', 2: 'two', 3: 'three', 4: 'four', 5: 'five', 6: 'six', 7: 'seven', 8: 'eight', 9: 'nine',10: 'ten',11: 'eleven',13: 'one','*': 'twelve'};
    //   if (!map[number])
    //     number = '*';
    //   return map[number];
    // }
    // 
    // var hour = LT.getHours();
    // var minute = LT.getMinutes();
    // var roughTime = 'sorry mate, something stuffed up';
    // 
    // if (minute >= 0 && minute < 5)
    //   roughTime = num_2_word(hour)+'-ish';
    // else if (minute >=5 && minute <14)
    //   roughTime = 'just gone '+num_2_word(hour);
    // else if (minute >=15 && minute <20)
    //   roughTime = 'quarter past '+num_2_word(hour);
    // else if (minute >=20 && minute <25)
    //   roughTime = 'nearly half past '+num_2_word(hour);
    // else if (minute >=25 && minute <35)
    //   roughTime = 'half past '+num_2_word(hour);
    // else if (minute >=35 && minute <40)
    //   roughTime = 'just gone half past '+num_2_word(hour);
    // else if (minute >=40 && minute <50)
    //   roughTime = 'quarter to '+num_2_word(hour + 1);
    // else if (minute >=50)
    //   roughTime =  'nearly '+num_2_word(hour +1);
    // 
    // return roughTime;
  
  var LC_Ye = LT.getFullYear();
  var LC_Mo = LT.getMonth();
  var LC_Da = LT.getDate();
  var LC_Ho = LT.getHours();
  var LC_Mi = LT.getMinutes();
  var LC_Se = LT.getSeconds();
  var LC_Me = (LC_Ho >= 12) ? "pm" : "am";
  if (LC_Ho == 0)
    LC_Ho = 12;
  else if (LC_Ho > 12)
    LC_Ho -= 12;
  if (LC_Mi < 10)
    LC_Mi = "0" + LC_Mi;
  if (LC_Se < 10)
    LC_Se = "0" + LC_Se;
  var LC_Month = LC_MonthName(LC_Mo);
//  return LC_Da + " " + LC_Month + " " + LC_Ye + " at " + LC_Ho + ":" + LC_Mi + ":" + LC_Se + " " + LC_Me; // Date and Time
    return LC_Ho + ":" + LC_Mi + ":" + LC_Se + " " + LC_Me;  // Just Time
}

function LC_Display() {
  LC_Unload();
  var LT = LC_GetLocalTime();
  if (!document.getElementById(LC_CLOCKID)) return false;
  document.getElementById(LC_CLOCKID).innerHTML = LC_FormatTime(LT);
  LC_Ref = setTimeout("LC_Display()", 500);
}

function LC_Unload() {
  if (LC_Ref != 0) {
    clearTimeout(LC_Ref);
    LC_Ref = 0;
  }
}