    if(window.addEventListener){
      window.addEventListener('load',clock_init,false)
    }

    function clock_init(){
      var w = window;
      if (w.clockDiameter==undefined) w.clockDiameter = 75;
      var canvas = document.getElementById('canvasClock');
      canvas.width = w.clockDiameter;
      canvas.height = w.clockDiameter;
      canvas.style.width = w.clockDiameter+"px";
      canvas.style.height = w.clockDiameter+"px";
      clock();
      setInterval('clock()',1000);
    }
  
    function clock(){
      var w = window;
      var canvas = document.getElementById('canvasClock');
      var now = new Date();
      var ctx = canvas.getContext('2d');
      ctx.save();
      ctx.clearRect(0,0,w.clockDiameter,w.clockDiameter);
      ctx.translate(w.clockDiameter/2,w.clockDiameter/2);
      ctx.rotate(-Math.PI/2);
      ctx.scale(w.clockDiameter/150,w.clockDiameter/150);
      ctx.strokeStyle = "black";
      ctx.fillStyle = "white";
      ctx.lineWidth = 5;
      ctx.save();

      // Background
      ctx.beginPath();
      ctx.arc(0,0,75,0,Math.PI*2,true);
      ctx.fill();
      ctx.closePath();

      // Hour marks
      ctx.beginPath();
      for (i=0;i<12;i++){
        ctx.rotate(Math.PI/6);
        ctx.moveTo(53,0);
        ctx.lineTo(70,0);
        ctx.stroke();
      }
      ctx.closePath();
      ctx.restore();
      ctx.save();

      // Minute marks
      ctx.lineWidth = 2;
      ctx.beginPath();
      for (i=0;i<60;i++){
        if (i%5!=0) {
          ctx.moveTo(64,0);
          ctx.lineTo(70,0);
          ctx.stroke();
        }
        ctx.rotate(Math.PI/30);
      }
      ctx.closePath();
      ctx.restore();
      ctx.lineWidth = 5;
      
      var sec = now.getSeconds();
      var min = now.getMinutes();
      var hr  = now.getHours();
      hr = hr>=12 ? hr-12 : hr;
      
      // write Hours
      ctx.save();
      ctx.rotate( hr*(Math.PI/6) + (Math.PI/360)*min + (Math.PI/21600)*sec )
      ctx.beginPath();
      ctx.lineWidth = 7;
      ctx.moveTo(-15,0);
      ctx.lineTo(48,0);
      ctx.stroke();
      ctx.closePath();
      ctx.restore();

      // write Minutes
      ctx.save();
      ctx.rotate( (Math.PI/30)*min + (Math.PI/1800)*sec )
      ctx.beginPath();
      ctx.lineWidth = 5;
      ctx.moveTo(-14,0);
      ctx.lineTo(65,0);
      ctx.stroke();
      ctx.closePath();
      ctx.restore();
      
      // Write seconds
      ctx.save();
      ctx.rotate(sec * Math.PI/30);
      ctx.strokeStyle = "red";
      ctx.fillStyle = "red";
      ctx.lineWidth = 2.5;
      ctx.beginPath();
      ctx.moveTo(-20,0);
      ctx.lineTo(51,0);
      ctx.stroke();
      ctx.arc(0,0,3,0,Math.PI*2,true);
      ctx.fill();
      ctx.arc(48,0,6,0,Math.PI*2,true);
      ctx.fill();
      ctx.closePath();
      ctx.restore();

      ctx.restore();
    }
