$().ready(function() {

	function findValueCallback(event, data, formatted) {
		$("<li>").html( !data ? "Nu am gasit sugestii" : "Selectat: " + formatted).appendTo("#result");
	}
	
	function formatItem(row) {
		//return row[0] + " (<strong>id: " + row[1] + "</strong>)";
		return row[0];
	}
	function formatResult(row) {
		return row[0].replace(/(<.+?>)/gi, '');
	}
	
	$("#q").autocomplete('mini.module.php?do=sugestii', {
		width: 260,
		multiple: false,
		matchContains: true,
		formatItem: formatItem,
		formatResult: formatResult
	});
	$(":text, textarea").result(findValueCallback).next().click(function() {
		$(this).prev().search();
	});
	$("#scrollChange").click(changeScrollHeight);
	
	$("#clear").click(function() {
		$(":input").unautocomplete();
	});
});

function changeOptions(){
	var max = parseInt(window.prompt('Please type number of items to display:', jQuery.Autocompleter.defaults.max));
	if (max > 0) {
		$("#suggest1").setOptions({
			max: max
		});
	}
}

function changeScrollHeight() {
    var h = parseInt(window.prompt('Please type new scroll height (number in pixels):', jQuery.Autocompleter.defaults.scrollHeight));
    if(h > 0) {
        $("#suggest1").setOptions({
			scrollHeight: h
		});
    }
}