if (GBrowserIsCompatible()) {
	
	var map = null;
	window.onload=function(){window.onload;initialize()}; 
	window.onunload=function(){window.onunload;GUnload()}; 
	
	function initialize() {
	
		//set up map
		map = new GMap2(document.getElementById("map")); //creates map
		map.addControl(new GSmallMapControl()); //adds pan and zoom control
		map.addControl(new GScaleControl()); //adds scale
		map.setCenter(new GLatLng(40.027035,-75.165157), 10, G_PHYSICAL_MAP); //sets center and map type
	
		var city_poly = new GGeoXml("http://www.phillywatersheds.org/kml/City_Line.kml"); //city limits
		//watershed layers
		var dc = new GGeoXml("http://www.phillywatersheds.org/kml/Darby_Cobbs_Creek_Watershed.kml");
		var de = new GGeoXml("http://www.phillywatersheds.org/kml/Delaware_River_Direct_Watershed.kml");
		var pp = new GGeoXml("http://www.phillywatersheds.org/kml/Pennypack_Creek_Watershed.kml");
		var pq = new GGeoXml("http://www.phillywatersheds.org/kml/Poquessing_Creek_Watershed.kml");
		var sh = new GGeoXml("http://www.phillywatersheds.org/kml/Schuylkill_River_Watershed.kml");
		var tf = new GGeoXml("http://www.phillywatersheds.org/kml/Tookany_Tacony_Frankford_Creek_Watershed.kml");
		var wi = new GGeoXml("http://www.phillywatersheds.org/kml/Wissahickon_Creek_Watershed.kml");
		map.addOverlay(city_poly); //adds city limits layer
		map.addOverlay(dc);
		map.addOverlay(de);
		map.addOverlay(pp);
		map.addOverlay(pq);
		map.addOverlay(sh);
		map.addOverlay(tf);
		map.addOverlay(wi);

		G_PHYSICAL_MAP.getMinimumResolution = function () { return 10 }; //sets min zoom level
		G_PHYSICAL_MAP.getMaximumResolution = function () { return 15 }; //sets max zoom level
		
				
		// Add a move listener to restrict the bounds range
		GEvent.addListener(map, "move", function() {
			checkBounds();
		});
	}
	
		//set icon characteristics for search result icon
		var geocodeIcon = new GIcon();
		geocodeIcon.image = 'http://www.phillywatersheds.org/img/marker/geocodemarker.png';
		geocodeIcon.shadow = "http://www.phillywatersheds.org/img/marker/shadow-geocodemarker.png";
		geocodeIcon.iconSize=new GSize(32,32);
		geocodeIcon.shadowSize=new GSize(16,16);
		geocodeIcon.iconAnchor=new GPoint(16,16);
		geocodeIcon.infoWindowAnchor=new GPoint(16,8);
	
		//bounding box for searches and panning
		var allowedBounds = new GLatLngBounds(new GLatLng(39.8480851,-75.395736), new GLatLng(40.15211,-74.863586));	

	
		//geocoding
		var geocoder = new GClientGeocoder();
		var resultArray = new Array();
		//if another marker exists in the array, remove it from the map
		function AddressSearch(address) {
		
		address = address + ", Philadelphia, PA";
		
		if(resultArray[0]){
		map.removeOverlay(resultArray[0]);
		}
		geocoder.getLatLng(
    		address,
    		function(point) {
      		if (!point) {
        		alert("Address not found. Please check the format of your address.");
      		} else {
        			var marker = createMarker(point,address);
				if(allowedBounds.contains(marker.getPoint())){
					var marker = createMarker(point,address);
					map.setCenter(point, 13);
        			map.addOverlay(marker);
					GEvent.trigger(marker,"click");
					resultArray[0] = marker;
				}else{
					alert("Please restrict your search to the Philadelphia area.");
				}
      		}
			}
		);
		}
		
			
		//creates marker for geocode search result
		function createMarker(point,html) {
			var marker = new GMarker(point, geocodeIcon);
			GEvent.addListener(marker, "click", function() {
			marker.openInfoWindowHtml(html);
			});
			return marker;
		}
		
		
	}else {
      alert("Sorry, Google Maps is not compatible with this browser");
    }
	