/**
* 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 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;
  }
}