/* use a "bodyguard" function to be able to rely on $ = jQuery in the function body */
(function($) {
	$(document).ready(function() {
		function format(item) {
			
			return item.name;
		}
		autocompleteField.autocomplete('autocomplete.php', {
			minChars: 2,
			dataType: "json",
			cacheLength: 1,
			matchSubset: false,
			autoFill: false,
			selectFirst: false,
			/* remove the // in the following line to turn of scrollbars for the suggestbox so it always takes the required height */
			scroll: true,
			scrollHeight: 180,
			/* set the width for the suggestion field, remove the // to activate */
			//width: 200, 
			parse: function(data) {
				return jQuery.map(data.suggestions, function(row) {
					row = row.split("|");
					return {
						data: {name: row[0], count: row[1]},
						value: row[0],
						result: row[0]
					}
				});
			},
			formatItem: function(item) {
				return format(item);
			},
			extraParams: {
				autoq: function() { return autocompleteField.val(); },
				count: 10 /* set the maximum number of suggestions */
			}
		});
	});
})(jQuery);

