    var mapReadyToShow = false;
    
    function showButtonInline(id) {
        showMap = document.getElementById(id);
        if (showMap) {
          showMap.style.display = 'inline';
        }
    }

    function showGoogleMap(mapId, showBtn, closeBtn, regionName) {
        var callback = "displayGoogleMap(true,'" + mapId + "','" + showBtn + "','" + closeBtn+ "','" + regionName + "');";
        google.load("maps","2.159", {"other_params":"client=gme-wotif&sensor=false", "callback":callback});
    }

    function hideGoogleMap(mapId, showBtn, closeBtn, regionName) {
        displayGoogleMap(false, mapId, showBtn, closeBtn, regionName);
    }

    function displayGoogleMap(display, mapId, showBtn, closeBtn, regionName) {
        if (!mapReadyToShow) {
          return;
        }
    	if (window["setCookie"] != null) {
            setCookie(regionName, display);
        }
    
		if (display) {
            showControls(mapId, showBtn, closeBtn);
		    onMapDisplay(mapId);
		} else {
            hideControls(mapId, showBtn, closeBtn);
		    onMapClose(mapId);
		}
    }

    function showControls(mapId, showBtn, closeBtn) {
        var map = document.getElementById(mapId);
		var mapDirectionsControl = document.getElementById(mapId + '-directionscontrol');
		var mapControlPanel = document.getElementById(mapId + '-controlpanel');
        var showMapButton = document.getElementById(showBtn);
		var closeMapButton = document.getElementById(closeBtn);

        setClassName(map, 'map-displayed');
        setClassName(mapDirectionsControl, 'map-directionscontrol-displayed');
        setDisplay(mapControlPanel, 'inline');
        setDisplay(closeMapButton, 'inline');
        setDisplay(showMapButton, 'none');
    }

    function hideControls(mapId, showBtn, closeBtn) {
        var map = document.getElementById(mapId);
        var mapError = document.getElementById(mapId + '-unavailable');
		var mapDirectionsControl = document.getElementById(mapId + '-directionscontrol');
		var mapControlPanel = document.getElementById(mapId + '-controlpanel');
        var showMapButton = document.getElementById(showBtn);
		var closeMapButton = document.getElementById(closeBtn);

        setClassName(map, 'map-hidden');
        setDisplay(mapControlPanel, 'none');
        setClassName(mapError, 'map-unavailable-hidden');
        setClassName(mapDirectionsControl, 'map-directionscontrol-hidden');
        setDisplay(closeMapButton, 'none');
        setDisplay(showMapButton, 'inline');
    }

    function showGoogleMapForInventory(mapId, showBtn, closeBtn, selectedInventoryId, regionName) {
        var callback = function() {
            if (!mapReadyToShow) {
              return;
            }

            if (selectedInventoryId == '') {
                displayGoogleMap(true, mapId, showBtn, closeBtn, regionName);
            } else {
                setCookie(regionName, true);

                showControls(mapId, showBtn, closeBtn);
                onMapDisplay(mapId, selectedInventoryId);
            }
        };

        google.load("maps","2.159", {"other_params":"client=gme-wotif&sensor=false", "callback":callback});
    }

	function hideDirections(mapId) {
  		var mapdirections = document.getElementById(mapId + '-directions');
	    setClassName(mapdirections, 'map-directions-hidden');
	}
	
    function setClassName(element, className) {
        if (element) {
            element.className = className;
        }
    } 
    
    function readyMapForDisplay(mapId, showBtn, closeBtn) {
		showControls(mapId, showBtn, closeBtn);
    	displayMapOnLoad[mapId]  = true;
    }
    
