jQuery(function($) {
	$('#global_search').live('focus', function() {
		$(this).select();
	});

	$('#global_search').live('response', function(e, data) {
		window.location = ROOT + 'search/all/' + data.q;
	});

	$('.pagination input.text').live('keydown', function(e) {
		// Setup
		var result = false;

		switch(e.keyCode) {
			default:
				result = true;
				break;

			// Enter
			case 13:
				$(this).closest('form').submit();
				result = true;
				break;

			// Up Arrow
			case 38:
				var max = $(this).siblings('input.text').val();
				var val = $(this).val();

				if(val < max) {
					$(this).val(++val);
				}
				break;

			// Down Arrow
			case 40:
				if($(this).val() > 1) {
					$(this).val($(this).val() - 1);
				}
				break;
		}

		return result;
	});
});
