(function($) {
	$.fn.autocomplete = function(options){
		var defaults = {
			lang : "fr",
			show_width : 260,
			begin_search : 3,
			default_text : "Search here", 
			slide_speed: 500
		};
		
		// On étend les options
		var opt = $.extend({}, defaults, options);
				
		// On crée une variable pour notre objet
		var obj = $(this);
		obj.val(opt.default_text);
			
		// On crée une div qui englobe le tout
		obj.after("<div id='"+obj.attr("id")+"_search'></div>");
		
		// On véhicule une variable currentlymoving sur notre objet
		obj.data("currentlyMoving", false);
		
		// Creation d'une variable pour l'enfant qui est visible
		var currentlyShow = 0;
		
		// On crée une variable pour notre conteneur principal
		var searchDiv = $("#"+obj.attr("id")+"_search");
		
		searchDiv.css({
			"width":opt.show_width+"px",
			"position":"absolute",
			"right":"10px",
			"top":"75px",
			"z-index":"2000"
		});
		
		obj.click(function(){
			var val = $(this).val();
			if(val == opt.default_text){
				$(this).val("");
			}
		});
		
		obj.keyup(function(){
			var val = $(this).val();
			if(val.length >= opt.begin_search){
				 $.ajax({
				   type: "POST",
				   url: "data-search.php",
				   data: "mot="+val+"&lang="+opt.lang,
				   success: function(msg){
				     if(msg != ""){
				     	searchDiv.css({
				     		"border-top": "1px solid #303030",
							"border-bottom": "1px solid #303030",
							"padding": "10px"
				     	});
				     } else {
				     	searchDiv.css({
				     		"border": "none",
							"padding": "0"
				     	});
				     }
				     searchDiv.html( msg );
				   }
				 });

			} else {
				searchDiv.empty();
				searchDiv.css({
		     		"border": "none",
					"padding": "0"
		     	});
			}
		});
	};
})(jQuery);
