  google.load("maps", "2.x");

  // Call this function when the page has been loaded
  function genGoogleMap(elemId,mapSize) {
    //alert(elemId);
    document.getElementById(elemId).innerHTML="Google Map";
    //var mapSize = (mapSize == null) ? 'small' : mapSize; // Set default to small map
    var map = new google.maps.Map2(document.getElementById(elemId));
    var geocoder = new GClientGeocoder();

    geocoder.setBaseCountryCode('US');
    geocoder.getLatLng(
       myStreetAddress,
       function(point) {
         if (!point) {
            //alert(address + " not found");
         } else {
            var marker = new GMarker(point);
            map.setCenter(point, 12);
            map.addOverlay(marker);
	    if (mapSize == 'small') {
               document.getElementById(elemId).style.display = "block";
	       document.getElementById(elemId).style.border = " 1px solid #000";
	       document.getElementById(elemId).style.background = "#ddd";
	       GEvent.addListener(map, "click", function() {
	          fireMyPopup();
	       });
	    }
	    if (mapSize == 'large') {
               document.getElementById('gmapTitleBar').innerHTML = myCompanyName;
               marker.openInfoWindowHtml(myInfoWindowContent);
	       map.addControl(new GLargeMapControl());
            }
         }
       }
    );

  }

function myPopupRelocate() {
 var scrolledX, scrolledY;
 if( self.pageYOffset ) {
   scrolledX = self.pageXOffset;
   scrolledY = self.pageYOffset;
 } else if( document.documentElement && document.documentElement.scrollTop ) {
   scrolledX = document.documentElement.scrollLeft;
   scrolledY = document.documentElement.scrollTop;
 } else if( document.body ) {
   scrolledX = document.body.scrollLeft;
   scrolledY = document.body.scrollTop;
 }

 var centerX, centerY;
 if( self.innerHeight ) {
   centerX = self.innerWidth;
   centerY = self.innerHeight;
 } else if( document.documentElement && document.documentElement.clientHeight ) {
   centerX = document.documentElement.clientWidth;
   centerY = document.documentElement.clientHeight;
 } else if( document.body ) {
   centerX = document.body.clientWidth;
   centerY = document.body.clientHeight;
 }

 var leftOffset = scrolledX + (centerX - 500) / 2;
 var topOffset = scrolledY + (centerY - 500) / 2;

 //document.getElementById("gmap_float").style.top = topOffset + "px";
 //document.getElementById("gmap_float").style.left = leftOffset + "px";
  document.getElementById("gmap_float").style.top = topOffset + "px";
  document.getElementById("gmap_float").style.left = leftOffset + "px";
  document.getElementById("gmap_float").style.display = "block";
}

function fireMyPopup() {
 myPopupRelocate();
 document.getElementById("gmap_float").style.display = "block";
 genGoogleMap('gmap_large','large')
 document.body.onscroll = myPopupRelocate;
 window.onscroll = myPopupRelocate;
}
function closeMyPopup() {
 document.getElementById("gmap_float").style.display = "none";
 document.body.onscroll = null;
 window.onscroll = null;
}

 function loadMaps() {
   google.load("maps", "2", {"callback" : mapsLoaded});
 }
 function mapsLoaded() {
//    alert('loaded');
  genGoogleMap('gmap_small','small');
 }

window.onload=loadMaps;

