var poilist = [];


// CLASSE PERCORSO
function poi(nome,descrizione,tipo,latitudine,longitudine,zoom) {
  this.nome         = nome;
  this.descrizione  = descrizione;
  this.tipo         = tipo;
  this.latitudine   = latitudine ;
  this.longitudine  = longitudine;
  this.zoom         = zoom;
  this.icon         = '';
  this.marker       = '';
}


function MostraPoi() {
  
  var zoom_mappa = map.getZoom();
  
  for (var i = 0; i < poilist.length ; i++) {
    if (poilist[i].zoom <= zoom_mappa)
      MostraMarkerPoi(i);
  }  
  
}


function MostraMarkerPoi(indice) {

  var icon = new GIcon();
  if (poilist[indice].tipo==1) {
    icon.iconAnchor = new GPoint(55,43);
  } else {
    icon.iconAnchor = new GPoint(5,5);
  }  
  icon.infoWindowAnchor = new GPoint(15,0);
  icon.image="/img/poi/ico_poi_" +  poilist[indice].tipo + ".png";

  var WindowHtml;
  
  if (poilist[indice].latitudine!=null && poilist[indice].longitudine!=null)
  {
    var marker = new GMarker(new GLatLng(poilist[indice].latitudine,poilist[indice].longitudine), icon);
    map.addOverlay(marker);
    poilist[indice].marker = marker;
    // infowindow partenza
    var newImg = new Image();
    newImg.src = '/img/poi/ico_poi_' +  poilist[indice].tipo + '.png';
    var icowidth  = newImg.width;
    var icoheight = newImg.height;

    WindowHtml = "<b><img class='png' width='" + icowidth + "' height='" + icoheight + "' src='/img/poi/ico_poi_" +  poilist[indice].tipo + ".png'>&nbsp;" + poilist[indice].nome + "</b><br>"
                 + poilist[indice].descrizione;
    GEvent.addListener(marker, "click", function() {
      marker.openInfoWindowHtml(WindowHtml,{maxWidth:250});
    });
  }

}


function RimuoviMarkerPoi() {

  for (var i = 0; i < poilist.length ; i++) {
      if (poilist[i].marker!=null){
        map.removeOverlay(poilist[i].marker);
      }
  }
  
}

function MapZoomModificato() {

  RimuoviMarkerPoi();
  MostraPoi();
  
}

