﻿function loadmap() 
{
var undefined = "undefined"; 
    if(typeof(homeSpatialInfo) != undefined && typeof(ProximityLocations) != undefined)
    {
      if (GBrowserIsCompatible()) 
      {
        var map = new GMap2(document.getElementById("map"));
        map.setCenter(new GLatLng(homeSpatialInfo.latitude, homeSpatialInfo.longitude), 8);
        map.addControl(new GSmallMapControl());
        map.addControl(new GMapTypeControl());

        // Create a base icon for all of our markers that specifies the
        // shadow, icon dimensions, etc.
        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);
        
        // Creates a marker whose info window displays the letter corresponding// to the given index.
        function createMarker(point, name, address, phone, fax, email, website, monhours, tueshours, wedhours, thurshours, frihours, sathours, sunhours, urladdress, locationNumber) 
        {
          var icon = new GIcon(baseIcon);  
          icon.image = "images/google/marker" + locationNumber + ".png";
          var marker = new GMarker(point, icon);
          var infoTabs = [
          new GInfoWindowTab("Address", name + '<br>' + address + '<br>' + '<a target="_blank" href="http://maps.google.com/maps?q='+ProximityLocations.locations[locationNumber-1].latitude+','+ProximityLocations.locations[locationNumber-1].longitude+'('+urladdress+')">Get Directional Info</a>'),
          new GInfoWindowTab("Contact Info", "Phone: " + phone + '<br>' + "Fax: " + fax + '<br>' + "Email: " + '<a href="mailto:' + email + '">' + email + '</a>' + '<br>' + "Website: " + '<a target="_blank" href="'+website+'">'+website+'</a>'),
          new GInfoWindowTab("Store Hours", '<table><tr><td>' + "Monday:" + '</td><td>' + monhours + '</td></tr><tr><td>' + 
                                                                  "Tuesday:" + '</td><td>' + tueshours + '</td></tr><tr><td>' + 
                                                                  "Wednesday:" + '</td><td>' + wedhours + '</td></tr><tr><td>' + 
                                                                  "Thursday:" + '</td><td>' + thurshours + '</td></tr><tr><td>' + 
                                                                  "Friday:" + '</td><td>' + frihours + '</td></tr><tr><td>' + 
                                                                  "Saturday:" + '</td><td>' + sathours + '</td></tr><tr><td>' + 
                                                                  "Sunday:" + '</td><td>' + sunhours + '</td></tr></table>')
           ];
          GEvent.addListener(marker, "click", function() {
          marker.openInfoWindowTabsHtml(infoTabs);
          });
          return marker;
        }

        // Load all the markers from the JSON ProximityLocations variable
        var bounds = map.getBounds();
        var southWest = bounds.getSouthWest();
        var northEast = bounds.getNorthEast();
        var lngSpan = northEast.lng() - southWest.lng();
        var latSpan = northEast.lat() - southWest.lat();
        for (var i = 0; i < ProximityLocations.locations.length; i++) 
        {
          var point = new GLatLng(ProximityLocations.locations[i].latitude,ProximityLocations.locations[i].longitude);
          map.addOverlay(createMarker(point, ProximityLocations.locations[i].name, ProximityLocations.locations[i].address, ProximityLocations.locations[i].phone, ProximityLocations.locations[i].fax, ProximityLocations.locations[i].email, ProximityLocations.locations[i].website, ProximityLocations.locations[i].monhours, ProximityLocations.locations[i].tueshours, ProximityLocations.locations[i].wedhours, ProximityLocations.locations[i].thurshours, ProximityLocations.locations[i].frihours, ProximityLocations.locations[i].sathours, ProximityLocations.locations[i].sunhours, ProximityLocations.locations[i].urladdress, i+1));
        }
     }
   }
}



