// アナログ時計
var anaclock_inited = false;
var anaclock_id = "clockbase"
var anaclock_handid = ["shand", "mhand", "hhand"];

function anaclock_init() {
	var clock = document.getElementById(anaclock_id);
	if(!clock) return false;
	
	var i;
	for(i = 0; i < 3; i++)
	{
		var hand = document.getElementById(anaclock_handid[i]);
		if(!hand) return false;
		var img = hand.childNodes[0];
		if(!img) return false;
		if(!hand.style.cssText) return false;
		hand.style.cssText += "; filter:progid:DXImageTransform.Microsoft.Matrix(M11=-1,M12=0,M21=0,M22=1)";
		if(!hand.filters || !hand.filters.length) return false;
		
		hand.style.pixelLeft = clock.style.pixelLeft;
		hand.style.pixelTop  = clock.style.pixelTop;
		hand.style.pixelWidth  = clock.clientWidth;
		hand.style.pixelHeight = clock.clientHeight;
	}
	return true;
}
function analogClock() {
	if(!document.getElementById) return;
	var clock = document.getElementById(anaclock_id);
	if(!anaclock_inited) {
		if(!clock) {
			setTimeout("analogClock()", 1000);
			return;
		}
		var b = anaclock_init();
		anaclock_inited = true;
		if(!b) return;
	}
	
	var now = new Date();
	var hour = now.getHours();
	if(hour > 11) hour -= 12;
	var minute = now.getMinutes();
	var second = now.getSeconds();
	var i;
	
	for(i = 0; i < 3; i++)
	{
		var hand = document.getElementById(anaclock_handid[i]);
		var img = hand.childNodes[0];
		var n, rad;
		if(i == 0)
			rad = (second * 6 - 90) * (Math.PI * 2 / 360);
		else if(i == 1)
			rad = ((minute * 60 + second)/60 * 6 - 90)
				* (Math.PI * 2 / 360);
		else if(i == 2)
			rad = ((hour * 60 + minute)/60 * 30 - 90)
				* (Math.PI * 2 / 360);
		hand.filters[0].M11 = Math.cos(rad);
		hand.filters[0].M12 = -Math.sin(rad);
		hand.filters[0].M21 = Math.sin(rad);
		hand.filters[0].M22 = Math.cos(rad);
		hand.filters[0].Dx = clock.clientWidth/2
			+ img.height/2 * Math.sin(rad);
		hand.filters[0].Dy = clock.clientHeight/2
			- img.height/2 * Math.cos(rad);
		if(hand.style.visibility = "hidden")
			hand.style.visibility = "visible";
	}
	
	setTimeout("analogClock()", 1000 - now.getMilliseconds());
}
analogClock();

