
function recherche_main() {
	$("#recherche_loading").css("opacity", 0);
	$("#recherche_loading").attr("src", chemin + "/images/design/symboles/loading.gif");
	$("#recherche_loading").fadeTo("slow", 1);
	$.ajax({
		type: "GET",
		url: chemin + "/scripts/ajax/recherche/recherche.php",
		data: "q=" + $.trim( $("#recherche_input").val() ),
		success: function(string){
			$("#recherche_loading").fadeTo("slow", 0);
			
			if (string == "0") {
				string = "Tapez au moins 3 caractères pour lancer la recherche.";
				$("#recherche_tooltip").html(string);
			} else if (string == "1") {
				string = "Aucun résultat.";
				$("#recherche_tooltip").html(string);
			} else {
				//format : <Nom retenu ou integer si nom_c> | nom_c | dev | console \n
				data = string.split("\n");
				$("#recherche_tooltip").html("");
				for (n=0; n<data.length-1; n++) {
					line = data[n].split("||");
					sub = parseInt(line[0]);
					bulle = " ";
					if (isNaN(sub) == false) {
						if (sub == 0)
							line[0] = line[1];
						else {
							bulle = 'title="' + line[1] + '" ';
							line[0] = line[1].substr(0, line[1].length - sub) + "...";
						}
					}
					imgName = (line[1].replace(/ /g, "-")).replace(/:/g, "~");
					link = "<a " + bulle + "href=\""+chemin+"/glossaire/"+line[3]+"/"+(line[1].replace(/'/, "\'")).replace(/ /g, "-")+"/\" style='text-decoration:none; display:block'>";
					img = "<img border='0' alt='' width='25' height='25' border='0' src='" + chemin + "/images/logos/" + line[3] + "/" + imgName + ".jpg' style='margin-right:5px; vertical-align:middle; margin-bottom:2px;' />";
					texte = line[0] + ", " + line[2] + ", " + line[3].toUpperCase();
					$("#recherche_tooltip").append(link + img + texte + "</a>");
				}
			}
			$("#recherche_tooltip > a").Tooltip({
			    track: true, 
			    delay: 300, 
			    showURL: false
			    //showBody: " - "
			});
			
			//afficher les résultats
			if ($("#recherche_tooltip").css("display") == "none")
				expandPane("recherche_input", "recherche_tooltip");
			
			//donner le focus à l'input (bug firefox...)
			$("#recherche_input")[0].focus(); //DOM
		}
	});
}

$(document).ready(function(){
	recherche_timer = null;
	
	$("#recherche_input").keypress(function(){
		clearTimeout(recherche_timer);
		recherche_timer = setTimeout("recherche_main();", recherche_timerDelay);
	});
	$("#recherche_input").focus(function(){
		if ($("#recherche_tooltip").css("display") == "none") {
			clearTimeout(recherche_timer);
			recherche_main();
		}
	});
	
	//init input
	$("#recherche_input").blur(function(){
		$("#recherche_tooltip").fadeOut();
		try {
			clearTimeout(recherche_timer);
		} catch (e) {}
		if ( $.trim($(this).val()) == "" )
			$(this).val("Rechercher...");
	});
});