﻿var currentMarker; 
var currentmarker;
var map;
var baseIcon;
var MyOverlay = function(marker, html) {
  this.marker = marker;
  this.html = html;
}
MyOverlay.prototype = new GOverlay();
MyOverlay.prototype.initialize = function(map) {
  var div = document.createElement("div");  
  div.style.display = 'block';
  div.style.height = '232px';
  div.style.width = '250px';
  div.style.backgroundColor = 'transparent';  
  div.innerHTML = this.html;

  // offsets based on popup div dimensions
  offsetY = 231;
  offsetX = 145; 

  div.style.top = (map.fromLatLngToDivPixel(this.marker.getPoint()).y - offsetY) + 'px';
  div.style.left = (map.fromLatLngToDivPixel(this.marker.getPoint()).x - offsetX) + 'px';
  div.style.position = 'absolute';
  div.onclick = closeOverlay;
  
  this._map = map;
  this._div = div;

  map.getPane(G_MAP_FLOAT_PANE).appendChild(div);  
}
MyOverlay.prototype.remove = function(){
  this._div.parentNode.removeChild(this._div);
}
MyOverlay.prototype.redraw = function() {
  //haven't had need for this yet
}
    
function closeOverlay() {
  if (currentMarker) {
    map.removeOverlay(currentMarker.overlay);
    currentMarker.show();
  }
}

    function initialize(centerLat, centerLong, zoomValue) {
      if (GBrowserIsCompatible()) {
        map = new GMap2(document.getElementById("map_canvas"));
        map.setCenter(new GLatLng(centerLat, centerLong), zoomValue);
        map.addControl(new GSmallMapControl());
        map.addControl(new GMapTypeControl());

        // Create a base icon for all of our markers that specifies the
        // shadow, icon dimensions, etc.
        baseIcon = new GIcon("http://www.gowireless.net/images/GOW_talk.gif");        
        baseIcon.iconSize = new GSize(64, 63);        
        baseIcon.iconAnchor = new GPoint(32, 63);
        baseIcon.infoWindowAnchor = new GPoint(34, 64);
        
        
        
               
      }
    }
    
    function createMarker(name, address, city, state, zip, telno, lat, lng, big) {

          var storeIcon = new GIcon(baseIcon);
          storeIcon.image = "http://www.gowireless.net/images/GOW_talk.gif";

          // Set up our GMarkerOptions object
          markerOptions = { icon:storeIcon };
          var marker = new GMarker(new GLatLng(lat, lng), markerOptions);

          GEvent.addListener(marker, "click", function() {
              if (typeof MyOverlay !== 'undefined') {
                if (currentMarker !== 'undefined') {
                  closeOverlay();                  
                }                         
                if (!this.overlay) {
                  // just recording this for use in the closeOverlay function
                  this.overlay = new MyOverlay(this, '<table width="250" border="0" cellspacing="0" cellpadding="0"><tr><td width="250" height="232" align="left" valign="top" class="ballon"><table width="100%" border="0" cellspacing="0" cellpadding="0"><tr><td height="50">&nbsp;</td></tr><tr><td><table width="100%" border="0" cellspacing="0" cellpadding="0"><tr><td width="40">&nbsp;</td><td><p><strong>' + name + '</strong></p><p>' + address  +'<br />' + city + ' ' + state + ' ' + zip + '<br /><a href="get-directions.aspx?sto_id=' + telno + '">Get Direction To Here</a></p></td><td width="40">&nbsp;</td></tr></table></td></tr></table></td></tr></table>');                 
                }
                currentMarker = this;                 
                if (big) {
                    map.panTo(new GLatLng((this.getPoint().lat()), this.getPoint().lng())); 
                    map.setCenter(new GLatLng(lat, lng), 14);
                }
                else {
                
                    //map.panTo(new GLatLng((this.getPoint().lat()), this.getPoint().lng())); 
                }
                map.addOverlay(this.overlay);
                this.hide();
              } else {
                marker.openInfoWindowHtml(html);
              }
          });
            
         
          return marker;
        }
        
   function createDirectionMarker(name, address, city, state, zip, telno, lat, lng) {

          var storeIcon = new GIcon(baseIcon);
          storeIcon.image = "http://www.gowireless.net/images/GOW_talk.gif";

          // Set up our GMarkerOptions object
          markerOptions = { icon:storeIcon };
          var marker = new GMarker(new GLatLng(lat, lng), markerOptions);

          GEvent.addListener(marker, "click", function() {
              if (typeof MyOverlay !== 'undefined') {
                if (currentMarker !== 'undefined') {
                  closeOverlay();                  
                }                         
                if (!this.overlay) {
                  // just recording this for use in the closeOverlay function
                  this.overlay = new MyOverlay(this, '<table width="250" border="0" cellspacing="0" cellpadding="0"><tr><td width="250" height="232" align="left" valign="top" class="ballon"><table width="100%" border="0" cellspacing="0" cellpadding="0"><tr><td height="50">&nbsp;</td></tr><tr><td><table width="100%" border="0" cellspacing="0" cellpadding="0"><tr><td width="40">&nbsp;</td><td><p><strong>' + name + '</strong></p><p>' + address  + '<br>' + city + ' ' + state + ' ' + zip + '<br /><a style=\"display:none\" href="get-directions.aspx?sto_id=' + telno + '">Get Direction To Here</a></p></td><td width="40">&nbsp;</td></tr></table></td></tr></table></td></tr></table>');                 
                }
                currentMarker = this;                 
                
                map.setCenter(new GLatLng(lat, lng), 14);
            
                map.addOverlay(this.overlay);
                this.hide();
              } else {
                marker.openInfoWindowHtml(html);
              }
          });
            
         
          return marker;
        }        
   //initialize(centerLat, centerLong)
   //map.addOverlay(createMarker('alex', 'gulod, guyong', 'sta maria', 'bulacan', '6411425', '3022', 37.4419, -122.1419, false));     

