// JavaScript Document

		var city;
	  	var map;
	  	var geocoder;
	  	var geoXml; 
	  	var toggleState = 1;
		var polygon;

	
// MAP SETTINGS
		/*Initial*/
				function initialize() {
				if (GBrowserIsCompatible()) {
		/*Map Appearance*/
				geoXml = new GGeoXml("http://thinkglobalohio.org/kml/ohio_outline.kml");
				map = new GMap2(document.getElementById("map_canvas")); 
				map.setCenter(new GLatLng(20.137741,-30.345374), 2);
				map.setMapType(G_PHYSICAL_MAP);
				map.addControl(new GSmallMapControl());
				//map.addOverlay(geoXml);				
				//polygon = new GPolygon("http://thinkglobalohio.org/kml/ohio_outline.kml");
		/*City Drop-down*/
				geocoder = new GClientGeocoder();
				geocoder.setCache(new CapitalCitiesCache());
		/*Toggle bits*/
				geoXml1 = new GGeoXml("http://thinkglobalohio.org/kml/x/companies.kml");
				geoXml2 = new GGeoXml("http://thinkglobalohio.org/kml/x/dod.kml");
				geoXml3 = new GGeoXml("http://thinkglobalohio.org/kml/x/sister.kml");
				geoXml4 = new GGeoXml("http://thinkglobalohio.org/kml/x/k12schools1.kml");
				geoXml5 = new GGeoXml("http://thinkglobalohio.org/kml/x/universities1.kml");
				geoXml6 = new GGeoXml("http://thinkglobalohio.org/kml/zoos.kml");
		  }
		}
// "SELECT A CITY" DROP-DOWN	 
		/*GeoCode cities fuction*/
				function CapitalCitiesCache() {
				GGeocodeCache.apply(this);
			  }
		/*Geocode cache function*/
				CapitalCitiesCache.prototype = new GGeocodeCache();
				CapitalCitiesCache.prototype.reset = function() {
				GGeocodeCache.prototype.reset.call(this);
				for (var i in city) {
				this.put(city[i].name, city[i]);
			  }
			}	
		/*Map settings (after search)*/
				function addAddressToMap(response) {
//				map.clearOverlays();
		
				if (response && response.Status.code != 200) {
				alert("Unable to locate " + decodeURIComponent(response.name));
				} else {
				var place = response.Placemark[0];
				var point = new GLatLng(place.Point.coordinates[1],
									  	place.Point.coordinates[0]);
										map.setCenter(point, 4);
				map.openInfoWindowHtml(point, place.name
				+ "<br><b></b> " + place.info);
			  }
			}
			
/*			map.setCenter(new GLatLng(place.Point.coordinates[1],
									  place.Point.coordinates[0]), 1);
*/			
			
		/*Cache fuction*/
				function findCity(which) {
				if (which != 0) {
				geocoder.getLocations(city[which - 1].name, addAddressToMap);
			  }
			} 
/*		//Aaron's suggestion	
				function overlay(checked) {
				if (clicked) {map.removeOverlay();
				else {map.addOverlay();
				}
*/
					
	
/*	function toggleGeoXML() {
  if (checked) {
    var geoXml = new GGeoXml(layers[id].url);
    layers[id].geoXml = geoXml;

    if (layers[id].lat && layers[id].lng) {
      map.setCenter(new GLatLng(layers[id].lat, layers[id].lng));
    } else {
      map.setCenter(new GLatLng(40.25,-82.665));
    }
    map.addOverlay(geoXml);
  } else if (layers[id].geoXml) {
    map.removeOverlay(layers[id].geoXml);
  }
}*/
	
//SIDEBAR TOGGLES
		// Museums
				function toggleMyKml1() {
				if (toggleState == 1) {
				map.addOverlay(geoXml);
				toggleState = 0;        
				} else {
				map.removeOverlay(geoXml1);
				toggleState = 1;
			  }
			}		
		// Organizations
				function toggleMyKml2() {
				if (toggleState == 1) {
				map.addOverlay(geoXml2);
				toggleState = 0;        
				} else {
				map.removeOverlay();
				toggleState = 1;
			  }
			}	
		// Consulates
				function toggleMyKml3() {
				if (toggleState == 1) {
				map.addOverlay(geoXml3);
				toggleState = 0;        
				} else {
				map.removeOverlay(geoXml3);
				toggleState = 1;
			  }
			}	
		// K12Schools
				function toggleMyKml4() {
				if (toggleState == 1) {
				map.addOverlay(geoXml4);
				toggleState = 0;        
				} else {
				map.removeOverlay(geoXml4);
				toggleState = 1;
			  }
			}		
		// Universities
				function toggleMyKml5() {
				if (toggleState == 1) {
				map.addOverlay(geoXml5);
				toggleState = 0;        
				} else {
				map.removeOverlay(geoXml5);
				toggleState = 1;
			  }
			}	
		// Zoos
				function toggleMyKml6() {
				if (toggleState == 1) {
				map.addOverlay(geoXml6);
				toggleState = 0;        
				} else {
				map.removeOverlay(geoXml6);
				toggleState = 1;
			  }
			} 