jQuery(function($) {
	$.fn.extend({
		localizare: function(options) {
			var $$	= $(this),
				s	= $.extend({}, $.fn.localizare.defaults, options),
				o 	= $.metadata ? $.extend({}, s, $$.metadata()) : s,
				k	= [];
			
			return this.each(
				function() {
					$$.bind('keydown.localizare' + o.mod.toString(), function(e){
						k.push(e.keyCode);
						if(k.toString().indexOf(o.mod) >= 0){
							k = [];
							o.activated.call(this, o);
							unbind.call(this, o);
						}
					});
				}
			);
		}
	});
	
	complete = function(o){
		var $overlay = $('<div class="overlay"></div>')
			$message = $('<div class="modal"></div>');
		
		$message.text(o.message).appendTo('body');
		$overlay.appendTo('body');
		setTimeout(function(){
			$message.fadeOut(500, function(){
				$(this).remove();
				$overlay.fadeOut(500, function(){
					$(this).remove();
				});
			});
		}, 1000);
	};
	
	unbind = function(o){
		if(o.unbind===true) {
			$(this).unbind('keydown.localizare' + o.mod.toString());
		}
	};
	
	$.fn.localizare.defaults = {
		'mod' 		: '38,38,40,40,37,39,37,39,66,65',
		'unbind'	: true,
		'activated'	: complete,
		'message'	: 'Activat'
	};
});


