$(document).ready(function() {
	$("input[name=szukaj]").autocomplete("/mpng2-front/suggestions.lmf", {
		minChars : 2,
		cacheLength : 1,
		selectFirst : false,
		extraParams : {
			szukaj : function() {
				return $("input[name=szukaj]").val()
			},
            timestamp : "",
            q : ""
		},
		width : 200,
		formatItem : function(row, i, max) {
			var num = '';
			if (row[1] <= 50)
				num = ' >&nbsp;10';
			if (row[1] > 50 && row[1] <= 100)
				num = ' >&nbsp;50';
			if (row[1] > 100 && row[1] <= 500)
				num = ' >&nbsp;100';
			if (row[1] > 500 && row[1] <= 1000)
				num = ' >&nbsp;500';
			if (row[1] > 1000)
				num = ' >&nbsp;1000';
			return '<span class="phrase">' + row[0]
					+ '</span> <span class="count">'
					+ num + '</span>';
		}

	}).result(function(event, data, formatted) {
		if (data) {
			$(this).parent().next().find("input").val(data[1]);
		}
	});
	$('.ac_input').keydown(function(event) {
		if (event.keyCode == 13) {
			if (navigator.userAgent.match(/Opera/)) {
				setTimeout("operaSubmit();document.getElementById('search-form').submit();", 400);
			} else {
				$('#search-form').submit();
			}
		}
	});
});

