// Analog Clock - Parameters Head Script
// You may change the parameters here to set up your clock
// refer to  http://javascript.about.com/library/blclock1.htm
// for a description of the parameters

//uitleg: http://javascript.about.com/library/blclock4.htm


var clock_clocksize=120;
var clock_colnumbers='000000';
var clock_colseconds='ff0000';
var clock_colminutes='000000';
var clock_colhours='000000';
var clock_coldate='000000';
var clock_numstyle = 3;
var clock_font_family = 'helvetica,arial,sans-serif';
var clock_localzone = 1;
var clock_showampm = 0; //HB
var clock_showday = 0; //HB
var clock_showdate = 0; //HB
var clock_mytimezone = 0;
var clock_dst = 0;
var clock_city = '';
var clock_country = '';
var clock_fix = 1;
var clock_xpos=0;
var clock_ypos=0;

// code to adjust for daylight saving time if applicable (clock_localzone = 0)
/* To get the clock adjusting for daylight savings time between the first
Sunday in October and the first Sunday in April (which is when it applies here)
I added:

var gmt = new Date;var lsm = new Date;var lso = new Date;
lsm.setMonth(3);lsm.setDate(7);
var day = lsm.getDay();lsm.setDate(7-day);

lso.setMonth(9);lso.setDate(7);
day = lso.getDay();lso.setDate(7-day);
if (gmt < lsm || gmt >= lso) clock_dst = 1;
*/

// code to handle clock positioning (clock_fix = 0)

/*
The final few parameters allow you to detach the clock from the web page.
To be able to set the position of the clock on the screen independently of
the page simply set clock_fix = 0. You can then set the absolute position of the
clock using the clock_xpos  and clock_ypos variables. By adding a script to manipulate
these values you can get the clock to stay in a clock_fixed position with the page
scrolling behind it, you could have the clock follow the mouse pointer, or
any other animation that you wish to apply to the clock.
*/


// Analog Clock - Head Script
// copyright Stephen Chapman, 19th November 2005, 28th September 2008
// you may copy this clock provided that you retain the copyright notice
var clock_am = 'AM';
var clock_pm = 'PM';
//var clock_dayname   = new Array ('Sunday','Monday','Tuesday','Wednesday','Thursday','Friday','Saturday','Sunday');
var clock_dayname   = new Array ('zondag','maandag','dinsdag','woensdag','donderdag','vrijdag','zaterdag','zondag'); //HB
var clock_daycode   = new Array ('zo','ma','di','wo','do','vr','za','zo'); //HB
var clock_monthcode = new Array ('jan','feb','mrt','apr','mei','jun','jul','aug','sep','okt','nov','dec'); //HB

// you should not need to alter the below code
var clock_pi = Math.PI;
var clock_d = document;
var clock_pi2 = clock_pi/2;
var clock_rad = (+clock_clocksize) / 2;
var clock_ctrX = (+clock_xpos) + clock_rad;
var clock_ctrY = (+clock_ypos) + clock_rad;
var clock_hourln = 1;
var clock_minln = clock_secln = 2;
for(var i = 0; i < (clock_rad / 2) + (clock_rad / 16); i++) { clock_hourln+=1; }
for(var i = 0; i < (clock_rad / 2) - (clock_rad / 8); i++) { clock_minln+=2; clock_secln+=2; }
var clock_fontsize = clock_rad / 4;
var clock_offset = 16;
var clock_num = [[,1,2,3,4,5,6,7,8,9,10,11,12]
                ,[,'I','II','III','IIII','V','VI','VII','VIII','IX','X','XI','XII']
                ,[,'·','·','-','·','·','<span style="font-size:60%">|</span>','·','·','-','·','·','<span style="font-size:60%">||</span>']
                ,[,'<b>&middot;</b>','<b>&middot;</b>','<b>&middot;</b>','<b>&middot;</b>','<b>&middot;</b>','<b>&middot;</b>','<b>&middot;</b>','<b>&middot;</b>','<b>&middot;</b>','<b>&middot;</b>','<b>&middot;</b>','<b>&middot;</b>']
                ];
