// JavaScript Document
$(document).ready(function() {
	// put all your jQuery goodness in here.
	var a = $('#query').autocomplete({
		serviceUrl:'/ajax/searchQuery.php',
		minChars:3, 
		//delimiter: /(,|;)\s*/, // regex or character
		delimiter: /(,|st[\-\.\s]?|saint|fort|ft[\-\.\s]?)\s*/, // regex or character
		maxHeight:400,
		width:280,
		zIndex: 9999,
		deferRequestBy: 0, //miliseconds
		//params: { country:'Yes' }, //aditional parameters
		noCache: false, //default is false, set to true to disable caching
		// callback function:
		onSelect: function(value, data){ 
			//alert('You selected: ' + value + ', ' + data);
			var url;
			var response;

			if(data!=0){
				response = data.split('|'); // example of data is L|location-url (used to be L|4|33) for locations or P|237 for properties
				
				switch(response[0]){
					case 'P':
						// data format is P|{property_id}
						url = '/vacation-rentals/' + response[1] + '/';
						break;
					case 'L':
						//data format is L|{location-url}
						url = '/vacation-rentals/' + response[1] + '/';
						break;
				}
				
				window.location = url;
			} else {
				$('#query').val(''); 	
			}
		}
	});
});
