
function Clock()
{
	this.lights = new Array();
	this.milTime = false;
	this.power = true;
	this.time = new Array();
}

Clock.prototype.setMilTime = function setMilTime(state)
{
	this.milTime = state!='undefined' ? state : (this.milTime ? false : true);
}

Clock.prototype.setPower = function setPower(state)
{
	this.power = state!='undefined' ? state : (state ? false : true);
}
Clock.prototype.getPower = function getPower()
{
	return this.power;
}

Clock.prototype.powerButton = function powerButton(state)//true means down and false means up
{
	var power = this.getPower();
	var elem = $('powerButton');
	if(!state)
	{	//    				                     ON & UP     OFF & UP
		elem.style.backgroundPosition = power ? '0px 0px' : '-32px 0px';
	}
	else
	{	//                  			          ON & DOWN     OFF & DOWN
		elem.style.backgroundPosition = !power ? '0px -32px' : '-32px -32px';
		this.setPower(!power);
	}
	this.drawTime();
}

Clock.prototype.run = function run()
{
	var d = new Date();
	this.time['mn'] = d.getMinutes();
	this.time['sc'] = d.getSeconds();
	this.time['hr'] = !this.milTime && d.getHours()>12 ? d.getHours()-12 : d.getHours();
	this.drawTime();
}

Clock.prototype.setLight = function setLight(which,state)
{
	var elem = $(which);
	if(elem)
	{	//                                           ON          OFF
		elem.style.backgroundPosition = state ? '0px -50px' : '0px 0px' ;
	}
}

Clock.prototype.getBit = function getBit(number,bit)
{
	// get the value of the bit at (2 to the power of (the position requested minus one))
	return number & Math.pow(2,bit-1) ? true : false;
}


Clock.prototype.drawTime = function drawTime()//YAY this keeps binary time! ! ! 
{
	for(i in this.time)
	{
		var number = this.getPower() ? this.time[i] : 0;
		//Ones
		var num1=number%10;
		this.setLight(i+'1d1',this.getBit(num1,1));
		this.setLight(i+'2d1',this.getBit(num1,2));
		this.setLight(i+'3d1',this.getBit(num1,3));
		this.setLight(i+'4d1',this.getBit(num1,4));
		//tens
		var num2 = Math.floor(number/10);
		this.setLight(i+'1d2',this.getBit(num2,1));
		this.setLight(i+'2d2',this.getBit(num2,2));
		if(i!='hr'){this.setLight(i+'3d2',this.getBit(num2,3));}
	}
}



//^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^



try {document.execCommand("BackgroundImageCache", false, true);} catch (e) {};

function $(id)
{
	return gebi = document.getElementById(id);
}


var clock = new Clock();
function startClock()
{
	setInterval(runClock,1000);
}
function runClock()
{
	clock.run();
}










