;(function($) {
var ver = 1.0;
var keys = [];
var match = [];
//	Simple log function to log runtime errors, mainly
//	for development.
function log(message){
	if (window.console && window.console.log){
	window.console.log('[vektor keyword] - '+message);
	}
};
$.fn.keyword = function(options) {
	//document.onkeyup = key_event(event); 
 	// get the current selector that called the function
	options.selector = this.selector;
	// we need to return the jQuery to allow it to be chained
	// further, and we'll iterate on the matched nodeset.
	return this.each(function() {
		// extend the default options, since some of them are
		// optional.
		options = $.extend($.fn.keyword.defaults, options);
		var $this = $(this);
		// init function, will only be called once per node.
		var opts = init($this, options);
		if(opts === false){	
			log("No element available, terminating.");
			return;
		}
	});
};

function init(container, options){
	
	document.onkeyup = function keyPress(e){
		clearTimeout(this.timeout);
		var checker = 0;
		var id = (window.event) ? event.keyCode : e.keyCode;
		keys.push(id);

		if(keys.length === match.length){			

			for(i=0; i<keys.length; i++){
				if(match[i] == keys[i]){
					checker++;
				}
				else{
					checker = 0;
				}
			}
		}
		
		if(checker === match.length){
			window.location.href = options.url;
		}
		
		this.timeout = setTimeout(function(){
			keys = [];
		}, 1000);
	} 
	

	var word = options.trigger;
	word = word.toUpperCase();
		
	for(i=0; i<word.length;i++){
		match.push(word.charCodeAt(i));
	}


};
//	Public default options for the plugin.
$.fn.keyword.defaults = {
	trigger: "kontakt",
	url: ""
};
//	Public function that returns the current version of the plugin.
$.fn.keyword.ver = function() { return ver; };
})(jQuery);
