//////////////////////////////////////////////////////////////////
// icoSearch.js                                                 //
// script pour la recherche & l'autosuggest                     //
//////////////////////////////////////////////////////////////////

/** Init autosuggest on Search Input */
$(document).ready(function() {
/*
});

jQuery(function() {
*/
	//==================== Search With all plugins =================================================
	// Unbind form submit
	$('.home_searchEngine').bind('submit', function() {return false;} ) ;
	
	// Set autosuggest options with all plugins activated
	var options = {
		script:"inc/frontend.php?json=true&limit=50&",
		varname:"input",
		json:true,						// Returned response type
		shownoresults:true,				// If disable, display nothing if no results
		noresults:"Heu.. Vous croyez ?",			// String displayed when no results
		maxresults:50,					// Max num results displayed
		cache:false,					// To enable cache
		minchars:2,						// Start AJAX request with at leat 2 chars
		timeout:100000,					// AutoHide in XX ms
		callback: function (obj) { 		// Callback after click or selection
			// For example use :
						
			// Build HTML
			var html = obj.info;
			var sid =  obj.sid;
			var lat =  obj.lat;
			var lng =  obj.lng;
			var type = obj.type;
			var loc = obj.loc;
			//$('#input_search_all_response').html(html).show() ;
			//$('.inputbox').val(html) ;
			//alert (city);		
			/*alert (lat);		
			alert (lng);		
			alert (loc);		*/
			/////////
			addMarkersForRegion(sid,lat,lng,type,loc);	
			$.get("inc/json.php",
				{ id: sid,  lat: lat, lng: lng, type: type },
				function(data){
					
					//alert("Data Loaded: " + data);
				}
			);			
			/////////
			
			// => TO submit form (general use)
			//$('#search_all_value').val(obj.id); 
			//$('#form_search_country').submit(); 
		}
	};
	// Init autosuggest
	var as_json = new bsn.AutoSuggest('input_search_all', options);
	
	// Display a little watermak	
	$("#input_search_all").Watermark("ex : Friture, Bio, am...");
	$("#searchInput").Watermark("Saisissez le nom d'une ville");


});

/**
* fin ajout farcebook search
*
*/

