﻿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), zoomlevel);
        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, num, name, address, phone, fax, email, website, monhours, tueshours, wedhours, thurshours, frihours, sathours, sunhours, pic, urladdress, locationNumber) 
        {
   
          var icon = new GIcon(baseIcon);  
          icon.image = "../media/markers/marker"+locationNumber+".png";
          var marker = new GMarker(point, icon);
          var infoTabs = [
          new GInfoWindowTab("Address", '<div style="width: 300px"><a style="color: Red" href="StoreDetails.aspx?store='+num+'">' + name + '</a>' + '<br>' + address + '<br>' + '<a style="color: Red" target="_blank" href="http://maps.google.com/maps?q='+ProximityLocations.locations[locationNumber-1].latitude+','+ProximityLocations.locations[locationNumber-1].longitude+'('+urladdress+')">Get Directional Info</a>' + '<br>' + pic + '</div'),
          new GInfoWindowTab("Contact Info", "Phone: " + phone + '<br>' + "Fax: " + fax + '<br>' + "Email: " + '<a style="color: Red" href="mailto:' + email + '">' + email + '</a>' + '<br>' + "Website: " + '<a style="color: Red" target="_blank" href="'+website+'">'+website+'</a>'),
          new GInfoWindowTab("Store Hours", "Monday:       " + monhours + '<br>' + 
                                            "Tuesday:      " + tueshours + '<br>' + 
                                            "Wednesday:    " + wedhours + '<br>' + 
                                            "Thursday:     " + thurshours + '<br>' + 
                                            "Friday:       " + frihours + '<br>' + 
                                            "Saturday:     " + sathours + '<br>' + 
                                            "Sunday:       " + sunhours + '<br>')
           ];
          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].num, 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].pic, ProximityLocations.locations[i].urladdress, i+1));
        }
     }
   }
}




