// NOTICE: ALWAYS RETURN THE JQUERY!
(function($) {
	'use strict';

	// apply to <a>nchors, forces browser to open href in a new window
	$.fn.blank = function() {
		return this.click(function(e) {
			window.open(this.href);
			e.preventDefault();
			e.stopPropagation();
		});
	};
	// shows & hides children on hover
	$.fn.revealing = function() {
		return this.hover(
			function() { $('.hidden', this).show(); },
			function() { $('.hidden', this).hide(); }
		);
	};
	// add & removes .hover class of .hovers on hover
	$.fn.hovers = function() {
		return this.hover(
			function() { $(this).addClass('hover'); },
			function() { $(this).removeClass('hover'); }
		);
	};
	// blurs element on click
	$.fn.blurry = function() {
		return this.click(function() { $(this).blur(); });
	};
	// focus & selects selected elements
	$.fn.selected = function() { return this.focus().select(); };


	// apply on <input>s to submit form on keypress(keyCode:ENTER)
	// and dblclick on radiobuttons, checkboxes, textfields
	// or click on buttons or images
	$.fn.hurry = function(keyCode, callback) {
		var form = this.parent('form');

		if (typeof(keyCode) == 'function') {
			callback = keyCode;
			keyCode = undefined;
		}
		if (typeof(keyCode) == 'undefined') keyCode = 13;
		if (typeof(callback) == 'undefined') callback = function(e) {
			form.submit();
			e.preventDefault();
		};

		if ($('input[type="submit"]', form).length == 0)
			this.after('<input type="submit" style="display: none;" />');

		return this
		.each(function() {
			var self = $(this),
				t = self.attr('type'),
				e = ('button' == t || 'image' == t)? 'click' : 'dblclick';

			self.bind(e, callback);
		})
		.keypress(function(e) {
			if (keyCode == (e.keyCode || e.which)) callback.apply(this, [e]);
		});
	};

})(jQuery);

