// Local Google Maps Scripts.

		    var geocoder = new GClientGeocoder();
		    var addressMarker;
   					  
			function initialize() {
				if (GBrowserIsCompatible()) {
		        map = new GMap2(document.getElementById('mapDiv'));
			    geocoder = new GClientGeocoder();
        		map.addControl(new GSmallMapControl());
		        gdir = new GDirections(map, document.getElementById('directions'));
		        showLocation('Lubbock, Tx', 'Lubbock');
		        GEvent.addListener(gdir, "load", onGDirectionsLoad);
		        GEvent.addListener(gdir, "error", handleErrors);
		        }
			}
					    
		    function setDirections() {
		    	var fAddress = document.getElementById('end_location');
		    	var tAddress = document.getElementById('start_location');
		    	if(fAddress && tAddress){
		    		map.clearOverlays();
		    		fromAddress = tAddress.value;
		    		toAddress = fAddress.value;
			    	gdir.load("from: " + fromAddress + " to: " + toAddress);
		    	}
		    }
			
			function showAllresources(){
			    // Creates a marker at the given point
			    // Clicking the marker will hide it
			    
			    function createMarker(latlng, number) {
			    	var marker = new GMarker(latlng);
			    	marker.value = number;
			      GEvent.addListener(marker,"click", function() {
			        var myHtml = "<b>" + titles[number -1] + "</b><br/>" + addresses[number -1];
			        map.openInfoWindowHtml(latlng, myHtml);
			      });
			      return marker;
				}
			
			    // Add 5 markers to the map at random locations
			    // Note that we don't add the secret message to the marker's instance data
			    
			    for (var i = 0; i < titles.length; i++) {
			    
			      geocoder.getLocations(addresses[i], mapAllAddresses);/*
			      var latlng = new GLatLng(southWest.lat() + latSpan * Math.random(),
				    southWest.lng() + lngSpan * Math.random());
					map.addOverlay(createMarker(latlng, i + 1)); */
			    }
			  
			}
			
			function mapAllAddresses(response){
		      map.clearOverlays();
		      if (!response || response.Status.code != 200) {
		        alert("Sorry, we were unable to find that address");
		      } else {
		        place = response.Placemark[0];
		        point = new GLatLng(place.Point.coordinates[1],
		                            place.Point.coordinates[0]);
		        marker = new GMarker(point);
		        map.setCenter(point, 12);
		        map.addOverlay(marker);
		        
			      GEvent.addListener(marker,"click", function() {
			        var myHtml = "<b>" + titles[1] + "</b><br/>" + addresses[1];
			        marker.openInfoWindowHtml(marker, myHtml);
			      });
			      
		      }
			}

			// addAddressToMap() is called when the geocoder returns an
		    // answer.  It adds a marker to the map with an open info window
		    // showing the nicely formatted version of the address and the country code.
		    
		    function addAddressToMap(response) {
		      map.clearOverlays();
		      if (!response || response.Status.code != 200) {
		        alert("Sorry, we were unable to find that address");
		      } else {
		        place = response.Placemark[0];
		        point = new GLatLng(place.Point.coordinates[1],
		                            place.Point.coordinates[0]);
		        marker = new GMarker(point);
		        if(document.zoom){
		        	zoom = document.zoom;
		        }else{
		        	zoom = 15;}
		        if(map.setCenter){
		        map.setCenter(point, zoom);}
		        if(map.addOverlay){
		        map.addOverlay(marker);}
		        marker.openInfoWindowHtml(place.address);
		      }
		    }
		
		    // showLocation() is called when you click on the Search button
		    // in the form.  It geocodes the address entered into the form
		    // and adds a marker to the map at that location.
		    document.zoom = 15;
		    function showLocation(address, title, zoom) {
		    	document.zoom = zoom;
		      geocoder.getLocations(address, addAddressToMap);
		      document.getElementById('end_location').value = address;
		      document.getElementById('end_location_title').innerHTML = title;
		    }

		    function handleErrors(){
			   if (gdir.getStatus().code == G_GEO_UNKNOWN_ADDRESS)
			     alert("No corresponding geographic location could be found for one of the specified addresses. This may be due to the fact that the address is relatively new, or it may be incorrect.\nError code: " + gdir.getStatus().code);
			   else if (gdir.getStatus().code == G_GEO_SERVER_ERROR)
			     alert("A geocoding or directions request could not be successfully processed, yet the exact reason for the failure is not known.\n Error code: " + gdir.getStatus().code);
			   
			   else if (gdir.getStatus().code == G_GEO_MISSING_QUERY)
			     alert("The HTTP q parameter was either missing or had no value. For geocoder requests, this means that an empty address was specified as input. For directions requests, this means that no query was specified in the input.\n Error code: " + gdir.getStatus().code);
		
			//   else if (gdir.getStatus().code == G_UNAVAILABLE_ADDRESS)  <--- Doc bug... this is either not defined, or Doc is wrong
			//     alert("The geocode for the given address or the route for the given directions query cannot be returned due to legal or contractual reasons.\n Error code: " + gdir.getStatus().code);
			     
			   else if (gdir.getStatus().code == G_GEO_BAD_KEY)
			     alert("The given key is either invalid or does not match the domain for which it was given. \n Error code: " + gdir.getStatus().code);
		
			   else if (gdir.getStatus().code == G_GEO_BAD_REQUEST)
			     alert("A directions request could not be successfully parsed.\n Error code: " + gdir.getStatus().code);
			    
			   else alert("An unknown error occurred.");
			   
			}
		
			function onGDirectionsLoad(){ 
		      // Use this function to access information about the latest load()
		      // results.
		
		      // e.g.
		      //document.getElementById("directions").innerHTML = gdir.getStatus().code;
			  // and yada yada yada...
			}
			
			var active_menu = '';
			
			
			
			function showSubLayer(layer){
				active_menu = document.active_menu;
				la = document.getElementById(layer);
				ac = document.getElementById(active_menu);
				la_css = document.getElementById('h_'+layer);
				ac_css = document.getElementById('h_'+active_menu);

				if(ac){
					if(active_menu == layer){
						new Effect.SlideUp(active_menu);
						ac_css.className = 'res_cat_no_focus';
						document.active_menu = '';
					}else{
						new Effect.SlideUp(active_menu, {afterFinish:function(){
							document.active_menu = layer;
							new Effect.SlideDown(layer);
							la_css.className = 'res_cat_focus';
							ac_css.className = 'res_cat_no_focus';
						}});
					}
				}else{
					document.active_menu = layer;
					new Effect.SlideDown(layer, {afterFinish:function(){
						la_css.className = 'res_cat_focus';
					}});
				}
			}
			
			
	County_visibility = '0';
	function loadCounty(id, root){
	
		if (County_visibility == '0'){
			new Ajax.Updater('county_information', root+'scripts/php/ajax-county_pull.php', {evalScripts: true, postBody:'id='+id+'&root='+root, onCreate:function(){
				document.getElementById('county_information').innerHTML = '<div align="left" style="padding-left:100px;"><img src="'+root+'images/loading.gif"></div>';
				new Effect.Appear('county_area', { afterFinish:function(){
					 initialize();
					 goTo('county_information');
				}});
			}, onComplete:function(){
				County_visibility = '1';
			}});
			
		}else{
			new Ajax.Updater('county_information', root+'scripts/php/ajax-county_pull.php', {evalScripts: true, postBody:'id='+id+'&root='+root, onCreate:function(){
				document.getElementById('county_information').innerHTML = '<div align="left" style="padding-left:100px;"><img src="'+root+'images/loading.gif"></div>';
				goTo('county_information');
			}});
		}
		
	}
