$(function() {
	/***************************
		Kosher Products
	 ***************************/

	$('.product-search-text, input[value=Product Search]').autocomplete(
		"/includes/_ac_kosher_products",
		{		
			minChars:3,
			matchSubset:1,
			cacheLength:10,
			maxItemsToShow:10,
			width:240
		}
	).result(function(event, item){
		location.href = 'http://www.oukosher.org/index.php/product_search#' + $('.product-search-text').val();	
	});
	
	
	/**************************
		OU Torah
	 **************************/
	 
	$('.torah-search-text').autocomplete(
		"/includes/_ac_torah",
		{		
			minChars:3,
			matchSubset:1,
			cacheLength:10,
			maxItemsToShow:10,
			width:240,
			delay:100
		}
	).result(function(event, data, formatter){
		$('.torah-search form .torah-search-text').val(data);
		$('.torah-search form').submit();	
	});
	
	/**************************
		Shuls
	 **************************/

	$('.shuls-search-text').autocomplete(
		"/includes/_ac_shuls",
		{		
			minChars:3,
			matchSubset:1,
			cacheLength:10,
			maxItemsToShow:10,
			width:240
		}
	).result(function(event, data, formatted){
		$('.shul-search form .shuls-search-text').val(data);
		$('.shul-search form').submit();
	});

	/**************************
		OU
	 **************************/

	$('.ou-search-text').autocomplete(
		"/includes/_ac_ou",
		{		
			minChars:3,
			matchSubset:1,
			cacheLength:10,
			maxItemsToShow:10,
			width:240
		}
	).result(function(event, item){
//		location.href = 'http://www.oukosher.org/index.php/product_search#' + $('.product-search-text').val();	
	});
	
	/**************************
		Jobs
	 **************************/
	 
	$('.jobs-search-text').autocomplete(
		"/includes/_ac_jobs",
		{		
			minChars:3,
			matchSubset:1,
			cacheLength:10,
			maxItemsToShow:10,
			width:300
		}
	).result(function(event, data, formatted){
		var id = $(formatted).attr('id');
		$('.jobs-search-text').val($(formatted).html());
		location.href = 'http://www.ou.org/jobs/job-hiring4/' + id;
	});
});
