var searchFieldId = "real_suchbox_header"; 
var categoryDelimiter = ">";
var exoProxyUrl = "/ecs-packet/suggest"; 
var exoProjectId = 344;

var searchFieldPath = "#" + searchFieldId;

var exo_search_result = "/realstore/Suchergebnis";
var exo_form_id = "CatalogProductSearchForm";
var exo_selector_form = "#" + exo_form_id;
var exo_q;
if (location.pathname === exo_search_result && location.hash === ""
	 && location.search.search(/[?&]q=[^&]+/) >= 0) {
	exo_q = location.search.match(/[?&]q=[^&]+/)[0].substr(3);
	location.replace(location.href + "#q=" + exo_q.replace(/%26/g, "$amp;").replace(/%3D/g, "$eq;"));
}

$(document).ready(function() {
	/* if (location.hash.search(/[#&]q=[^&]+/) >= 0) { */
	/* 	exo_q = location.hash.match(/[#&]q=[^&]+/)[0].substr(3); */
	/* 	$(searchFieldPath).val(exo_q).focus().blur(); */
	/* } */

	$(searchFieldPath).result(redirect);

	$(searchFieldPath).autocomplete(exoProxyUrl, {
		max: 25,
		exoUrl: "http://commerce.exorbyte.de/",
		extraParams: { Bias: 100, SN_limit: "display=type" },
		projectId: exoProjectId,
		leftOffset: -9,
		topOffset: 5,
		width: 325,
		formatHeader: formatHead,
		formatItem: secondColNone
	});

	$("form:has(#real_suchbox_footer)").submit(function () {
		$(window).scrollTop(0);
		var query = encodeURI($("#real_suchbox_footer").val()).replace(/&/g, "$amp;").replace(/=/g, "$eq;");
		location.assign(exo_search_result + "#q=" + query);
		return false;
	});

	if ($("#exo-results").size() === 1) {
		$('body').attr('style', '');
		$(searchFieldPath).mainsearch(exoProxyUrl, {
			projectId: exoProjectId,
			sortBrandsByCount: false,
			sortCategoriesByCount: true,
			formatAddToCart: false,
			rowsPerPage: 16,
			currencySymbolAfterPrice: true,
			currencySymbol: "&euro;",
			decimalPoint: ",",
			noResultsMsg: "Ihre Suche ergab keine Treffer.",
			of: "von",
			to: "bis",
			results: "Treffer",
			sortBy: "Sortieren nach",
			relevance: "Treffergenauigkeit",
			lowestPrice: "Preis aufsteigend",
			highestPrice: "Preis absteigend",
			categories: "Kategorien",
			brands: "Marke",
			prices: "Preis",
			brand: "Hersteller",
			more: "weitere",
			deselect: "Aufheben",
			imageDir: "http://content.exorbyte.com/feeds/real/ecs-packet/img",
			useImgCache: false
		});
	} else {
		$(exo_selector_form).submit(function () {
			var query = encodeURI($(searchFieldPath).val()).replace(/&/g, "$amp;").replace(/=/g, "$eq;");
			location.assign(exo_search_result + "#q=" + query);

			return false;
		});
	}			
});

