﻿var geocoder;
var map;
var address;

function loadMap(placeName, locationDetails, address) {
    // Create new map object
    map = new GMap2(document.getElementById("map"));
    map.addControl(new GLargeMapControl());

    // Create new geocoding object
    geocoder = new GClientGeocoder();

    // Retrieve location information, pass it to addToMap()
    geocoder.getLocations(address, addToMap);

    // Use place name as header and also show details for the popup window
    document.getElementById("LocationPlaceName").innerHTML = placeName;
    document.getElementById("LocationDetails").innerHTML = locationDetails;

    // Hide the video player because the layer cannot overlay on it
    showOrHideVideoPlayer("hidden");
}

function addToMap(response) {
    // Retrieve the object
    place = response.Placemark[0];

    // Retrieve the latitude and longitude
    point = new GLatLng(place.Point.coordinates[1], place.Point.coordinates[0]);

    // Center the map on this point
    map.setCenter(point, 13);

    // Create a marker
    marker = new GMarker(point);

    // Add the marker to map
    map.addOverlay(marker);

    // Add address information to marker
    marker.openInfoWindowHtml("<div style='width:190px; font-size:12px; color:#555; font-family:Tahoma; line-height:20px;'>" + place.address + "</div>");

    // Show Modal Map Pop Up
    GoogleMap('show');
}

window.onunload = GUnload;


// Google Map Modal Popup 
function GoogleMap(showOrHide) {
    var elemGoogleMap = document.getElementById("GoogleMap");
    var elemMapBg = document.getElementById("MapBg");

    if (showOrHide == "show") {
        elemGoogleMap.style.top = "50%";
        elemMapBg.style.display = "block";
    } else {
        elemGoogleMap.style.top = "-100000px";
        elemMapBg.style.display = "none";
        
        // show video player again
        showOrHideVideoPlayer("visible");
    }
}
