﻿google.load("search", "1");

$(document).ready(function() {
	$("#search").blur(function () {
		if($(this).val() == ""){
			$(this).val("SEARCH");
			$("#resultbox").css("display", "none"); 
		}
	});
	
	$("#search").focus(function () {
		if ($(this).val() == "SEARCH") {
			$(this).val("");
		}
	});
	
	$("#search").keyup(function () {
		$("#resultbox").css("display", ""); 
		$("#footer").css("display", "none");
		//$(".siteheader").html('<img src="images/loading.gif" width="16" height="16" style="margin-right:8px; vertical-align:-15%;" />Loading Results from Site...');
		$(".googleheader").html('<img src="images/loading.gif" width="16" height="16" style="margin-right:8px; vertical-align:-15%;" />Loading Results from Google...');
		
		/* === Site Search === 
		$.ajax({ 
			method: "get",
			url: "sitesearch.htm",
			success: function(html){  
				$(".siteheader").html('Results from Site:');
				$("#sitesearch").html(html); 
			}
		}); */
		
		/* === Google Search === */
		var sc = new GSearchControl();
	    
	    var searcher = new google.search.WebSearch();
	    var options = new google.search.SearcherOptions();
	    searcher.setSiteRestriction("007877004247474223534:pddipscvk6g");
	    searcher.setUserDefinedLabel("ScienceBased Health Search Result");   
		sc.addSearcher(searcher, options);
		
		/*sc.addSearcher(new GvideoSearch());
		sc.addSearcher(new GblogSearch());
		sc.addSearcher(new GnewsSearch());*/

		var drawOptions = new GdrawOptions();
		drawOptions.setDrawMode(GSearchControl.DRAW_MODE_TABBED);
		
		var foo;
		sc.setSearchCompleteCallback(foo, function(){
			$(".googleheader").html('Results from Google:');
		});
		sc.setNoResultsString(GSearchControl.NO_RESULTS_DEFAULT_STRING);

	    sc.draw(document.getElementById("googlesearch"), drawOptions);
		sc.execute(document.getElementById("search").value);
		/* === End Search === */
		
		if($(this).val() == ""){
			$("#resultbox").slideUp(400, function(){
				$("#footer").css("display", "");
			});
		}
	});
});
