// JavaScript Document
<!-- Map javascript -->
	String.prototype.trim = function () {
		return this.replace(/^\s*/, "").replace(/\s*$/, "");
	} //end of trim
	
	function addDistrictBound() {
		GDownloadUrl("data/DCBndyPly_Gen.kml", function(data) {
			var xml = GXml.parse(data);
			var placemarks = xml.documentElement.getElementsByTagName("Placemark");
	
			var count = 0;
			for(var i=0; i<placemarks.length; i++){
	
				var name = placemarks[i].getElementsByTagName("name")[0].childNodes[0].nodeValue;
	
				var coordinates;
				coordinates = placemarks[i].getElementsByTagName("coordinates")[0].childNodes[0].nodeValue;
	
				coordinates = coordinates.trim();
	
				for(var chunk=1;  chunk<placemarks[i].getElementsByTagName("coordinates")[0].childNodes.length;chunk++){
					 coordinates+=placemarks[i].getElementsByTagName("coordinates")[0].childNodes[chunk].nodeValue;
				}
	
				coordinates = coordinates.split(" ");
	
				for(var j=0; j<coordinates.length;j++){
						coordinates[j] = coordinates[j].split(",");
				}
				
				if(coordinates.length > 1){
					var points = new Array();
					for(var j=0; j<coordinates.length; j++)
					{
						if(coordinates[j].length == 3)
						{	
							points.push(new  GLatLng(parseFloat(coordinates[j][1]),parseFloat(coordinates[j][0])));	
						}
						else if(coordinates[j].length == 4)
						{	
							points.push(new  GLatLng(parseFloat(coordinates[j][2]),parseFloat(coordinates[j][1])));	
						}
					}
					dcbndyply = new GPolygon(points,"#FF0000",2 ,0.8)
					map.addOverlay(dcbndyply);				
				}
				else
				{
					continue;
				}								
			}		
			});  
	} //end of addDistrictBound
	
	if (GBrowserIsCompatible()) { 
	  // A function to create the marker and set up the event window
	  // Dont try to unroll this function. It has to be here for the function closure
	  // Each instance of the function preserves the contends of a different instance
	  // of the "marker" and "html" variables which will be needed later when the event triggers.    
	  function createMarker(point,html) {
		var marker = new GMarker(point);
		GEvent.addListener(marker, "click", function() {
		  marker.openInfoWindowHtml(html);
		});
		return marker;
	  }
	  
	  function createIconMarker(point,html,icon) {
        var marker = new GMarker(point,icon);
        GEvent.addListener(marker, "click", function() {
          marker.openInfoWindowHtml(html);
        });
        return marker;
      }
	  
	  //used to place a single map point on the map with a home location
	  function addHomeOnly(latPoint,lngPoint) {
	  	//define home icon information
		var baseIcon = new GIcon();
		baseIcon.iconSize=new GSize(32,32);
		baseIcon.shadowSize=new GSize(56,32);
		baseIcon.iconAnchor=new GPoint(16,32);
		baseIcon.infoWindowAnchor=new GPoint(16,0);
		
		var house   = new GIcon(baseIcon, "http://maps.google.com/mapfiles/kml/pal3/icon56.png", null, "http://maps.google.com/mapfiles/kml/pal3/icon56s.png");
		
		//clear all overlays
		map.clearOverlays();
		//re add district bound
		addDistrictBound();
		//add home point to the map
		point = new GLatLng(latPoint,lngPoint);
		var marker = createIconMarker(point,'<div style="width:150px;color:#000000;text-align:left;">Central Search Point<\/div>',house)
		map.addOverlay(marker);
		//recenter the map on the given point
		map.setCenter(new GLatLng(latPoint, lngPoint), 11);
		//jump the page to the top
		scroll(0,0);
	  } //end of function addHomePoint
	  
	  //used to place a single map point on the map with a home location
	  function addHomePoint(latPoint,lngPoint,hLatPoint,hLngPoint,strInfo) {
	  	//define home icon information
		var baseIcon = new GIcon();
		baseIcon.iconSize=new GSize(32,32);
		baseIcon.shadowSize=new GSize(56,32);
		baseIcon.iconAnchor=new GPoint(16,32);
		baseIcon.infoWindowAnchor=new GPoint(16,0);
		
		var house   = new GIcon(baseIcon, "http://maps.google.com/mapfiles/kml/pal3/icon56.png", null, "http://maps.google.com/mapfiles/kml/pal3/icon56s.png");
		
		//clear all overlays
		map.clearOverlays();
		//re add district bound
		addDistrictBound();
		//add point to the map
		var point = new GLatLng(latPoint,lngPoint);
		var marker = createMarker(point,'<div style="width:200px;color:#000000;text-align:left;">' + strInfo + '<\/div>')
		map.addOverlay(marker);
		//add home point to the map
		point = new GLatLng(hLatPoint,hLngPoint);
		var marker = createIconMarker(point,'<div style="width:150px;color:#000000;text-align:left;">Central Search Point<\/div>',house)
		map.addOverlay(marker);
		//recenter the map on the given point
		map.setCenter(new GLatLng(hLatPoint, hLngPoint), 11);
		//jump the page to the top
		scroll(0,0);
	  } //end of function addHomePoint
	  
	  //used to place a single map point on the map
	  function addOnePoint(latPoint,lngPoint,strInfo) {
	  	//clear all overlays
		map.clearOverlays();
		//re add district bound
		addDistrictBound();
		var point = new GLatLng(latPoint,lngPoint);
		var marker = createMarker(point,'<div style="width:200px;color:#000000;text-align:left;">' + strInfo + '<\/div>')
		map.addOverlay(marker);
		//recenter the map on the given point
		map.setCenter(new GLatLng(latPoint, lngPoint), 11);
		//jump the page to the top
		scroll(0,0);
	  } //end of function addOnePoint
	  
	  //used to place a many map points on the map
	  function addPoints(latPoint,lngPoint,strInfo) {
		var point = new GLatLng(latPoint,lngPoint);
		var marker = createMarker(point,'<div style="width:200px;color:#000000;text-align:left;">' + strInfo + '<\/div>')
		map.addOverlay(marker);
	  } //end of function addOnePoint

	  // Display the map, with some controls and set the initial location 
	  var map = new GMap2(document.getElementById("map"));
	  map.addControl(new GLargeMapControl());
	  map.addControl(new GMapTypeControl());
	  //map.addControl(new GScaleControl());
	  map.setCenter(new GLatLng(38.897000, -77.02000), 11);
	  
	  //add district bound
	  addDistrictBound();
	} // end of if
	
	// display a warning if the browser was not compatible
	else {
	  alert("Sorry, the Google Maps API is not compatible with this browser");
	} //end of else