firstRun = true;
$(document).ready(function() {
    setTimeout("initialLoad()", 1500);

    if ($("#searchBox")) {
        $("#searchBox").autocomplete("/CMSData/Templates/Content/Publicsite/Foodcures/widget/asp/jbwidget_dropdownsearch.asp");
        $("#searchBox").result(function(event, item) {
            if (firstRun) {
                firstRun = false;

                // animate intro
                if ($("#contentBody_intro")) {
                    $("#contentBody_intro").fadeTo("slow", 0, function() {
                        $("#contentBody_intro").css({ 'display': 'none' });
                        $("#contentBody_results").html(item[1]);
                        $("#contentBody_entry").fadeIn("slow", function() { });
                    });
                }
            }
            else {

                if ($("#contentBody_results")) {
                
                    // animate results
                    $("#contentBody_results").fadeTo("slow", 0, function() {
                        $("#contentBody_results").html(item[1]);
                        $("#contentBody_results").fadeTo("slow", 1, function() {
                        });
                    });
                }
            }
            
            if (item && item[0] == "No Results" && document.getElementById("searchBox")) {
                document.getElementById("searchBox").value = "";
            }
        });
    }
}); 

	function initialLoad() {
	    if (document.getElementById("contentSearch_firstLoader")) {
	        document.getElementById("contentSearch_firstLoader").style.display = 'none';
	        document.getElementById("contentSearch_input").style.display = 'block';
	    }
	}
	
	function manualSearch()
	{
	    $.get("/CMSData/Templates/Content/Publicsite/Foodcures/widget/asp/jbwidget_dbsearch.asp", { q: $("#searchBox").val() },
	function(data) {
	    if (firstRun) {
	        firstRun = false;

	        if ($("#jbwidget_bottom_content")) {

	            // animate widget
	            $("#jbwidget_bottom_content").fadeTo("slow", 0, function() {
	                if ($("#jbwidget_bottom_content"))
	                    $("#jbwidget_bottom_content").css({ 'display': 'none' });

	                if ($("#contentBody_results")) {
	                    $("#contentBody_results").html(data);
	                    $("#contentBody_results").fadeIn("slow", function() { });
	                }

	                if ($("#jbwidget_bottom_copy"))
	                    $("#jbwidget_bottom_copy").fadeIn("slow", function() { });
	            });
	        }
	    }
	    else {

	        if ($("#contentBody_results")) {
	            $("#contentBody_results").fadeTo("slow", 0, function() {

	                if ($("#contentBody_results")) {
	                    $("#contentBody_results").html(data);
	                    $("#contentBody_results").fadeTo("slow", 1, function() { });
	                }
	            });
	        }
	    }
	});
}
