    //<![CDATA[


var baseIcon = new GIcon();
baseIcon.shadow = "http://www.google.com/mapfiles/shadow50.png";
baseIcon.iconSize = new GSize(20, 34);
baseIcon.shadowSize = new GSize(37, 34);
baseIcon.iconAnchor = new GPoint(9, 34);
baseIcon.infoWindowAnchor = new GPoint(9, 2);
baseIcon.infoShadowAnchor = new GPoint(18, 25);

// global variables
      var map;
      var request;
      var gmarkers;
      var gmark;
	  var candidate = new Array();

function makeMap(labeler,mapscale) {
    if (GBrowserIsCompatible()) {
      // resize the map

      var m = document.getElementById("map");
      // create the map
        map = new GMap2(document.getElementById("map"));
        map.addControl(new GSmallMapControl());
        map.addControl(new GMapTypeControl());
        map.setCenter(new GLatLng(39, -105), 8);
      Displaylines(labeler,mapscale)
	} else {
      alert("your browser does not support Google Maps!");
    }	
}

function Displaylines(distid,scaleno){
 	ConvXML = function(doc){
    // === GXML to translate into XML parsed data ===
	var datapass = GXml.parse(doc);
	XMLParsing(datapass,scaleno);
	}

	// Form the correct file names for each XMLfile
	var distxml = "/downloads/comaps/dist" + distid +".xml";
		
	GDownloadUrl(distxml, ConvXML);  
}

function XMLParsing(xmlDoc,themapscale)
{
	var markers = xmlDoc.documentElement.getElementsByTagName("marker");
	var i = 0;
	var gmarkers = markers[i].getAttribute("tag");
    // Create point relevant data
	var lat = parseFloat(markers[i].getAttribute("lat"));
	var lng = parseFloat(markers[i].getAttribute("lng"));
	var point = new GLatLng(lat,lng);

	// Center/scale the map
	var scale = themapscale;
	var scale2 = 17-parseFloat(markers[i].getAttribute("scale"));

	// Needed since I used the old Gmap scaling mechanism to originally make these
		// map.setCenter(point, scale2);
		map.setCenter(point,themapscale);

	// Used for polylines later
	
	var color = markers[i].getAttribute("color");

	//Process representatives part - for marker pop-up window
	var reps = xmlDoc.documentElement.getElementsByTagName("rep");
	if (reps.length == 0)
	{ repname = 'Name unavailable'; nameshtml = 'Name unavailable';}
	else
	{
	var repname = reps[0].getAttribute("name");
	var repparty = reps[0].getAttribute("party");
		if (repparty == "D")
		{
		color = "#0000F0";
		}
		else
		{ color = "#F00000"; }
	}
	
	// Create Marker and Overlay the Marker on the Map
		//var marker = createMarker(point,gmarkers,repname);
		//map.addOverlay(marker);

        // ========= Now process the polylines ===========
	// Any line will process - there is no tag checking, since I determined it was pretty redundant
	// All tags are the two letter/two number code

    var lines = xmlDoc.documentElement.getElementsByTagName("line");
        
	// Setup the variables required  
	var pol = 0
	var pts = [];
	onlyone = 0;

    if (lines && lines.length && (lines.length > 0)) 
	{
		for (var a = 0; a < lines.length; a++) 
		{
			// Set the line width and alpha tranparency attributes
			var width  = 2;
			var alpha  = 0.1;
            // Points load to 300, then are overlayed on the map and the pts matrix resets
			// FYI doing a 1000+ point line overlay usually stalls Firefox/Google
            var points = lines[a].getElementsByTagName("pt");
            var pol = 0
			var pts = [];
			
			var agt=navigator.userAgent; 
			var safari_detect = "AppleWebKit";
			
			if(agt.indexOf(safari_detect) == -1)
			{			
            for (var i = 0; i < points.length; i++) 
			  {
//				if (pol > 300) 
//				{
//				map.addOverlay(new GPolyline(pts,color,width,alpha));
//				var lastpt = pts[300];
//				pts = [];
//				pts[0] = lastpt;
//			pol=1;
//				}
				pts[i] = new GLatLng(parseFloat(points[i].getAttribute("lat")), parseFloat(points[i].getAttribute("lng")));
              }
              map.addOverlay(new GPolygon(pts,color,width,1,color,alpha));
			}
			else
			{
			 for (var i = 0; i < points.length; i++) 
			 {
				if (pol > 300) 
				{
				map.addOverlay(new GPolyline(pts,color,width,.7));
				var lastpt = pts[300];
				pts = [];
				pts[0] = lastpt;
				pol=1;
				}
				pts[pol] = new GLatLng(parseFloat(points[i].getAttribute("lat")), parseFloat(points[i].getAttribute("lng")));
				pol++;
              }
			map.addOverlay(new GPolyline(pts,color,width,.7));
            }
        }
    }
}


function createMarker(point,gmarkers,repname) 
{
  // Create a lettered icon for this point using our icon class from above
  var gmark = gmarkers;
  var icon = new GIcon(baseIcon);
  
  //icon.image = "http://facethestate.com/downloads/comaps/" + gmarkers + ".png";
  icon.image = "http://facethestate.com/downloads/comaps/pink.png";
  var marker = new GMarker(point, icon);

  // Show this marker's index in the info window when it is clicked.

  var html = 'District ' +  gmarkers.substring(2,4) + ' <BR> ' + repname;
  
  GEvent.addListener(marker, 'click', function() {
	marker.openInfoWindowHtml(html);
  });
  return marker;
}

// ======================================================================

function switchit(list)
{
	var listElementStyle=document.getElementById(list).style;
	if (listElementStyle.display=="none")
	{
		listElementStyle.display="block";
	}
	else 
	{
		listElementStyle.display="none";
	}
}

function clearAll() {
	map.clearOverlays();
}

    //]]>
