﻿
var map = null;
var geocoder = null;
var currentPoint = null;
var bSilent = 0; // var to control Silent Mode (No alerts)
var currentID = 0;
var lat = 37.105075146021605;
var log = -8.673923313617706;



function hideMap() {
    var modalPopupBehavior = $find('panelMapsBehaviour');
    modalPopupBehavior.hide();
}
function showMap() {

    var modalPopupBehavior = $find('panelMapsBehaviour');
    modalPopupBehavior.show();

    startMap('mapModal', 1);
}



window.onload = function() { startMap('map', 1); }

function startMap(name, ctrls) {
    if (GBrowserIsCompatible()) {

        map = new GMap2(document.getElementById(name));

        // set map type
        //map.setMapType(G_SATELLITE_MAP);

        //G_PHYSICAL_MAP.getMaximumResolution = function() { return 15 };
        //G_NORMAL_MAP.getMaximumResolution = function() { return 15 };
        //G_SATELLITE_MAP.getMaximumResolution = function() { return 15 };
        //G_HYBRID_MAP.getMaximumResolution = function() { return 15 };

        if (ctrls == 1) {
            // Zoom in - out - etc
            map.addControl(new GSmallMapControl());

            // Make map type buttons visible
            map.addControl(new GMapTypeControl());
        }
        geocoder = new GClientGeocoder();

        //aValues = sLocation.split(",");
        var iPoint;

        //                // Check location values
        //                if (!isNaN(aValues[0]) && !isNaN(aValues[1])) {
        //                    iPoint = new GLatLng(aValues[0], aValues[1]);
        //                    map.setCenter(iPoint, 14);
        //                }
        //                else {
        //                    // Values were invalid - set default location
        //                    iPoint = new GLatLng(37.13171883784762, -8.545475006103515);
        //                    map.setCenter(iPoint, 14);
        //                }

        iPoint = new GLatLng(lat, log);
        map.setCenter(iPoint, 14);
        // Set a marker on the map
        createMarker(iPoint);
        currentPoint = iPoint;
    }
}

// Create a marker whose info window displays the given number.
function createMarker(point) {
    map.clearOverlays();

    var opts = new Object();


    //map.setCenter(point);
    var icon = new GIcon();
    icon.image = "Images/google_pin.png";
    icon.iconSize = new GSize(21, 34);
    icon.iconAnchor = new GPoint(10, 31);
    opts.icon = icon;
    var marker = new GMarker(point, opts);
    marker.icon = icon;
    map.addOverlay(marker);

    return false;
}


