$ = jQuery.noConflict();
$(function(){
	$(".searchBox").keyup(function(e){
		$this = $(this);
		search_text = $this.val();
		if(search_text.length>0){ 
			placeholder = $("#siteSearchAutocomplete").show();
			placeholder.html("Loading suggestions...");
			if(search_text){ // @TODO: don't make ajax calls if right-arrow is pressed
				$.ajax({
					url: "http://vioafrica.com/search.suggestions/ajax.php",
					type: "post",
					dataType: "html",
					data: "search_text="+encodeURIComponent($this.val()),
					error: function(){
						// pass
					},
					success: function(html){
							if(html.length>0){ // result exists
								placeholder.html(html).appendTo(".search_container").show();
							} else {
								$("#siteSearchAutocomplete").hide();
							}
						}
					});
				}
		}
		if(search_text.length==0){
			if($("#siteSearchAutocomplete").length>0){
				$("#siteSearchAutocomplete").hide();
			}
		}
		});
	$("body").bind("click", function(e){
		$("#siteSearchAutocomplete").hide();
	});
});

