// JavaScript Document


var map;

function loadMap()
{
	if (GBrowserIsCompatible()) {   
      
      // Display the map, with some controls and set the initial location 
      map = new GMap2(document.getElementById("map"));
      map.addControl(new GLargeMapControl());
      map.addControl(new GMapTypeControl());
     // map.setCenter(new GLatLng(43.907787,-79.359741),8);
      map.setCenter(new GLatLng(42.601619944327965, -87.51708984375), 6);
      loadData();
	 
    }
    
    // display a warning if the browser was not compatible
    else {
      alert("Sorry, the Google Maps API is not compatible with this browser");
    }	
}

//Creates a marker with click event
function createMarker(point,html) {
	var marker = new GMarker(point,{icon:GetIcon()});
	GEvent.addListener(marker, "click", function() {
	  marker.openInfoWindowHtml(html);
	});
	return marker;
}

//Loads data from xml source
function loadData()
{
	if(myArray != null){
		for (var i=0; i<myArray.length; i++)
		{
			var lon = myArray[i][0];//Longitude
			var lat = myArray[i][1];//Latitude
			var point = new GLatLng(lat,lon);
			var marker = createMarker(point,'<div class="google_pop"><h2>'+myArray[i][2]+'</h2>'+myArray[i][3]+'<br /><a href="location_detail.aspx?loc='+myArray[i][2]+'">Go to Location page</a></div>')
			map.addOverlay(marker);
		}
	}
}

function GetIcon()
{
	var baseIcon = new GIcon();
	//baseIcon.shadow = "../images/googlepin_shadow.png";
	baseIcon.image = "../images/google_green.png";
	baseIcon.iconSize = new GSize(16, 28);
	baseIcon.shadowSize = new GSize(22, 15);
	baseIcon.iconAnchor = new GPoint(6, 15);
	baseIcon.infoWindowAnchor = new GPoint(5, 1);
	baseIcon.infoShadowAnchor = new GPoint(5, 1);
	baseIcon.transparent = "../images/googlepin_shadow.png";
	baseIcon.transparent = "../images/google_green.png";	
	
	return baseIcon;
}