//+ Jonas Raoni Soares Silva
//@ http://jsfromhell.com [v1.0]

String.prototype.repeat = function(l){
	return new Array(l+1).join(this);
};


function rando (range, decimals) {
	decimals = decimals || 0;
	var factor = Math.pow(10, decimals);
	return parseInt(Math.random() * range * factor)/factor;
}

//firebugx
if (!window.console || !console.firebug)
{
    var names = ["log", "debug", "info", "warn", "error", "assert", "dir", "dirxml",
    "group", "groupEnd", "time", "timeEnd", "count", "trace", "profile", "profileEnd"];

    window.console = {};
    for (var i = 0; i < names.length; ++i)
        window.console[names[i]] = function() {}
}


$(function () {

	$("#letter-box").css({width:'100%',height:$(window).height()});
	
	$(document).keypress(function (e) {
		if (e.which == 32 || (65 <= e.which && e.which <= 65 + 25)
			|| (97 <= e.which && e.which <= 97 + 25)) {
			var c = String.fromCharCode(e.which);
			$('#words').append(document.createTextNode(c));
		} else if (e.which == 8) {
			// backspace in IE only be on keydown
			$('#words').children(":last").remove();
		}
		$("#letter-box").text(c);
		$("#letter-box").stop(true, true).show().fadeOut();
		$('body').css({backgroundColor:'rgb('+rando(255)+','+rando(255)+','+rando(255)+')'});
	});
	
});
