// JScript File
var map;
var myglobal;

function buildmap() 
	{
	if (GBrowserIsCompatible()) 
		{
		map = new GMap2(document.getElementById("map"));
		map.setCenter(new GLatLng(45.767, -115.004), 6);
		map.addControl(new GLargeMapControl());
		map.addControl(new GMapTypeControl());
		map.addMapType(G_PHYSICAL_MAP);
		       
        GEvent.addListener(map, "moveend", function() {
          var center = map.getCenter();
          document.getElementById("centercoords").innerHTML = "Map center coordinates: " + center.toString();
        });
        addpoints();
        }
    else
		{
		alert("This page is not compatible with your browser.")
		};
    }
    
function addpoints()
    {
        GDownloadUrl("Mapap/Offices/Officesdata.xml", function(data, responseCode) {
        var xml = GXml.parse(data);
        var markers = xml.documentElement.getElementsByTagName("marker");
        for (var i = 0; i < markers.length; i++) {
            //get the latitude and longitude of each point from the xml file
            var point = new GLatLng(parseFloat(markers[i].getAttribute("lat")),parseFloat(markers[i].getAttribute("lng")));
            //get ancillary information to post
            var my_office_info = markers[i].getAttribute("officename") + "<br />" + markers[i].getAttribute("straddr")+ "<br />" + markers[i].getAttribute("cityaddr");
            var my_contact_info = markers[i].getAttribute("phone");
            var my_website_info = "<br /> <a href=http://www.idl.idaho.gov" + markers[i].getAttribute("website") + ">Website</a>";

            map.addOverlay(createMarker(point, my_office_info, my_contact_info, my_website_info));
        }
        });
    }

// Creates a marker at the given point with the given number label
function createMarker(point, my_value, my_contact , my_website) {
  var marker = new GMarker(point);
  
//setup the info window content
  var infoTabs = [
  new GInfoWindowTab("Location", "Office: " + my_value),
  new GInfoWindowTab("Contacts", my_contact + my_website)
  ];

//for a click event: open a tabbed Info window
  GEvent.addListener(marker, "click", function() {
    marker.openInfoWindowTabsHtml(infoTabs);
  });
  
  GEvent.addListener(marker, "dblclick", function() {
    map.setZoom(15);
    map.panTo(point);
  });
  
  return marker;
}


