function lista_immagini_home() {
  resetImmagini();
  var myAjax = new Ajax.Request(
			url_immagini_home, 
			{
				method: 'post',
				onComplete: visualizzaListaImmaginiHome
			});
}

function visualizzaListaImmaginiHome(originalRequest) {
  if (!(/^\{/.test(originalRequest.responseText))) { return ; }
  var result = eval('(' + originalRequest.responseText + ')');

  if (/^debug:/i.test(result.messaggio)) { alert(originalRequest.responseText); return ; }
  
  if (result.errore == 0) {
    var schede = result.schede;
    var indice_td = 1;
    
    if (schede.length>0) {
      for (var i=0; i<schede.length; i++) {
         var scheda = schede[i];
         
         if ((scheda.foto != '')&&(!/^undefined$/.test(scheda.foto))) {
           immagine = result.url + scheda.id + '/' + scheda.foto;
           immagine = immagine.replace(/ /,'%20');
           
           tipologia = '';
           if (scheda.tipologia == 'Ristrutturazioni') { tipologia = 'ristrutturazioni'; }
           if (scheda.tipologia == 'Costruzioni realizzate') { tipologia = 'costruzionirealizzate'; }
           if (scheda.tipologia == 'Vendita immobili') { tipologia = 'venditaimmobili'; }

           $('foto_home_'+indice_td).innerHTML = "<a href='home.php?page="+tipologia+"&scheda="+scheda.id+"'><img src='"+immagine+"' alt='clicca per i dettagli' width='221' height='138' border='0'/></a>";
           indice_td++;
         }
      }
    }
  } else {
    alert("Non sono riuscito a recuperare la lista delle immagini: "+result.messaggio);
  }  
}

function resetImmagini() {
  $('foto_home_1').innerHTML = "<img src='"+url_immagine_blank+"' alt='clicca per ingrandire' width='221' height='138' />";
  $('foto_home_2').innerHTML = "<img src='"+url_immagine_blank+"' alt='clicca per ingrandire' width='221' height='138' />";
  $('foto_home_3').innerHTML = "<img src='"+url_immagine_blank+"' alt='clicca per ingrandire' width='221' height='138' />";
}

