var iconData = {
  "bolt": { width: 24, height: 24 },
  "bolt-shadow": { width: 48, height: 24 },
  "nut": { width: 24, height: 24 },
  "nut-shadow": { width: 48, height: 24 }
};

function bodyOnLoad(){
  //var storeLoc = document.getElementById("StoreLocator");
  //storeLoc.style.display='none';
}

    function loadGMap(lat, lon, zoom, state) {
    
      if (!window.XMLHttpRequest) {// IE6, older browsers can't handle the memory load of the google map with all the points
        var sURL = 'locations.ex?action=search&zip='
          + '&state=' + state;
        window.location.href = sURL;
      } else {
        var sMap = document.getElementById("stateMap");
        if (sMap != null) sMap.style.display='none';
        var wMap = document.getElementById("worldMap");
        if (wMap != null) wMap.style.display='none';
        var sMap = document.getElementById("wMapKey");
        if (sMap != null) sMap.style.display='none';
        var wMap = document.getElementById("sMapKey");
        if (wMap != null) wMap.style.display='none';
        var gMap = document.getElementById("map");
        if (gMap != null) gMap.style.display='block';
        var gMap = document.getElementById("wMapLink");
        if (gMap != null) gMap.style.display='block';
        var gMap = document.getElementById("sMapLink");
        if (gMap != null) gMap.style.display='block';
        var wMap = document.getElementById("gMapKey");
        if (wMap != null) wMap.style.display='block';
        gload(lat, lon, zoom); 
      }
    }



    function loadSMap() {
      var wMap = document.getElementById("worldMap");
      if (wMap != null) wMap.style.display='none';
      var gMap = document.getElementById("map");
      if (gMap != null) gMap.style.display='none';
      var gMap = document.getElementById("sMapLink");
      if (gMap != null) gMap.style.display='none';
      var sMap = document.getElementById("wMapKey");
      if (sMap != null) sMap.style.display='none';
      var wMap = document.getElementById("gMapKey");
      if (wMap != null) wMap.style.display='none';
      var wMap = document.getElementById("sMapKey");
      if (wMap != null) wMap.style.display='block';
      var sMap = document.getElementById("stateMap");
      if (sMap != null) sMap.style.display='block';
      var gMap = document.getElementById("wMapLink");
      if (gMap != null) gMap.style.display='block';
    }
    
    function loadWMap() {
      var gMap = document.getElementById("map");
      if (gMap != null) gMap.style.display='none';
      var sMap = document.getElementById("stateMap");
      if (sMap != null) sMap.style.display='none';
      var gMap = document.getElementById("wMapLink");
      if (gMap != null) gMap.style.display='none';
      var gMap = document.getElementById("sMapLink");
      if (gMap != null) gMap.style.display='none';
      var wMap = document.getElementById("sMapKey");
      if (wMap != null) wMap.style.display='none';
      var wMap = document.getElementById("gMapKey");
      if (wMap != null) wMap.style.display='none';
      var wMap = document.getElementById("worldMap");
      if (wMap != null) wMap.style.display='block';
      var sMap = document.getElementById("wMapKey");
      if (sMap != null) sMap.style.display='block';
    }
    
    //<![CDATA[
    var map;
    var oDone = false;
    var icons = {};

    function gload(lat, lon, zoom) {
      if (GBrowserIsCompatible()) {
        map = new GMap2(document.getElementById("map"));
        map.addControl(new GLargeMapControl()); 
        map.addControl(new GMapTypeControl());
        map.setCenter(new GLatLng(lat, lon), zoom);
        map.enableDoubleClickZoom();
        window.setTimeout(setupOfficeMarkers, 0);
      }
    }

    function getIcon(images) {
      var icon = null;
      if (images) {
        if (icons[images[0]]) {
          icon = icons[images[0]];
        } else {
          icon = new GIcon();
          icon.image = "../common/images/icons/" + images[0] + ".png";
          var size = iconData[images[0]];
          icon.iconSize = new GSize(size.width, size.height);
          icon.iconAnchor = new GPoint(size.width >> 1, size.height >> 1);
          icon.shadow = "../common/images/icons/" + images[1] + ".png";
          size = iconData[images[1]];
          icon.shadowSize = new GSize(size.width, size.height);
          icon.infoWindowAnchor = new GPoint(size.width >> 1, size.height >> 1);
          icons[images[0]] = icon;
        }
      }
      return icon;
    }
    var bIcon, nIcon;
    
    
function setupOfficeMarkers() {
  var clusterer = new Clusterer(map);
  bIcon = getIcon(["bolt", "bolt-shadow"]);
  nIcon = getIcon(["nut", "nut-shadow"]);
  clusterer.SetMaxVisibleMarkers(20);
  clusterer.SetMaxLinesPerInfoBox(6);
  clusterer.SetIcon(nIcon);
  setupMyOfficeLayer();
  var i;
  for (i = myOfficeLayer.length; i >= 0; i--) {
    var place = myOfficeLayer[i];          
    if (place != null){
      if (typeof( place[1]) != "undefined"){
        var posn = new GLatLng(place[1], place[2]);
        var aGMarker = new GMarker(posn, { title: place[0], icon: bIcon });
        aGMarker.title = place[0];        
        clusterer.AddMarker(aGMarker, aGMarker.title);
      }
    }
    myOfficeLayer.splice(i, 1);
  }
  
  myOfficeLayer.length = 0;
  myOfficeLayer = null;
}
    
    
    function reSetupOfficeMarkers(clusterer) {
      //clusterer.markers.length = 0;
      Clusterer.DisplayMarkers(clusterer);
      
    }
    
    function addLabelMarker(pMarker, label) {
      GEvent.addListener(pMarker, "click", function() {
        pMarker.openInfoWindowHtml('<div class="divinfowindow">' + label + '<\/div>');
      });
      return pMarker;
    }
    
    //]]>