﻿// JScript File
    var map = null;
    var geocoder = null;
    var baseIcon = null;
    var bubble =null;
    function addLoadEvent(func) {
        var oldonload = window.onload;
        if (typeof window.onload != 'function') {
            window.onload = func;
        } else {
            window.onload = function() {
                if (oldonload) {
                    oldonload();
                }
                func();
            }
        }
    }
 function closeBubble() {
      bubble.hide();
    }
    
 function loadMap() {
      if (GBrowserIsCompatible()) {
        map = new GMap2(document.getElementById("map_canvas"));
        map.setCenter(new GLatLng(37.4419, -100.1419), 3);
        //map.setCenter(new GLatLng(42.366662,-71.106262), 11);
        var mapControl = new GMapTypeControl();
        map.addControl(mapControl);
        map.addControl(new GLargeMapControl());
        geocoder = new GClientGeocoder();
      
      }
    }
    
function showAddress(address) {
      if (geocoder) {
        geocoder.getLatLng(
          address,
          function(point) {
            if (!point) {
              alert(address + " not found");
            } else {
              map.setCenter(point,11);
             
            }
          }
        );
      }
    }
function addmarker(lat,lng,letter,iframe)
   {
        // Create a base icon for all of our markers that specifies the
        // shadow, icon dimensions, etc.
        var baseIcon = new GIcon();
        baseIcon.shadow = "/dealer/assets/img/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);
      
      // == Create an EBubble ==
      // Parameters
      // ==========
      // 1. map.
      // 2. URL of the background image
      // 3. GSize() specifying the size of that image
      // 4. GSize() specifying the size of the inner area when the contents can be written.
      // 5. GPoint() specifying the offset of top left corner of the inner area from the top left corner of the background image
      // 6. GPoint() specifying the anchor point of the image.
      // ==========
     // bubble = new EBubble(-1-, -  2                           -",-      3         -,-      4         -,-      5         -, -      6         -);      
      bubble = new EBubble(map, "/dealer/assets/img/infoBubble.png",new GSize(213,205), new GSize(213,177), new GPoint(0,0), new GPoint(52,201));      
      
        // Creates a marker whose info window displays the letter corresponding
        // to the given index.
        function createMarker(point, letter, iframe) {
          // Create a lettered icon for this point using our icon class
           var letteredIcon = new GIcon(baseIcon);
          letteredIcon.image = "/dealer/assets/img/marker" + letter + ".png";

          // Set up our GMarkerOptions object
          markerOptions = { icon:letteredIcon };
          var marker = new GMarker(point, markerOptions);

          GEvent.addListener(marker, "click", function() {
           //pan marker to center
           map.panTo(new GLatLng(lat + .05, lng + .01));
           //delay 1 sec for pan
           window.setTimeout(function() {
            bubble.openOnMarker(marker,iframe);
            }, 1000);
                      
           
          });
          return marker;
        }
      
     var point = new GLatLng(lat,lng);
     map.addOverlay(createMarker(point,letter,iframe));
    }
function goToMarker(dealerId,lat,lng){
//*********************************************************************//
//***  This function is used to open the Info Window from the list
//***  
//*********************************************************************//

    //Close any open eBubbles
   if(bubble){bubble.hide();}
    //Center Map on lat,lng
    map.panTo(new GLatLng(lat + .05, lng + .01));

    //Create new eBubble IFrame
    // bubble = new EBubble(-1-, -  2                           -",-      3         -,-      4         -,-      5         -, -      6         -);      
      bubble = new EBubble(map, "/dealer/assets/img/infoBubble.png",new GSize(213,205), new GSize(213,177), new GPoint(0,0), new GPoint(52,201));      
     var dealerIFrame = "<iframe src='dealerInfo.aspx?did=" + dealerId + "' height=177 width=225 frameborder=0 Allowtransparency=True></iframe>";
     
      //Open eBubble after 1 sec delay (this allows pan to finish.
     window.setTimeout(function() {
            //point, html, offset
            bubble.openOnMap(new GLatLng(lat, lng),dealerIFrame,new GPoint(0, 35));
            }, 1000);
    
                         
}