var white = Color.htmltoint('#FFFFFF');
var black = Color.htmltoint('#000000');

var gc = new GCanvas(180,180,white,1);

var output = new GHTMLOutput();

// Analog clock
var cenx = Math.round(gc.width/2.)-1;
var ceny = Math.round(gc.height/2.)-1;
var rad = Math.min(Math.round(gc.width/2.),Math.round(gc.height/2.))-3;
var shcolor = Color.htmltoint("#000000");
var mhcolor = Color.htmltoint("#000000");
var hhcolor = Color.htmltoint("#000000");

function clock()
{
      datetime = new Date();

      offset = -datetime.getTimezoneOffset()/60;
      dst = 1;

      s = datetime.getSeconds();
      m = datetime.getMinutes();
      h = datetime.getHours() % 12;
      //h = datetime.getHours() - offset + dst;
      //if ( h<0 ) { h = 24 + h; }
      //if ( h>=24 ) { h = h - 24; }
      //h = h % 12;

      // Clear the background.
      gc.clear();
      
      // Draw the clock circle.
      //gc.circle(cenx, ceny, rad, black);
      //gc.circle(cenx, ceny, 3, black);

      // Draw the second pointer.
      sr = (s/60)*2*Math.PI-.5*Math.PI; 
      sx = Math.round((rad*0.7)*Math.cos(sr)+cenx);
      sy = Math.round((rad*0.7)*Math.sin(sr)+ceny);
      csx = Math.round(3*Math.cos(sr)+cenx);
      csy = Math.round(3*Math.sin(sr)+ceny);
      gc.line(csx,csy, sx, sy, shcolor);
      //gc.circle(sx, sy, 2, shcolor);

      // Draw the minute hand.
      mr=(m/60+s/3600)*2*Math.PI-.5*Math.PI; 
      cmx = Math.round(3*Math.cos(mr)+cenx);
      cmy = Math.round(3*Math.sin(mr)+ceny);
      mx = Math.round((rad*0.7)*Math.cos(mr)+cenx);
      my = Math.round((rad*0.7)*Math.sin(mr)+ceny);
      gc.line(cmx, cmy - 1, mx, my, mhcolor);
      gc.line(cmx - 1, cmy, mx, my, mhcolor);

      // Draw the hour hand.
      hr=(h/12+m/720)*2*Math.PI-.5*Math.PI; 
      chx = Math.round(3*Math.cos(hr)+cenx);
      chy = Math.round(3*Math.sin(hr)+ceny);
      hx = Math.round((rad*0.5)*Math.cos(hr)+cenx);
      hy = Math.round((rad*0.5)*Math.sin(hr)+ceny);
      gc.line(chx, chy - 1, hx, hy, hhcolor);
      gc.line(chx - 1, chy, hx, hy, hhcolor);

      output.setup(this.document,'clock_optimised');
      output.compression=1;
      output.print(gc);
      setTimeout('clock()', 1000);
}