 
// Create a base icon for all of our markers that specifies the shadow, icon
// dimensions, etc.
var baseColorIcon = new GIcon(G_DEFAULT_ICON);
baseColorIcon.shadow = "/images/markers/lettermarkers/large_shadow.png";
baseColorIcon.iconSize = new GSize(20, 34);
baseColorIcon.shadowSize = new GSize(37, 34);
baseColorIcon.iconAnchor = new GPoint(9, 34);
baseColorIcon.infoWindowAnchor = new GPoint(9, 2);
baseColorIcon.infoShadowAnchor = new GPoint(18, 25);

var smallIcon = new GIcon(G_DEFAULT_ICON);
smallIcon.shadow = "/images/markers/lettermarkers/small_shadow.png"
smallIcon.iconSize = new GSize(12, 20);
smallIcon.shadowSize = new GSize(22, 20);
smallIcon.iconAnchor = new GPoint(6, 20);
smallIcon.infoWindowAnchor = new GPoint(5, 1);

// TODO: we shouldn't be creating 3 icons in this include ... it should be 1 per map type
var numIcon = new GIcon(G_DEFAULT_ICON);
numIcon.shadow = "/images/markers/nummarkers/shadow.png"
numIcon.iconSize = new GSize(20, 34);
numIcon.shadowSize = new GSize(37, 34);
numIcon.iconAnchor = new GPoint(9, 34);
numIcon.infoWindowAnchor = new GPoint(5, 1);


// for popup info windows on sidebars ... 
var markers = new Array();


function drawCircle2(lat,lng,radius,width)
{
   var Ccolor = '#0000ff';    // color blue
   var d2r = Math.PI/180;   // degrees to radians
   var r2d = 180/Math.PI;   // radians to degrees
   var Clat = (radius/3963)*r2d;   //  using 3963 as earth's radius

   var Clng = Clat/Math.cos(lat*d2r);
   var Cpoints = [];

   for (var i=0; i < 33; i++) {
      var theta = Math.PI * (i/16);
      Cx = lng + (Clng * Math.cos(theta));
      Cy = lat + (Clat * Math.sin(theta));
      Cpoints.push(new GPoint(Cx,Cy));
   };
   map.addOverlay(new GPolyline(Cpoints,Ccolor,width)); 
}


function drawCircle(lat,lon,radius,color,width)
{
   var d2r = Math.PI/180;   // degrees to radians
   var r2d = 180/Math.PI;   // radians to degrees
   var Clat = (radius/3963)*r2d;   //  using 3963 as earth's radius 
   var Clng = Clat/Math.cos(lat);
   var Cpoints = [];
   for (var i=0; i < 33; i++) {
      var theta = Math.PI * (i/16);
      Cx = lon + (Clng * Math.cos(theta));
      Cy = lat + (Clat * Math.sin(theta));
      Cpoints.push(new GPoint(Cx,Cy));
   };
   map.addOverlay(new GPolyline(Cpoints,color,width));
}
 

// Creates a marker whose info window displays the letter corresponding to
// the given index
function createColorLetterMarker(lat, lon, html, index, rating)
{
  // Create a lettered icon for this point using our icon class from above
  var letter = String.fromCharCode("A".charCodeAt(0) + index);
  var icon = new GIcon(baseColorIcon);
  var color="grey";
  if (rating > 0)
  {
	color="green";
  }
  else if (rating < 0)
  {
	color="red";
  }
  icon.image = "/images/markers/lettermarkers/marker" + letter + "_" + color + ".png";
  var point = new GLatLng(lat*57.29578, lon*57.29578, true);
  var marker = new GMarker(point, icon);
	map.addOverlay(marker);
  // Show this marker's index in the info window when it is clicked
	  GEvent.addListener(marker, "click", function() {
   	     marker.openInfoWindowHtml(html);
      });

	markers.push(marker);

  return point;
}



function createColorNumberMarkerNew(lat, lon, html, index, rating)
{
  // Create a lettered icon for this point using our icon class from above
  var icon = new GIcon(numIcon);
  var color="grey";
  if (rating > 0)
  {
	color="green";
  }
  else if (rating < 0)
  {
	color="red";
  }
  icon.image = "/images/markers/nummarkers/marker" + index + "_" + color + ".png";
  var point = new GLatLng(lat*57.29578,lon*57.29578, true);
  var marker = new GMarker(point, icon);
  // Show this marker's index in the info window when it is clicked
	if (html.length > 0)
	{
	  GEvent.addListener(marker, "mouseover", function() {
   	     marker.openInfoWindowHtml(html);
      });
	}

	markers.push(marker);
	
  return marker;
}


function createColorNumberMarker(lat, lon, html, index, rating)
{
  // Create a lettered icon for this point using our icon class from above
  var icon = new GIcon(numIcon);
  var color="grey";
  if (rating > 0)
  {
	color="green";
  }
  else if (rating < 0)
  {
	color="red";
  }
  icon.image = "/images/markers/nummarkers/marker" + index + "_" + color + ".png";
  var point = new GLatLng(lat*57.29578,lon*57.29578, true);
  var marker = new GMarker(point, icon);
	map.addOverlay(marker);
  // Show this marker's index in the info window when it is clicked
	if (html.length > 0)
	{
	  GEvent.addListener(marker, "mouseover", function() {
   	     marker.openInfoWindowHtml(html);
      });
	  GEvent.addListener(marker, "mouseover", function() {
   	     GMap2.closeInfoWindow();
      });
	}

	markers.push(marker);
	
  return point;
}


function createSmallColorMarker(lat, lon, rating, html)
{
  var icon = new GIcon(smallIcon);
  var color="grey";
  if (rating > 0)
  {
	color="green";
  }
  else if (rating < 0)
  {
	color="red";
  }
  icon.image = "/images/markers/lettermarkers/small_" + color + ".png";
  var point = new GLatLng(lat*57.29578,lon*57.29578, true);
  var marker = new GMarker(point, icon);
	map.addOverlay(marker);
	  GEvent.addListener(marker, "click", function() {
   	     marker.openInfoWindowHtml(html);
      });

  return point;
}


function resizeMap( map, points, maxZoom ) {
        // Create new bounds object
        var bounds = new GLatLngBounds();

        // Loop through the points, extending the bounds as necessary
        for (var i=0; i< points.length; i++) {
                bounds.extend(points[i].getPoint());
        }

        // Find the centre of the new bounds
        var lat = bounds.getSouthWest().lat() + ((bounds.getNorthEast().lat()
- bounds.getSouthWest().lat()) / 2);
        var lon = bounds.getSouthWest().lng() + ((bounds.getNorthEast().lng()
- bounds.getSouthWest().lng()) / 2);

        // Get the bounds zoom level
        var zoom = map.getBoundsZoomLevel(bounds);
		if (zoom > maxZoom)
		{
			zoom = maxZoom;
		}

        // Change the map to the new bounds values
        map.setCenter(new GLatLng(lat, lon), zoom);
}
  
 var map;

 
