function rand(min, max) {
	return Math.floor(Math.random() * (max - min)) + min;
}

(function ($) { $(function () {
	//on ready and with proper scope
	
	$('.hoverable').hover(
		function () { $(this).addClass('hover'); },
		function () { $(this).removeClass('hover'); }
	);

}); })(jQuery);

//interrupt plugin
(function($) {
	$.fn.interrupt = function(options) {
		// Set the options.
		var options = $.extend({}, $.fn.interrupt.defaults, options);

		// Go through the matched elements and return the jQuery object.
		return this.each(function() {
			var $form = $(this);
			
			if(options.useMessage) {
				$form.prepend('<div class="message"></div>');
			}
			$form.prepend(options.prepend);
			
			$form.submit(function () {
				
				options.before();
				
				$.ajax({
					type: $form.attr('method'),
					url: $form.attr('action'),
					dataType: options.dataType,
					data: $form.serialize(),
					success: function (response, status) {
						if(options.useMessage) {
							$form.children('div.message')
								.attr('className', 'message ' + response.status)
								.html(response.message)
								.show();
						}
						options.success(response, status);
					},
					error: function (request, status, error) {
						options.error(request, status, error);
					},
					complete: function (request, status) {
						$form.find('.focus').focus();
						options.complete(request, status);
					}
				});

				return false;
			});
		});
	};
	
	// Public defaults.
	$.fn.interrupt.defaults = {
		dataType: 'json',
		before: function() {}, //$.noop,
		success: function() {}, //$.noop,
		error: function() {}, //$.noop,
		complete: function() {}, //$.noop,
		useMessage: true,
		prepend: '<input type="hidden" name="interrupt" value="1" />'
	};
	
	// Public functions.
	/*$.fn.plugin.func = function() {
		return;
	};*/
})(jQuery);