/* 
################################
 _____                 _     _     _                       
|_   _|   _ _ __   ___| |   (_)___| |_ ___ _ __   ___ _ __ 
  | || | | | '_ \ / _ \ |   | / __| __/ _ \ '_ \ / _ \ '__|
  | || |_| | |_) |  __/ |___| \__ \ ||  __/ | | |  __/ |   
  |_| \__, | .__/ \___|_____|_|___/\__\___|_| |_|\___|_|   
      |___/|_|

	TypeListener 1.1
	by: Hugo Wiledal
	
	presented as is with
	no warranties
	
################################
*/
TypeListener = function(attachObject, limit) {
	this.listenList = [];
	this.limit = limit || 50;
	this.lastTyped = "";
	this.listen(attachObject || window);
}
TypeListener.prototype = {
	add : function(word, func) {
		this.listenList[word] = func;
	},
	remove : function(word) {
		delete this.listenList[word];
	},
	listen : function(attachObject) {
		var _this = this;
		attachObject.onkeyup = function(event) {
			_this.lastTyped = _this.lastTyped + String.fromCharCode(event.keyCode);
			for (i in _this.listenList) {
				if (_this.lastTyped.indexOf(i.toUpperCase()) != -1) {
					_this.listenList[i]();
					_this.lastTyped = "";
				}
			}
			if (_this.lastTyped.length > _this.limit) {
				_this.lastTyped = _this.lastTyped.slice(1);
			}
		}
	}
}
