// ******* ********* ********* ********* ********* ********* ********* *********

var map;
// var mgr;
var Icon;
// var marcador;

var latIni;
var lngIni;
var zoomIni;
var tipoIni;

var lm; // lista de marcadores;

function load(latIni_, lngIni_, zoomIni_, tipoIni_) {
  if (GBrowserIsCompatible()) {
    latIni = latIni_;
    lngIni = lngIni_;
    zoomIni = zoomIni_;
    tipoIni = tipoIni_;
    map = new GMap2(document.getElementById("map"));

    // ====== Restricting the range of Zoom Levels =====
    // Get the list of map types      
    var mt = map.getMapTypes();
    // Overwrite the getMinimumResolution() and getMaximumResolution() methods
    for (var i=0; i<mt.length; i++) {
      mt[i].getMinimumResolution = function() {return 12;}
      mt[i].getMaximumResolution = function() {return 17;}
    }

    map.addControl(new GLargeMapControl());
    map.addControl(new GMapTypeControl());
    map.addControl(new GScaleControl());
    // map.setMapType(_HYBRID_TYPE);
    centrarMapaInicial(latIni, lngIni, zoomIni, tipoIni);
 
    Icon = new GIcon();
    Icon.iconSize=new GSize(32,32);
    Icon.shadowSize=new GSize(56,32);
    Icon.iconAnchor=new GPoint(16,32);
    Icon.infoWindowAnchor=new GPoint(16,0);
    pathBaseIcon = "";
    Icon.image = pathBaseIcon + "/cruz_verde.png";
    Icon.shadow = pathBaseIcon + "/cruz_sombra.png";

    iniciar_();
  }
}


// ******* ********* ********* ********* ********* ********* ********* *********

function cargarMarcadores() {
  var bounds = map.getBounds();
  if (!lastBounds.containsBounds(bounds)) {
    actualizarLimites(bounds);
  }
  // document.getElementById("output").value = urlRequest;
}

// ******* ********* ********* ********* ********* ********* ********* *********

function colocarMarcador(lat, lng, textoInfo) {
    // alert("colocar marcador, lat: " + lat + ", lng: " + lng + "\n" + textoInfo);
    var iconoFoto = new GIcon(Icon);
    var marcador = new GMarker(new GLatLng(lat, lng), { draggable:false, icon: iconoFoto});
    GEvent.addListener(marcador, "click", function() {
      marcador.openInfoWindowHtml(textoInfo);
    });
    map.addOverlay(marcador);
    return marcador;
}

// ******* ********* ********* ********* ********* ********* ********* *********

// Posicion, zoom y tipo de mapa inicial
function centrarMapaInicial(geoLat, geoLong, zoomLev, mapType) {
  map.setCenter(new GLatLng(geoLat, geoLong), zoomLev, mapType);
}

function mostrarInfo(id) {
  // alert("Centro: " + id);
  makeHttpRequest('gmGateway.php?id=2&idCentro=' + id, 'colocarSalida', 'infoCentro', false);
}

function resetInfoCentro() {
  xGetElementById("infoCentro").innerHtml = '';
  centrarMapaInicial();
}

// ******* ********* ********* ********* ********* ********* ********* *********

  function panToLL(lat, lng) {
    // alert("lat: " + lat + ", lng: " + lng);
    var pos = new GLatLng(lat, lng);
    map.panTo(pos);
  }

// ******* ********* ********* ********* ********* ********* ********* *********

