//------------------------------------
//	
//	BOOKONLINE.JS
//	
//------------------------------------

////////////////////////////
// BEGIN JQUERY

$(function(){

	$('#book_online input#search').autocomplete({
	
		source:	function(request, response){

			// Add in the locations
			$.getJSON('/ajax/restaurant_autocomplete', {search_term: request.term}, function(locations){
				
				if( locations ){
					response($.map(locations, function(item){
					
						return {
							label: item.name,
							slug: item.slug
						}
						
					}));
					
				}
				
			});
			
			// Start search
//			findMyNearest(request.term, {
//				dataSource: '/ajax/restaurant_search',
//				searchTotal: 4,
//				logger: false,
//				onBlank: function(){},
//				onResult: function(locations) {
//console.log(locations);
//					result = true;
//					error = false;
//
//
//
//				}
//			});
		},
		
		delay:		50,
		
		minLength:	2,
		
		select:		function(event, ui){
		
			window.location.href="/restaurant/" + ui.item.slug;
			
		},
		
		open:		function(event, ui){
		
			$(this).addClass('autocomplete');
			
			$('body > ul.ui-autocomplete').css({
				'z-index':	1001
			});
			
		},
		
		close:		function(){
		
			$(this).removeClass('autocomplete');
			
		}
	});
	
});
