// autocomplete _renderItem patch
function patchAutocomplete() {
 $.ui.autocomplete.prototype._renderItem = function(ul,item) {
  return $("<li></li>")
  	.data("item.autocomplete", item)
  	.append("<a>"+item.head+"<span>"+item.subhead+"</span></a>")
  	.appendTo(ul);
 };
}

// autocomplete hook
$(function() {
		var cache = {},
			lastXhr;
		$( "#quicksearch" ).autocomplete({
			minLength: 1,
			select : function( event, ui ) {
			 window.location.href = ui.item.link;
			 return false;
			},
			source: function( request, response ) {
				var term = request.term;
				if ( term in cache ) {
					response( cache[ term ] );
					return;
				}

				lastXhr = $.getJSON( "/ac.php", request, function( data, status, xhr ) {
					cache[ term ] = data;
					if ( xhr === lastXhr ) {
						response( data );
					}
				});
			}
		});
	});
