/**
 *@author Sam McCallum <sam@palo-verde.us>
 */
 
/**
 * Utility function to draw words
 */
function DrawWord(word, container) {
	for (var it = word.length;it>0;it--) {
		var character = word.charAt(it-1);
		if (character == ' ') character="space";
		eval(character+'.drawInto(\''+container+'\');');
	}
};

/**
 * Define an object for building letters
 */
function Letter() {
	this.buildLetterArray();
};

Letter.prototype = {
	drawInto: function (container) {
		var letter = new Element('div', {className: 'letter'});
		this.letterArray.each(
			function (el) {
				el.each(
					function (pix) {
						var pixelState;
						if (pix) {
							pixelState = 'pixel on';
						} else {
							pixelState = 'pixel off';
						}
						
						letter.insert(new Element('div',{className: pixelState}));
					}.bind(this)
				);
			}.bind(this)
		);
		
		$(container).insert(letter);
	},
	
	buildLetterArray: function () {
		this.letterArray = new Array(5);
		Number(5).times(
			function (index) {
				this.letterArray[index] = new Array(8);
			}.bind(this)
		);
	},
	
	stateRow: function (rowNum, state) {			
		Number(8).times(
			function (index) {
				this.letterArray[rowNum][index] = state;
			}.bind(this)
		);
	},
	
	blankRow: function (rowNum) {
		this.stateRow(rowNum, false);
	},
	
	fillRow: function (rowNum) {
		this.stateRow(rowNum, true);
	},
	
	populateRow: function (rowNum, array) {
		array.length.times(
			function (index) {
				this.letterArray[rowNum][index] = array[index];
			}.bind(this)
		);
	}
};