function update_clock(){
	var d = new Date;

	var seconds = d.getSeconds();
	var minutes = d.getMinutes()+seconds/60.0;
	var hours = d.getHours()+minutes/60.0;

	var seconds_angle = 2.0*Math.PI*(seconds/60.0);
	//minutes_rect.attr({opacity: (0.25+0.5*Math.sin(seconds_angle))});

	var minutes_angle = 360.0*(minutes/60.0);
	minutes_rect.rotate(minutes_angle,circle_center_x,circle_center_y);

	var hours_angle = 360*((hours % 12)/12.0);
	hours_rect.rotate(hours_angle,circle_center_x,circle_center_y);
  setTimeout('update_clock()',500);
}

function original_colors(){
	background_rect.attr({fill: "#fff"});
	circle.attr({opacity: 0.5, fill: "#f00", stroke: "#a00"});
	hours_rect.attr({opacity: 0.5, fill: "#0f0", stroke: "#0a0"});
	minutes_rect.attr({opacity: 0.5, fill: "#00f", stroke: "#00a"});
}

function raphael_colors(){
	background_rect.attr({fill: "#000"});
	circle.attr({opacity: 0.7, fill: "#f00", stroke: "#fff"});
	hours_rect.attr({opacity: 0.6, fill: "#0f0", stroke: "#fff"});
	minutes_rect.attr({opacity: 0.5, fill: "#00f", stroke: "#fff"});
}

function start_clock(){
  update_clock();
}

function initialize_clock(width, height){
	container = document.getElementById('canvas_container');
	//if(fullscreen){
		//paper = Raphael(
			//container,
			//1*Math.min(window.document.width,window.document.height),
			//1*Math.min(window.document.width,window.document.height));
	//}else{
		//paper = Raphael(
			//container);
        //}
        paper = Raphael(container,width,height);
	clock_radius =
		Math.min(width, height)/2/Math.sqrt(2.0);

	background_rect = paper.rect(0,0,width,height);

	circle_center_x = width/2;
	circle_center_y = height/2;
	circle = paper.circle(circle_center_x,circle_center_y,clock_radius);

	var hours_width = clock_radius*Math.sqrt(4.0/5.0);
	var hours_height = hours_width;
	hours_rect = paper.rect(
	circle_center_x-hours_width/2,
	circle_center_y-hours_height,
	hours_width,
	hours_height); 

	var minutes_width = clock_radius*2;
	var minutes_height = clock_radius;
	minutes_rect = paper.rect(
		circle_center_x-minutes_width/2,
		circle_center_y-minutes_height,
		minutes_width,
		minutes_height); 
	raphael_colors();
}


// Globals
var paper;
var minutes_rect;
var hours_rect;
var circle;
var background_rect;
var clock_radius;
var circle_center_x;
var circle_center_y;

