//vml时钟类
function VMLClock(width, height, offset)
{
	this.Width = width;
	this.Height = height;
	this.Offset = offset;
	this.PointSec = null;
	this.PointMin = null;
	this.PointHou = null;
	this.VMLObject = null;
	this.Container = null;
}

//初始化
VMLClock.prototype.initialise = function()
{
	if (this.Container == null) return;

	//画容器
	var group = document.createElement("v:group");
	group.style.width = this.Width + "px";
	group.style.width = this.Height + "px";
	group.coordsize = "100,100";
	group.style.position = "relative";

	//画钟面
	var clockface = document.createElement("<v:oval style='width: 100%; height: 100%'>");
	var strokeBold = document.createElement("<v:stroke weight='1' color='black'/>");
	clockface.appendChild(strokeBold);
	group.appendChild(clockface);

	//画刻度
	var scale;
	scale = document.createElement("<v:line from='100,50' to='92,50'>");//3点
	var strokeBold = document.createElement("<v:stroke weight='2' color='black'/>");
	scale.appendChild(strokeBold);
	group.appendChild(scale);
	scale = document.createElement("<v:line from='50,100' to='50,92'>");//6点
	var strokeBold = document.createElement("<v:stroke weight='2' color='black'/>");
	scale.appendChild(strokeBold);
	group.appendChild(scale);
	scale = document.createElement("<v:line from='0,50' to='8,50'>");//9点
	var strokeBold = document.createElement("<v:stroke weight='2' color='black'/>");
	scale.appendChild(strokeBold);
	group.appendChild(scale);
	scale = document.createElement("<v:line from='50,0' to='50,8'>");//12点
	var strokeBold = document.createElement("<v:stroke weight='2' color='black'/>");
	scale.appendChild(strokeBold);
	group.appendChild(scale);
	var strokeNormal = document.createElement("<v:stroke weight='1' color='black'/>");
	scale = document.createElement("<v:line from='73,6' to='73,14' style='rotation: 30'>");//1点
	scale.appendChild(strokeNormal);
	group.appendChild(scale);
	scale = document.createElement("<v:line from='90,23' to='90,31' style='rotation: 60'>");//2点
	scale.appendChild(strokeNormal);
	group.appendChild(scale);
	scale = document.createElement("<v:line from='90,77' to='90,69' style='rotation: 300'>");//4点
	scale.appendChild(strokeNormal);
	group.appendChild(scale);
	scale = document.createElement("<v:line from='73,94' to='73,86' style='rotation: 150'>");//5点
	scale.appendChild(strokeNormal);
	group.appendChild(scale);
	scale = document.createElement("<v:line from='27,94' to='27,86' style='rotation: 210'>");//7点
	scale.appendChild(strokeNormal);
	group.appendChild(scale);
	scale = document.createElement("<v:line from='10,77' to='10,69' style='rotation: 60'>");//8点
	scale.appendChild(strokeNormal);
	group.appendChild(scale);
	scale = document.createElement("<v:line from='10,23' to='10,31' style='rotation: 300'>");//10点
	scale.appendChild(strokeNormal);
	group.appendChild(scale);
	scale = document.createElement("<v:line from='27,6' to='27,14' style='rotation: 330'>");//11点
	scale.appendChild(strokeNormal);
	group.appendChild(scale);

	//画秒针
	var pointsec = document.createElement("<v:group style='width: 100%; height: 100%; position: absolute; top: 0; left: 0;'>");
	var line = document.createElement("<v:line from='50,50' to='50,8'>");
	var strokeNormalPoint = document.createElement("<v:stroke weight='1' endcap='round' color='red'/>");
	line.appendChild(strokeNormalPoint);
	pointsec.appendChild(line);
	group.appendChild(pointsec);
	this.PointSec = pointsec;
	

	//画分针
	var pointmin = document.createElement("<v:group style='width: 100%; height: 100%; position: absolute; top: 0; left: 0;'>");
	var line = document.createElement("<v:line from='50,50' to='50,16'>");
	var strokeBoldPoint = document.createElement("<v:stroke weight='1' endcap='round' color='navy'/>");
	line.appendChild(strokeBoldPoint);
	pointmin.appendChild(line);
	group.appendChild(pointmin);
	this.PointMin = pointmin;

	//画时针
	var pointhou = document.createElement("<v:group style='width: 100%; height: 100%; position: absolute; top: 0; left: 0;'>");
	var line = document.createElement("<v:line from='50,50' to='50,24'>");
	var strokeBoldPoint = document.createElement("<v:stroke weight='1' endcap='round' color='navy'/>");
	line.appendChild(strokeBoldPoint);
	pointhou.appendChild(line);
	group.appendChild(pointhou);
	this.PointHou = pointhou;

	this.VMLObject = group;
	this.Container.appendChild(this.VMLObject);
}

//刷新时钟指针
VMLClock.prototype.updatePointers = function()
{
	var dNow = new Date();
	var nNow = dNow.valueOf();
	var fTimeZone = dNow.getTimezoneOffset()/60;
	var nPerHour = 1000 * 60 * 60;
	var nAreaTime = nNow + (fTimeZone + this.Offset) * nPerHour;
	var dAreaTime = new Date(nAreaTime);
	
	this.PointSec.style.rotation = dAreaTime.getSeconds() * 6;
	this.PointMin.style.rotation = dAreaTime.getMinutes() * 6 + dAreaTime.getSeconds() / 10;
	this.PointHou.style.rotation = dAreaTime.getHours() * 30  + dAreaTime.getMinutes() / 2;
}