var defIcon	= ["dog park","dog wash","veterinarian","animal hospital"];

function OnLoad() 
{
	// Create an array of hotspots. Each entry contains and html element
  	// from your page, and the query to execute when that element is clicked
  	var hotspotsList = [
      { element : document.getElementById("hs01"), query : "dog park+dogs+parks+dog+park" },
      { element : document.getElementById("hs02"), query : "dog wash+dog+wash" },
      { element : document.getElementById("hs03"), query : "veterinarian" },
      { element : document.getElementById("hs04"), query : "animal hospital" }
  	];
    
	var options = {
	//            title : "Googleplex",
	//            url : "http://www.google.com/corporate/index.html"
		activeMapZoom 	: GSmapSearchControl.ACTIVE_MAP_ZOOM-10, 
		zoomControl 	: GSmapSearchControl.ZOOM_CONTROL_ENABLE_ALL,
        mapTypeControl 	: GSmapSearchControl.MAP_TYPE_ENABLE_ALL, // This line is custom code!
	    showResultList 	: document.getElementById("results-inside"),
		hotspots 		: hotspotsList
    }
	
	var center = new Object(); 
	center.lat = 37.0902; 
	center.lng = -95.7129; 

    new GSmapSearchControl(
		document.getElementById("map-inside"),
		center,
		options
	);
}

function in_array(query)
{	
	var found	= false;
	
	for(var i=0;i<defIcon.length;i++)
	{
		result	= query.search(defIcon[i]);		
		
		if( result != -1)
		{
			found = true;
			break;
		}
	}
	
	return found;	
}

function search_array(query)
{	
	var found	= 0;
	
	for(var i=0;i<defIcon.length;i++)
	{
		result	= query.search(defIcon[i]);		
		
		if( result != -1)
		{
			found = i;
			break;
		}
	}
	
	return found;	
}


GSmapSearchControl.prototype.newSearch = function(opt_query) 
{
	if (this.searchForm.input.value) 
	{
		var address	= jQuery('input.gsc-input').attr('value');
		var title	= "";
		var array_number	= 0;
		var term	= "";
		
		
		title		= title + " near " + address;
		
		// clear markers, set prev/next
        this.clearMarkers();
        GSmapsc_removeChildren(this.attributionDiv);
        // I added from here to the next comment
        
		var i = this.searchForm.input.value;
				  
        if (!in_array(opt_query)) 
		{
			title	= "dog parks" + title;
			
		 	i = i + "+dog park+dogs+parks+dog+park"; 
			jQuery("ul.tabs li").removeClass("active")
			jQuery("ul.tabs li:first").addClass("active").show(); //Activate first tab

		} else
		{ 
			array_number	= search_array(opt_query);
			term			= defIcon[array_number];
			if(term == 'dog wash')
			{ term	= 'dog washes'; }
			else { term = term + "s"; }
			
			title			= term + title;
			
			i	= i + '+' + opt_query;
		}
				  		  
		// Stopped adding here
        this.gs.execute(i);
		this.gmap.setZoom(12); 
		jQuery("#result-title").text(title);
	}
    
	return false;
	
}

GSearch.setOnLoadCallback(OnLoad);