// google ajax search api
// load the libs on demand
google.load("search", "1");

// global variables
var siteSearch;
var searchControl;

// search in differents places
function searchInVancouver()
{
	// change label css classes
	jQuery("#searchVancouver").css("font-weight", "bold");
	jQuery("#searchWorld").css("font-weight", "");
	jQuery("#searchCanada").css("font-weight", "");
	
	// change the search target
	siteSearch.setSiteRestriction("vancouverliving.com");
}
function searchInWeb()
{
	jQuery("#searchWorld").css("font-weight", "bold");
	jQuery("#searchVancouver").css("font-weight", "");
	jQuery("#searchCanada").css("font-weight", "");
	siteSearch.setSiteRestriction(null);
}
function searchInCanada()
{
	jQuery("#searchCanada").css("font-weight", "bold");
	jQuery("#searchVancouver").css("font-weight", "");
	jQuery("#searchWorld").css("font-weight", "");
	siteSearch.setSiteRestriction("*.ca");
}

// load page call back
function OnLoad() 
{
	var options;
	var drawOptions;
	var gSearchForm;
	
	// create a searcher options object
	// set up for open expansion mode
	// load a searcher with these options
	options = new GsearcherOptions();
	options.setExpandMode(GSearchControl.EXPAND_MODE_OPEN);
	
	// Create a search control
	searchControl = new GSearchControl(null);
	
	// web search
	siteSearch = new GwebSearch();
	//siteSearch.setUserDefinedLabel("Amazon.com");
	siteSearch.setUserDefinedClassSuffix("siteSearch");
	//siteSearch.setSiteRestriction("amazon.com");
	searchControl.addSearcher(siteSearch, options);
	
	// create a drawOptions object
	drawOptions = new GdrawOptions();
	drawOptions.setSearchFormRoot(document.getElementById("searchForm"));
	
	// Tell the searcher to draw itself and tell it where to attach
	 searchControl.draw(document.getElementById("searchcontrol"), drawOptions);
	
	// create a search form without a clear button
	// bind form submission to my custom code
	gSearchForm = new GSearchForm(false, document.getElementById("searchForm"));
	//GSearchForm.input.src = "themes/vancouverliving/images/button-search.png";
	//alert(gSearchForm.userDefinedCell);
	gSearchForm.setOnSubmitCallback(null, CaptureForm);
	inputtext = gSearchForm.input;
	gSearchForm.input.focus();
	
	// by default search in Vancouver
	searchInVancouver();
}

// Cancel the form submission, executing an AJAX Search API search.
function CaptureForm(searchForm) {
  searchControl.execute(searchForm.input.value);
  return false;
}

function CreateBookmarkLink() {

 var url = location.href;
 var title = document.title;

 if (window.sidebar) { // Mozilla Firefox Bookmark
  window.sidebar.addPanel(title, url,"");
 } else if( window.external ) { // IE Favorite
  window.external.AddFavorite( url, title); }
 else if(window.opera && window.print) { // Opera Hotlist
  return true; 
 }
}
// call the load page callback
google.setOnLoadCallback(OnLoad);


// Hide script from older browsers 
// script by http://www.hypergurl.com 
//var urlAddress = "http://www.vancouverliving.com"; 
//var pageName = "Vancouverliving"; 

/* function addToFavorites() { 
	if (window.external) { 
		window.external.AddFavorite(location.href,document.title);
	} else { 
		alert("Sorry! Your browser doesn't support this function."); 
	}	
}*/

function CreateBookmarkLink() {

	var url = location.href;
	var title = document.title;

	if (window.sidebar) { // Mozilla Firefox Bookmark
		window.sidebar.addPanel(title, url,"");
	} else if( window.external ) { // IE Favorite
		window.external.AddFavorite( url, title); }
	else if(window.opera && window.print) { // Opera Hotlist
		return true; 
	}
}
