// we will add our javascript code here.  When DOM loaded, code executes in .ready                               
 $(document).ready(function(){

	var a1;
	
	jQuery(function() {
	
	var onAutocompleteSelect = function(value, data, userQuerr) 
	{
	  // Note : The Form passes the data via GET (?q=toto) when user did not accept one of the selections
	  // Redirect to search results
	  // Note : escape does the URLEncoding (example space becomes '%20'
	  // Note : The javascript url encode (escape()) does not encode '+' or '/'.  The form 
	  //        encodes a space as a '+' while javascript encodes the space as '%20'
	  window.location = "recherche-animaux.php?q="+ escape(value);
	  
	  // This can add stuff to the page based on suggestions results - when user accepted one of the suggestions.
	  // $('#selection').html('<img src="\/global\/flags\/small\/' + data + '.png" alt="" \/> ' + value);
	  // alert(userQuerr);
	  // alert(value);
	}
	
	var options = {
	  serviceUrl: 'php/autot2.php',
	  width: 460,
	  delimiter: /(,|;)\s*/,
	  zIndex: 9999,
	  onSelect: onAutocompleteSelect,
	  deferRequestBy: 0, //miliseconds
	  params: { country: 'Yes' }
	};
	
	a1 = $('#query').autocomplete(options);
	
	$('#navigation a').each(function() {
	  $(this).click(function(e) {
		var element = $(this).attr('href');
		$('html').animate({ scrollTop: $(element).offset().top }, 300, null, function() { document.location = element; });
		e.preventDefault();
	  });
	});

});

 });  
