function init_clock(canvas_id,timeshift){
  var canvas = document.getElementById(canvas_id);
  if(canvas.getContext) {
    clock(canvas_id,timeshift);
    setInterval("clock('"+canvas_id+"',"+timeshift+")",1000);
  }
  else {
    alert('This browser doesn\'t support the canvas element :(');
  }
}
function clock(canvas_id,timeshift){
  var now = new Date(new Date().getTime()+(timeshift)*3600000);
  var ctx = document.getElementById(canvas_id).getContext('2d');

  ctx.save();
  ctx.clearRect(0,0,100,100);
  ctx.translate(50,40);
  ctx.scale(0.25,0.25);
  ctx.rotate(-Math.PI/2);
  ctx.strokeStyle = "white";
  ctx.fillStyle = "white";
  ctx.lineWidth = 4;
  ctx.lineCap = "round";

  // Hour marks
  ctx.save();
  ctx.beginPath();
  for (var i=0;i<12;i++){
    ctx.rotate(Math.PI/6);
    ctx.moveTo(100,0);
    ctx.lineTo(120,0);
  }
  ctx.stroke();
  ctx.restore();

  // Minute marks
/*  ctx.save();
  ctx.lineWidth = 5;
  ctx.beginPath();
  for (i=0;i<60;i++){
    if (i%5!=0) { // 5 minutes
      ctx.moveTo(117,0);
      ctx.lineTo(120,0);
    }
    ctx.rotate(Math.PI/30);
  }
  ctx.stroke();
  ctx.restore();*/
  
  var sec = now.getSeconds();
  var min = now.getMinutes();
  var hr  = now.getHours();
  hr = hr>=12 ? hr-12 : hr;

  ctx.fillStyle = "#FFFFFF";

  // write Hours
  ctx.save();
  ctx.rotate( hr*(Math.PI/6) + (Math.PI/360)*min + (Math.PI/21600)*sec )
  ctx.lineWidth = 10;
  ctx.beginPath();
  ctx.moveTo(-20,0);
  ctx.lineTo(80,0);
  ctx.stroke();
  ctx.restore();

  // write Minutes
  ctx.save();
  ctx.rotate( (Math.PI/30)*min + (Math.PI/1800)*sec )
  ctx.lineWidth = 8;
  ctx.beginPath();
  ctx.moveTo(-28,0);
  ctx.lineTo(112,0);
  ctx.stroke();
  ctx.restore();
  
  // Write seconds
  ctx.save();
  ctx.rotate(sec * Math.PI/30);
  ctx.strokeStyle = "#FFFFFF";
  ctx.fillStyle = "#FFFFFF";
  ctx.lineWidth = 4;

  ctx.beginPath();
  ctx.moveTo(-10,0);
  ctx.lineTo(68,0);
  ctx.stroke();

  ctx.beginPath();
  ctx.moveTo(91,0);
  ctx.lineTo(100,0);
  ctx.stroke();

  ctx.beginPath();
  ctx.arc(79,0,10,0,Math.PI*2,true);
  ctx.stroke();

  ctx.restore();
  ctx.restore();
}
