;(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 pug] - '+message);
	}
};
$.fn.vektorpug = 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.vektorpug.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 setupDOM(){
	$("#pug").append("<div id='pug-top'></div>");
	$("#pug-top").append("<div id='pug-content'></div>");
	$("#pug-content").append("<h3>You just got pugged</h3><a href='#' id='close-pug'></a>");
}

function init(container, options){
	setupDOM();
	if( $(options.closebutton).size() > 0){
		$(options.closebutton).live("click", function(event){
			event.preventDefault();
			container.animate({
			bottom: "-"+options.height
			});
		});
	}
	else{
		log("No close button defined.");
	}
	document.onkeyup = function keyPress(e){
		var id = (window.event) ? event.keyCode : e.keyCode;
		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){
			container.animate({
				bottom: "0px"
			});
			Cufon.replace('#pug-content h3');
		}
		
		this.timeout = setTimeout(function(){
			keys = [];
		}, 1000);
	} 
	
	if(options.selector){
		
		$(options.selector).css({
			"width": "100%",
			"height": options.height,
			"position": "fixed",
			"left": "0px",
			"bottom": "-"+options.height,
			"z-index": "110"
		});
		var word = options.trigger;
		word = word.toUpperCase();
		
		for(i=0; i<word.length;i++){
			match.push(word.charCodeAt(i));
		}
	}
	else 
		return false;
};
//	Public default options for the plugin.
$.fn.vektorpug.defaults = {
	trigger: "pug",
	height: "282px",
	closebutton: "#close-pug"
};
//	Public function that returns the current version of the plugin.
$.fn.vektorpug.ver = function() { return ver; };
})(jQuery);
