  
	Date.implement({
	
		clearTime: function() {
			this.setHours(0);
	        this.setMinutes(0);
	        this.setSeconds(0);
	        this.setMilliseconds(0);
	        return this;
		},
	
		today: function() {
			return this.clearTime();
		},
	
		get12HourHour: function () {
			return (this.getHours() > 12) ? this.getHours() - 12 : (this.getHours() === 0) ? 12 : this.getHours();
		},
		
		get24HourHour: function() {
			return this.getHours();
		},
		
		getDesignator: function () { 
			return (this.getHours() < 12) ? "am" : "pm";
		},

		
		"dummy":""
    });

  
	function getTime() {
		return (new Date());
	}
  
	function tick() {
		var d = getTime();
		var h = d.getHours();
		var m = d.getMinutes();
		var s = d.getSeconds();
		hours(h);
		minutes(m);
		seconds(s);
	}
	
	function hoursHelper(hours) {
		hours= ( hours> 12 ) ? hours- 12 : hours;
		hours= ( hours== 0 ) ? 12 : hours;
		return hours;
	}
	
	function hours(hours) {
		// This function converts from 24 hour time to 12 hour
		hours = hoursHelper(hours);
		if ( hours >= 10 ) { 
			// logic for d4 and d3
			toggleBlocks("d1", 1);
			toggleBlocks("d2", (hours % 10)); // this is the second set of blocks
		} else {
			// logic for d2 and d1
			allOff("d1");
			toggleBlocks("d2", hours);
		}
	}
		
	function minutes(minutes) {
		var d2 = Math.floor(minutes / 10); // second;
		var d1 = (minutes % 10); // first
		toggleBlocks("d3", d2);
		toggleBlocks("d4", d1); // this is the second set of blocks
	}
	
	function seconds(seconds) {
		var d5 = Math.floor(seconds / 10); // first digit
		var d6 = (seconds % 10); // leftovers
		toggleBlocks("d5", d5);
		toggleBlocks("d6", d6);
	}
	
	// Turn off all the blocks in a digit group.
	function allOff(digit) {
		$(digit).getElements(".block").removeClass("on");
	}
		
	function toggleBlocks(digit, blocks) {
		var d = $(digit);
		var bs = d.getElements(".block");
		allOff(digit); // removes the on class
		
		// this will fill an array so that it only contains unique blocks
		var rbs = [];

		while (rbs.length < blocks) {
			//counter++;
			var b = bs.getRandom();
			if ( rbs.contains(b) == false ) {
				rbs.push(b);
			}
		}


		// we fill the blocks here
		rbs.each(function(el, i){
			el.addClass("on");
		});
		
	}
	
	function createDigits() {
		var digits = 6;
		digits.each(function(el, i){
			var id = "d" + (el+1);
			var c = new Element("div"); // this is simply a container with no styles
			var digit = new Element("div", {
				"id": id,
				"class": "digit" 
			}); // this is the digit
			
			var spacer = new Element("div").addClass("spacer");
			
			// now for major fun; adding the blocks to each
			var blocks = 3;
			switch (el+1) {
				case 1: blocks = 3; break;
				case 2: blocks = 9; break;
				case 3: blocks = 6; break;
				case 4: blocks = 9; break;
				case 5: blocks = 6; break;
				case 6: blocks = 9; break;
			}
			blocks.each(function(el, i) {
				digit.grab(new Element("div", {"class": "block"}));
			});
			
			c.grab(digit);
			c.grab(spacer);
			
			$("clock").grab(c);
			
		});
		
		
	}
	
	var clock = null;
  
	window.addEvent("domready", function(){
	createDigits();
		clock = tick.periodical(1000);
	});
  