if (clock_numstyle < 0 || clock_numstyle > 3) clock_numstyle = 0;
function prepareclock() {
  clock_rad = (+clock_clocksize) / 2;
  clock_ctrX = (+clock_xpos) + clock_rad;
  clock_ctrY = (+clock_ypos) + clock_rad;
  clock_hourln = 1;
  clock_minln = clock_secln = 2;
  for (var i = 0; i < (clock_rad / 2) + (clock_rad / 16); i++) { clock_hourln+=1; }
  for(var i = 0; i < (clock_rad / 2) - (clock_rad / 8); i++) { clock_minln+=2; clock_secln+=2; }
  clock_fontsize = clock_rad / 4;
}
function timeZone(now,loc,mtz,clock_dst) {
  if (loc) {
    var dow = now.getDay();
    var second = now.getSeconds();
    var minute = now.getMinutes();
    var hour = now.getHours();
    var year = now.getFullYear(); //HB
    var month = now.getMonth(); //HB
    var day = now.getDate(); //HB
  } else {
    now.setUTCMinutes(now.getUTCMinutes() + (mtz + clock_dst)*60);
    var dow = now.getUTCDay();
    var second = now.getUTCSeconds();
    var minute = now.getUTCMinutes();
    var hour = now.getUTCHours();
    var year = now.getUTCFullYear(); //HB
    var month = now.getUTCMonth(); //HB
    var day = now.getUTCDate(); //HB
  }
  if (hour > 11) {moa = clock_pm; hour -= 12;} else moa = clock_am;
  return [dow,moa,hour,minute,second,year,month,day]; //HB
//  return [dow,moa,hour,minute,second];
}
function commonClock(n) {
  n.style.position = 'absolute';
  n.style.top = '0';
  n.style.left = '0';
  n.style.visibility = 'hidden';
}
function displayClock() {
  prepareclock();
//  if (!clock_d.getElementById) return;
  var ctx = document.createElement('div');
  if (clock_fix) {
    ctx.style.position = 'relative';
    ctx.style.margin = 'auto';
    ctx.style.width = (clock_clocksize + clock_offset * 2) + 'px';
    ctx.style.height = (clock_clocksize + clock_offset * 2) + 'px';
    ctx.style.overflow = 'visible';
  }
  var cn = [];
  for (var i = 12; i > 0; i--) {
    cn[i] = document.createElement('div');
    cn[i].id = 'cnum' + i;
    commonClock(cn[i]);
    cn[i].style.width = (clock_offset * 2) + 'px';
    cn[i].style.height = (clock_offset * 2) + 'px';
    cn[i].style.fontFamily = clock_font_family;
    cn[i].style.fontSize = clock_fontsize + 'px';
    cn[i].style.color = '#' + clock_colnumbers;
    cn[i].style.textAlign = 'center';
if ((i==9)||(i==3)) cn[i].style.paddingTop = '8px'; else //HB
    cn[i].style.paddingTop = '10px';
    cn[i].style.zIndex = 1000;
    cn[i].innerHTML = clock_num[clock_numstyle][i];
    ctx.appendChild(cn[i]);
  }
  var mn = [];
  for (i = clock_minln; i > 0; i--) {
    mn[i] = document.createElement('div');
    mn[i].id = 'cmin' + i;
    commonClock(mn[i]);
    mn[i].style.width = '1px';
    mn[i].style.height = '1px';
    mn[i].style.fontSize = '1px';
    mn[i].style.backgroundColor = '#' + clock_colminutes;
    mn[i].style.zIndex = 997;
    ctx.appendChild(mn[i]);
  }
  var hr = [];
  for (i = clock_hourln; i > 0; i--) {
    hr[i] = document.createElement('div');
    hr[i].id = 'chour' + i;
    commonClock(hr[i]);
    hr[i].style.width = '2px';
    hr[i].style.height = '2px';
    hr[i].style.fontSize ='2px';
    hr[i].style.backgroundColor = '#' + clock_colhours;
    hr[i].style.zIndex = 998;
    ctx.appendChild(hr[i]);
  }
  var sc = [];
  for (i = clock_secln; i > 0; i--) {
    sc[i] = document.createElement('div');
    sc[i].id = 'csec' + i;
    commonClock(sc[i]);
    sc[i].style.width = '1px';
    sc[i].style.height = '1px';
    sc[i].style.fontSize ='1px';
    sc[i].style.backgroundColor = '#' + clock_colseconds;
    sc[i].style.zIndex = 999;
    ctx.appendChild(sc[i]);
  }
  var am = document.createElement('div');
  am.id = 'ampm';
  commonClock(am);
  am.style.width = ((clock_xpos + clock_rad) * 2) + 'px';
  am.style.fontFamily = clock_font_family;
  am.style.fontSize = (clock_fontsize * 5 / 6) + 'px'; //HB
//  am.style.fontSize = (clock_fontsize * 2 / 3) + 'px';
  am.style.color = '#' + clock_coldate;
  am.style.textAlign = 'center';
  am.style.paddingTop = '10px';
  am.style.zIndex = 990;
  ctx.appendChild(am);
  var zn = document.createElement('div');
  zn.id = 'zone';
  commonClock(zn);
  zn.style.width = ((clock_xpos + clock_rad) * 2) + 'px';
  zn.style.fontFamily = clock_font_family;
  zn.style.fontSize = (clock_fontsize * 2 / 3) + 'px';
  zn.style.color = '#' + clock_colnumbers;
  zn.style.textAlign = 'center';
  zn.style.paddingTop = '10px';
  zn.style.zIndex = 990;
  ctx.appendChild(zn);
  getid('clock_a').appendChild(ctx);
  for (var i = 12; i > 0; i--) {
    getid('cnum' + i).style.top = (clock_ctrY - clock_offset + clock_rad * Math.sin(i * clock_pi / 6 - clock_pi2))+'px';
    getid('cnum' + i).style.left = (clock_ctrX - clock_offset + clock_rad * Math.cos(i * clock_pi / 6 - clock_pi2))+'px';
    getid('cnum' + i).style.visibility = 'visible';
  }
//  clock_d.getElementById('clock_a').appendChild(ctx);
//  for (var i = 12; i > 0; i--) {
//    clock_d.getElementById('cnum' + i).style.top = (clock_ctrY - clock_offset + clock_rad * Math.sin(i * clock_pi / 6 - clock_pi2))+'px';
//    clock_d.getElementById('cnum' + i).style.left = (clock_ctrX - clock_offset + clock_rad * Math.cos(i * clock_pi / 6 - clock_pi2))+'px';
//    clock_d.getElementById('cnum' + i).style.visibility = 'visible';
//  }
  updateClock();
}
function moveClock(l, e, f) {
  for (var i = l; i > 0; i--) {
    getid(e + i).style.top = (clock_ctrY + i * Math.sin(f))+'px';
    getid(e + i).style.left = (clock_ctrX + i * Math.cos(f))+'px';
    getid(e + i).style.visibility = 'visible';
  }
//  for (var i = l; i > 0; i--) {
//    clock_d.getElementById(e + i).style.top = (clock_ctrY + i * Math.sin(f))+'px';
//    clock_d.getElementById(e + i).style.left = (clock_ctrX + i * Math.cos(f))+'px';
//    clock_d.getElementById(e + i).style.visibility = 'visible';
//  }
}
function updateClock() {
  var now = new Date();
  var theTime = timeZone(now,clock_localzone,clock_mytimezone,clock_dst);
  //HB: ampm, day and date are optional
  var s = '';
  if (clock_showdate) { if (s!='') s+='<br />'; s+=clock_daycode[theTime[0]]+' '+theTime[7]+' '+clock_monthcode[theTime[6]]+' '+theTime[5]; } else //HB
  if (clock_showday) { if (s!='') s+='<br />'; s+=clock_dayname[theTime[0]]; }
  if (clock_showampm) { if (s!='') s+='<br />'; s+=theTime[1]; }
  getid('ampm').style.top = (clock_ypos + clock_rad)+'px'; //HB
  getid('ampm').innerHTML = s;
  getid('ampm').style.visibility = 'visible';
//  clock_d.getElementById('ampm').style.top = (clock_ypos + clock_rad/3)+'px';
//  clock_d.getElementById('ampm').innerHTML = s;
//  clock_d.getElementById('ampm').style.visibility = 'visible';
  if (!clock_localzone) {
    getid('zone').style.top = (clock_ctrY + (clock_rad/10))+'px';
    getid('zone').innerHTML = clock_city + '<br />' + clock_country;
    getid('zone').style.visibility = 'visible';
//    clock_d.getElementById('zone').style.top = (clock_ctrY + (clock_rad/10))+'px';
//    clock_d.getElementById('zone').innerHTML = clock_city + '<br />' + clock_country;
//    clock_d.getElementById('zone').style.visibility = 'visible';
  }
  moveClock(clock_secln, 'csec', clock_pi * theTime[4] / 30 - clock_pi2);
  moveClock(clock_minln, 'cmin', clock_pi * theTime[3] / 30 - clock_pi2);
  moveClock(clock_hourln, 'chour', clock_pi * theTime[2] / 6 + clock_pi * (+now.getMinutes())/360 - clock_pi2);
  setTimeout('updateClock()', 100);
}
//window.onload = displayClock;

