google.load("search", "1");

function googleSearchComplete() {
  if (webSearch.results && webSearch.results.length > 0) {
		items = jQuery.map(webSearch.results, function(a) {
			return "<li><b><a href='" + a.url + "'>" + a.titleNoFormatting + "</a></b><p>" + a.content + "</p></li>";
		});
		
		$("#google-search-result-web").html("<ol>" + items.join("") + "</ol>");
		webSearch.results = [];
	}
	
  if (blogSearch.results && blogSearch.results.length > 0) {
		items = jQuery.map(blogSearch.results, function(a) {
			return "<li><b><a href='" + a.postUrl + "'>" + a.titleNoFormatting + "</a></b><p>" + a.content + "</p></li>";
		});
		
		$("#google-search-result-blog").html("<ol>" + items.join("") + "</ol>");
		blogSearch.results = [];
	}
	
  if (videoSearch.results && videoSearch.results.length > 0) {
		items = jQuery.map(videoSearch.results, function(a) {
			return "<li><b><a href='" + a.url + "'>" + a.titleNoFormatting + "</a></b><p><img src='" + a.tbUrl + "' />" + a.content + "</p></li>";
		});
		
		$("#google-search-result-video").html("<ol>" + items.join("") + "</ol>");
		videoSearch.results = [];
	}
}

$(document).ready(function() {
	
	var searchControl = new google.search.SearchControl();
	searchControl.setResultSetSize(google.search.Search.LARGE_RESULTSET);
	
	var url = $("a#site_url").attr("href");
	
	webSearch = new google.search.WebSearch();
	webSearch.setSearchCompleteCallback(this, googleSearchComplete, null);
	webSearch.execute(url + " site:.com");

	blogSearch = new google.search.BlogSearch();
	blogSearch.setSearchCompleteCallback(this, googleSearchComplete, null);
	blogSearch.execute(url + " site:.com");

	videoSearch = new google.search.VideoSearch();
	videoSearch.setSearchCompleteCallback(this, googleSearchComplete, null);
	videoSearch.execute(url + " site:.com");

/*	var options = new google.search.SearcherOptions();
	options.setExpandMode(google.search.SearchControl.EXPAND_MODE_OPEN);
	options.setRoot(document.getElementById("google-search-result-web"));
	searchControl.addSearcher(webSearch, options);
	
	options.setRoot(document.getElementById("google-search-result-video"));
	searchControl.addSearcher(videoSearch, options);

	options.setRoot(document.getElementById("google-search-result-blog"));
	searchControl.addSearcher(blogSearch, options);

	searchControl.draw(document.getElementById("google-search-control"));
	searchControl.execute($("a#site_url").attr("href"));
*/});