﻿// Point type for an event point
function point(lat, lon, title, href, time, location, marker) {
    this.lat = lat;
    this.lon = lon;
    this.title = title;
    this.href = href;
    this.time = time;
    this.location = location;
    this.marker = marker;
    this.tag = null;
    this.activate =
       function() {
           if (this.tag != null) {
               this.tag.openInfoWindowHtml("<a href='" + this.href + "'><b>" + this.title + "</b></a><br/>" + this.time + "<br/>" + this.location);
           }
       }
}

// Define an array of event points
var points = getPoints();
function loadMap() {
    // Make the PNG files transparent for IE6
    if (/MSIE (\d+\.\d+);/.test(navigator.userAgent)){ //test for MSIE x.x;
     var ieversion=new Number(RegExp.$1) // capture x.x portion and store as a number
     if (ieversion<=6) {
      supersleight.run();
     }
    }

  if (GBrowserIsCompatible()) {
    // Create the map
    var map = new GMap2(document.getElementById("map"));
    map.setCenter(new GLatLng(45.566347,-94.138584), 12);
    map.addControl(new GLargeMapControl());
    map.addControl(new GMapTypeControl());
    map.enableDoubleClickZoom();
    
    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);
    
    function setMarker(point) {
        var apoint = new GLatLng(point.lat, point.lon);
        var aIcon = new GIcon(baseIcon);
        aIcon.image = "http://www.google.com/mapfiles/marker" + point.marker + ".png";
        var marker = new GMarker(apoint, aIcon);
        point.tag = marker;
        GEvent.addListener(marker, "click", function() {point.activate()});
        map.addOverlay(marker);
    }
    
    var x;
    var activate = getActivate();
    for (x = 0; x < points.length; x++) {
        setMarker(points[x]);
        if (activate == points[x].href) {
            points[x].activate();
        }
    }
    
  }
}