
function loadMap (thelongitude,thelatitude) {
  var elem = document.getElementById("map");
  var isLoaded = false;
  if (GBrowserIsCompatible() && elem) {
    cursorWait();
    map = new GMap2(elem);
//    map.getMapTypes().pop();
    map.addControl(new GLargeMapControl());
    map.addControl(new GMapTypeControl());
    map.addControl(new GScaleControl());
    map.addControl(new GOverviewMapControl());
    longitude = thelongitude;
    latitude = thelatitude;
    var center = new GLatLng(latitude,longitude);
    isLoaded = loadStateFromCookies();
    if (!isLoaded) {
      map.setCenter(center, 17 - mymapZoom, getMapType(mymapTypeName));
      updateCookies();
      updateAttrCookie(false,false);
      updateHotelCookie(false,false);
    }
    if (attrNo!=0) {
      var marker = createAttrMarkerWithTrip(longitude,latitude, balloon,attrNo,mainIcon);
      marker.setTooltip(attrName.replace(/ /g,"&nbsp;"));
      map.addOverlay(marker);
      if (!isLoaded) openInfo(attrNo);
      isLoaded = true;
    }
    else
    {
      if (isCityIconShown) {
        var marker = createAttrMarker(longitude,latitude,balloon,attrNo,cityIcon);
        var cityname = city + ", " + state;
        marker.setTooltip(cityname.replace(/ /g,"&nbsp;"));
        map.addOverlay(marker);
        if (!isLoaded) {
          var theCtrl = document.getElementById("attractlink");
          switchNearbyAttractionMode(theCtrl);
          isLoaded = true;
        }
      }
    }
    GEvent.addListener(map, "moveend", updateCookies);
    GEvent.addListener(map, "maptypechanged", updateCookies);
    GEvent.addListener(map, "zoom", updateZoomCookie);
    GEvent.addListener(map,"load", cursorClear());
  }
  return isLoaded;
}

// Creates a marker whose info window displays the given number
function createMarker(longitude, latitude, html,itemNo,icon,itemtype,rating) {
  var point = new GPoint(parseFloat(longitude),parseFloat(latitude));
  var key = itemtype+itemNo;
  var marker = markersByAttrNo[key];
  if (marker==null) {
    marker = new PdMarker(point, icon, "");
    marker.setImage(icon.image);
    if (html!="") {
      // Show this marker's index in the info window when it is clicked
      GEvent.addListener(marker, "click", function() {
        marker.openInfoWindowHtml(html);
        openInfoKey = key;
        updateOpenInfoCookie(itemtype,itemNo);
      });
    }
    marker.html = html;
    marker.attractNo = itemNo;
    marker.roadsideType = itemtype;
    marker.roadsideRating = rating;
    markersByAttrNo[key] = marker;
  }
  marker.show();

  return marker;
}


function getIcon(iconUrl, shadowUrl, printShadowUrl) {
  var icon = new GIcon();
  icon.image = iconUrl;
  icon.shadow = shadowUrl;
  icon.printImage = iconUrl;
  icon.mozPrintImage = iconUrl;
  if (printShadowUrl) {
    icon.printShadow = printShadowUrl;
  }
  icon.iconSize = new GSize(33, 40);
  icon.shadowSize = new GSize(33, 40);
  icon.iconAnchor = new GPoint(16, 40);
  icon.infoWindowAnchor = new GPoint(16, 10);
  return icon;
}


var mapTypeArray = new Array();
mapTypeArray["G_MAP_TYPE"] = G_NORMAL_MAP;
mapTypeArray["G_SATELLITE_TYPE" ] = G_SATELLITE_MAP;
mapTypeArray["G_HYBRID_TYPE" ] = G_HYBRID_MAP;

function initMap(x,y,z,mtype) {
  map.setCenter(new GLatLng(y, x), z, mtype);
}

var lastMarker;
function updateZindex(marker) {
  try {
    if (lastMarker) {
      lastMarker.restoreMarkerZIndex();
    }
    marker.show();
    marker.topMarkerZIndex();
    lastMarker = marker;
  } catch (e) {
    // do nothing
  }
}


function removeMarkers(markerArray,skipKey) {
  for (var i = 0; i < markerArray.length; i++) {
    var marker = markerArray[i];
    var key = marker.roadsideType+marker.attractNo;
    if (key!=skipKey) {
      if (key==openInfoKey) {
        map.closeInfoWindow();
      }
      marker.hide();
    }
  }
}


function showMarkers(markerArray,skipKey) {
  for (var i = 0; i < markerArray.length; i++) {
    var marker = markerArray[i];
    var key = marker.roadsideType+marker.attractNo;
    if (key!=skipKey) {
      marker.show();
    }
  }
}

function unloadForm()
{
  GUnload();
}


