//---------------------------
function digiclock(){
//---------------------------
	var now = new Date();
	var ctx = document.getElementById('digiclock').getContext('2d');
	ctx.save();
	ctx.clearRect(0,0,180,45);
	ctx.rect(0,0,180,45);
	ctx.scale(0.2,0.2);
	ctx.translate(15,15);
	ctx.strokeStyle = "black";
	ctx.fillStyle = "black";
	ctx.lineWidth = 10;
	ctx.lineCap = "round";
	
	//..............................
	ctx.beginPath();
	ctx.arc(215,40,10,0,Math.PI*2,true);
	ctx.fill();
	ctx.beginPath();
	ctx.arc(215,110,10,0,Math.PI*2,true);
	ctx.fill();
	ctx.beginPath();
	ctx.arc(465,40,10,0,Math.PI*2,true);
	ctx.fill();
	ctx.beginPath();
	ctx.arc(465,110,10,0,Math.PI*2,true);
	ctx.fill();

	//..............................
	var hr = now.getHours();
	var min = now.getMinutes();
	var sec = now.getSeconds();
	//..............................
	var lineThk = 10;
	var	stickLen = 50;
	
	//..............................
	var offsetdigitH1 = 0
		,offsetdigitH2 = 100
		,offsetdigitM1 = 250
		,offsetdigitM2 = 350
		,offsetdigitS1 = 500
		,offsetdigitS2 = 600
	;
	//..............................
	var offset1 = lineThk + lineThk/2
		,offset2 = lineThk/2
		,offset3 = lineThk*2 + stickLen + lineThk/2
		,offset4 = lineThk + stickLen + lineThk/2
		,offset5 = lineThk*4 + lineThk/2 + stickLen*2
		,offset6 = lineThk*3 + lineThk/2 + stickLen
		,offset7 = lineThk*3 + lineThk/2 + stickLen*2
	;

	//=================
	ctx.save();
	ctx.restore();
	//=================

	//..............................
	if(hr<10) {
		zero(offsetdigitH1);
		digits(hr,offsetdigitH2);
	}
	if(hr>9 && hr<20) {
		un(offsetdigitH1);
		digits((hr-10),offsetdigitH2);
	}
	if(hr>19) {
		deux(offsetdigitH1);
		digits((hr-20),offsetdigitH2);
	}

	//..............................
	if(min<10) {
		zero(offsetdigitM1);
		digits(min,offsetdigitM2);
	}
	if(min>9 && min<20) {
		un(offsetdigitM1);
		digits((min-10),offsetdigitM2);
	}
	if(min>19 && min<30) {
		deux(offsetdigitM1);
		digits((min-20),offsetdigitM2);
	}
	if(min>29 && min<40) {
		trois(offsetdigitM1);
		digits((min-30),offsetdigitM2);
	}
	if(min>39 && min<50) {
		quatre(offsetdigitM1);
		digits((min-40),offsetdigitM2);
	}
	if(min>49) {
		cinq(offsetdigitM1);
		digits((min-50),offsetdigitM2);
	}
	
	//..............................
	if(sec<10) {
		zero(offsetdigitS1);
		digits(sec,offsetdigitS2);
	}
	if(sec>9 && sec<20) {
		un(offsetdigitS1);
		digits((sec-10),offsetdigitS2);
	}
	if(sec>19 && sec<30) {
		deux(offsetdigitS1);
		digits((sec-20),offsetdigitS2);
	}
	if(sec>29 && sec<40) {
		trois(offsetdigitS1);
		digits((sec-30),offsetdigitS2);
	}
	if(sec>39 && sec<50) {
		quatre(offsetdigitS1);
		digits((sec-40),offsetdigitS2);
	}
	if(sec>49) {
		cinq(offsetdigitS1);
		digits((sec-50),offsetdigitS2);
	}
	
	
	//=================
	ctx.restore();
	//=================


	//=============================
	function htop(offset) {
		ctx.beginPath();
		ctx.moveTo(offset1+offset,offset2);
		ctx.lineTo(offset4+offset,offset2);
		ctx.stroke();
	}
	function hmiddle(offset) {
		ctx.beginPath();
		ctx.moveTo(offset1+offset,offset3);
		ctx.lineTo(offset4+offset,offset3);
		ctx.stroke();
	}
	function hbottom(offset) {
		ctx.beginPath();
		ctx.moveTo(offset1+offset,offset5);
		ctx.lineTo(offset4+offset,offset5);
		ctx.stroke();
	}
	function vtopleft(offset) {
		ctx.beginPath();
		ctx.moveTo(offset2+offset,offset1);
		ctx.lineTo(offset2+offset,offset4);
		ctx.stroke();
	}
	function vbottomleft(offset) {
		ctx.beginPath();
		ctx.moveTo(offset2+offset,offset6);
		ctx.lineTo(offset2+offset,offset7);
		ctx.stroke();
	}
	function vtopright(offset) {
		ctx.beginPath();
		ctx.moveTo(offset3+offset,offset1);
		ctx.lineTo(offset3+offset,offset4);
		ctx.stroke();
	}
	function vbottomright(offset) {
		ctx.beginPath();
		ctx.moveTo(offset3+offset,offset6);
		ctx.lineTo(offset3+offset,offset7);
		ctx.stroke();
	}

	//=============================
	function zero(offset) {
		htop(offset);
		vtopright(offset);
		vbottomright(offset);
		hbottom(offset);
		vbottomleft(offset);
		vtopleft(offset);
	}
	function un(offset) {
		vtopright(offset);
		vbottomright(offset);
	}
	function deux(offset) {
		htop(offset);
		vtopright(offset);
		hmiddle(offset);
		vbottomleft(offset);
		hbottom(offset);
	}
	function trois(offset) {
		htop(offset);
		vtopright(offset);
		hmiddle(offset);
		vbottomright(offset);
		hbottom(offset);
	}
	function quatre(offset) {
		vtopleft(offset);
		vtopright(offset);
		hmiddle(offset);
		vbottomright(offset);
	}
	function cinq(offset) {
		htop(offset);
		vtopleft(offset);
		hmiddle(offset);
		vbottomright(offset);
		hbottom(offset);
	}
	function six(offset) {
		htop(offset);
		vtopleft(offset);
		hmiddle(offset);
		vbottomright(offset);
		vbottomleft(offset);
		hbottom(offset);
	}
	function sept(offset) {
		htop(offset);
		vtopright(offset);
		vbottomright(offset);
	}
	function huit(offset) {
		htop(offset);
		vtopleft(offset);
		vtopright(offset);
		hmiddle(offset);
		vbottomright(offset);
		vbottomleft(offset);
		hbottom(offset);
	}
	function neuf(offset) {
		htop(offset);
		vtopleft(offset);
		vtopright(offset);
		hmiddle(offset);
		vbottomright(offset);
		hbottom(offset);
	}
	
	function digits(sec,offset) {
		switch(sec) {
			case 0:
				zero(offset);
				break;
			case 1:
				un(offset);
				break;
			case 2:
				deux(offset);
				break;
			case 3:
				trois(offset);
				break;
			case 4:
				quatre(offset);
				break;
			case 5:
				cinq(offset);
				break;
			case 6:
				six(offset);
				break;
			case 7:
				sept(offset);
				break;
			case 8:
				huit(offset);
				break;
			case 9:
				neuf(offset);
				break;
		}
	}
	//=============================
}

