$(function() {
	function format(item) {
		
		var img = '<span class="col col1"><img src="'+ item.image +'" width="35" height="35"></span>';
		
		var sku = '<span class="extra">'+ item.sku_txt +'</span>';
		
		var text = '<span class="text">'+ item.text +'</span>';
		
		return "<div style=\"position:relative;width:100%;\"> " + img + " " + text + " " + sku + "</div>";
	}
	$("input#suggestBox2").autocomplete('/search/search', {
		multiple: false,
		dataType: "json",
		width: 500,
		delay: 200,
		scrollHeight: 250,
		max: 20,
		autoFill: false,
		selectFirst: false,
		matchContains: false,
		mustMatch: false,
		parse: function(data) {
			return $.map(data, function(row) {
				return {
					data: row,
					value: row.id,
					result: row.text
				}
			});
		},
		formatItem: function(item) {
			return format(item);
			//return item.text;
		}
	}).result(function(e, item) {
		//$("#content").append("<p>selected " + format(item) + "</p>");
		//Replace the spatie met een _
		
		//reg = '/\s+/';
		//item.text.replace(reg,'+')
		
		//alert(item.text);
		//window.location = '/products/'+ item.id +'/'+ item.sku +'/'+ item.text +'';
		window.location = '/products/'+ item.url +'';
	});
	
});