/*global window, document, alert */

var bingo = new function() {
	this.count = 0;
	this.init = function() {
		if (!document.getElementsByTagName) { return false; }
		var buzzwords = document.getElementsByTagName("td");
		bingo.total = buzzwords.length;
		for (var i=0; i<bingo.total; i++) {
			buzzwords[i].onclick = function() {
				bingo.toggleState(this);
			};
		}
	};
	this.toggleState = function (buzzword) {
		if (!buzzword.className) {
			buzzword.className = "spoken";
			this.count++;
		} else {
			buzzword.className = "";
			this.count--;
		}
		if (this.count == this.total) {
			alert("BINGO!");
		}
	};
}();

window.onload = bingo.init;