$(document).ready(function(){
	/* item[1].replace(/(<.+?>)/gi, '')*/
	function formatItem (item) {return (item.length > 1 ? item[1] + ((item.length > 2 && item[2].length > 0) ? ' (' + item[2] + ')' : '') : ''); }
	function formatResult (item) { return (item.length > 1 ? item[1] : ''); }

	/* Festival search */
	$("#FestivalSearch").autocomplete("/festivals/autocomplete",{
		minChars: 4,
		cacheLength: 10,
		formatItem: formatItem,
		formatResult: formatResult,
		autoFill: false
	});
	$("#FestivalSearch").result(function(event, data, formatted) {
		if (data)
			window.location = data[3];
	});
	/* Artist search */
	$("#ArtistSearch").autocomplete("/artists/autocomplete",{
		minChars: 4,
		cacheLength: 10,
		formatItem: formatItem,
		formatResult: formatResult,
		autoFill: false
	});
	$("#ArtistSearch").result(function(event, data, formatted) {
		if (data)
			window.location = data[3];
	});
	/* Dance school search */
	$("#SchoolSearch").autocomplete("/schools/autocomplete",{
		minChars: 4,
		cacheLength: 10,
		formatItem: formatItem,
		formatResult: formatResult,
		autoFill: false
	});
	$("#SchoolSearch").result(function(event, data, formatted) {
		if (data)
			window.location = data[3];
	});
});

