 //<![CDATA[
var pointList = new Array();
var circleList = new Array();
var map;
var bounds;
var text = " ";

function initialize() {
   if (GBrowserIsCompatible() && pointList) {      
      map = new GMap2(document.getElementById("map_canvas"));
      bounds = new GLatLngBounds();

      new GKeyboardHandler(map);

      map.setUIToDefault();
      map.setMapType(G_PHYSICAL_MAP);
//      map.enableContinuousZoom();
//      map.enableDoubleClickZoom();

      // Set CenterPoint of US to start
      // map.setCenter(new GLatLng(39.6, -96.6), 10);

      // Iterate through the points
                
      for (var i=0; i<pointList.length; i++) {
         var point = new GLatLng(pointList[i][0], pointList[i][1]);
         if (pointList[i].length==5) {
            map.addOverlay(createMarker(point, i + 1, pointList[i][3], pointList[i][4]));
         } else {
            map.addOverlay(createMarker(point, i + 1, pointList[i][2]));
         }
//         sidebar(pointList[i][4], i);
         bounds.extend(point);
      }
      for (var i=0; i<circleList.length; i++) {
         var point = new GLatLng(circleList[i][0], circleList[i][1]);
         drawCircle(point, circleList[i][2], 360);
      }
                
      // Set the center and autozoom
      var zoomLevel = map.getBoundsZoomLevel(bounds);
//      if (zoomLevel > 11) zoomLevel = 11;
   
      var clat = (bounds.getNorthEast().lat() + bounds.getSouthWest().lat()) /2;
      var clng = (bounds.getNorthEast().lng() + bounds.getSouthWest().lng()) /2;
      map.setCenter(new GLatLng(clat,clng), zoomLevel);
   }
}

function createMarker(point, number, myhtml, mycolorvalue) {
   var file;
   switch (mycolorvalue) {
      case 'Black':
         file='marker_black.png';
         break;
      case 'Brown':
         file='marker_brown.png';
         break;
      case 'Green':
         file='marker_green.png';
         break;
      case 'Purple':
         file='marker_purple.png';
         break;
      case 'Yellow':
         file='marker_yellow.png';
         break;
      case 'Grey':
         file='marker_grey.png';
         break;
      case 'Orange':
         file='marker_orange.png';
         break;
      case 'White':
         file='marker_white.png';
         break;
      default:
         file='marker.png';
         break;
   }
   var url = 'http://www.google.com/mapfiles/'+file;
   var myIcon = new GIcon(G_DEFAULT_ICON);
   myIcon.image = url;
   var markerOptions = { icon:myIcon };
   var marker = new GMarker(point, markerOptions);
   marker.value = number;
   GEvent.addListener(marker, "click", function() {map.openInfoWindowHtml(point, myhtml);});
   return marker;
}

function drawCircle(center, radius, nodes, licolor, liWidth, liOpa, fillcolor, fillOpa) {
   //calculating km/degree
   var latConv = center.distanceFrom(new GLatLng(center.lat()+0.1, center.lng()))/100;
   var lngConv = center.distanceFrom(new GLatLng(center.lat(), center.lng()+0.1))/100;

   //Loop 
   var points = [];
   var step = parseInt(360/nodes)||10;
   for(var i=0; i<=360; i+=step) {
      var pint = new GLatLng(center.lat() + (radius/latConv * Math.cos(i * Math.PI/180)), center.lng() + (radius/lngConv * Math.sin(i * Math.PI/180)));
      points.push(pint);
      bounds.extend(pint); //this is for fit function
   }
   points.push(points[0]); // Closes the circle, thanks Martin
   fillcolor = fillcolor||licolor||"#0055ff";
   liWidth = liWidth||2;
   var poly = new GPolygon(points,licolor,liWidth,liOpa,fillcolor,fillOpa);
   map.addOverlay(poly);
}

function sideBar(line, j){
//text += "<br/><span class='sidebar'";
//text += "onclick='GEvent.trigger(marker["+j+"],\"click\")' ";
//text += "onmouseover='GEvent.trigger(marker["+j+"],\"mouseover\")' ";
//text += "onmouseout='GEvent.trigger(marker["+j+"],\"mouseout\")' ";
//text += ">";
//text += line;
//text += "</span>";
//document.getElementById("sidebar").innerHTML = text;
}



//]]>
