// function visText: visual news text
function visText(serverPage, objID, newsId) {
   var obj = document.getElementById(objID);
   // ricava l'oggetto relativo al pulsante apri/chiudi
   nameButt = "butt" + newsId;
   var objButt = document.getElementById(nameButt);
 
   if (obj.innerHTML == "") {
      var searchPage = serverPage + "?id=" + newsId;
      xmlhttp.open("GET", searchPage);
      xmlhttp.onreadystatechange = function() {
         if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
	    // attiva il contenitore del testo della news per inserirci il testo
	    obj.style.height = "";
            obj.style.display = "block";
            obj.innerHTML = xmlhttp.responseText;
            objButt.innerHTML="<img src=\"img/freccia_v.gif\" >";
            // ricava la dimensione dell'elemento e pone l'altezza a 0px in modo che sia l'animazione ad aprirlo
	    heightElem = obj.offsetHeight;
            obj.style.height = "0px";
	    apriNews(0,objID,heightElem);
         }
      }
      xmlhttp.send(null);
   } else {
      heightElem = obj.offsetHeight;
      chiudiNews(heightElem,objID);
      objButt.innerHTML="<img src=\"img/freccia_o.gif\">";
   }
}


function apriNews(i,objID,heightElem)
{
   var obj = document.getElementById(objID);
   // alert(heightElem);
   // alert(objID);
   if (i<heightElem) {
      obj.style.height=i+"px";
      // alert(i);
      i=i+7;
      setTimeout('apriNews('+i+',"'+objID+'",'+heightElem+')',1);
   }
}

function chiudiNews(i,objID)
{
   var obj = document.getElementById(objID);
   if (i>0) {
      obj.style.height=i+"px";
      i=i-7;
      setTimeout('chiudiNews('+i+',"'+objID+'")',1);
   } else {
      obj.style.display = "none";
      obj.innerHTML="";
   }
}


//funzione ricorsiva che chiama internamente visText, con un ritardo di 2 sec 
//passandogli successivamente ciascun id delle news contenuto nel vettore v;
//
var indiceNews=0;
 
function visNewsArray()
{ //alert("ciao "+indiceNews+" "+v.length);
  if (indiceNews<v.length)
  {  visText('news/textNews.php', 'news'+v[indiceNews], v[indiceNews]);
     indiceNews++;
     setTimeout('visNewsArray()',2000);
  }
	else indiceNews=0;
}
