var indexthumb=0;
var totalimages=0;

var imgArray = new Array();
var timerID = null
var timerRunning = false
var delay = 4000

function manualupdate(idimg){
AutoStop();
aggiornabig(idimg);
}


function aggiornabig(idimg){
  if (document.all){ // Explorer
  document.getElementById('ImgBig').filters.blendTrans.Apply(); 
  document.getElementById('ImgBig').src=imgArray[idimg][1];	
  document.getElementById('ImgBig').filters.blendTrans.Play(); 
  }
  else
  {
   document.getElementById('ImgBig').src=imgArray[idimg][1];		  
  }
  a = new String(imgArray[idimg][2]);
  a = a.slice(a,a.length-4);
  
  
  
  document.getElementById('descrizione').innerHTML=a;//imgArray[idimg][2];
  

}

function aggiornathumb(startindex) {
  aggiornabig(startindex);
  
  if (startindex < 1) 
    { 
      document.getElementById('area_btnprev').href ="javascript:donothing();" 
	  document.getElementById('BtnPrev').src="LeftDis.png"
    }
  else 
    { 
      document.getElementById('BtnPrev').src="Left.png"
      document.getElementById('area_btnprev').href ="javascript:slideshowBack();" 
	};
  
  if (startindex+5 > (totalimages-1)) 
    { 
      document.getElementById('area_btnnext').href ="javascript:donothing();" 
	  document.getElementById('BtnNext').src="RightDis.png"
    }
  else 
    { 
      document.getElementById('BtnNext').src="Right.png"
      document.getElementById('area_btnnext').href ="javascript:slideshowNext();" 
	};  
  
  for (i=0; i<5; i++) { 
    if (i+startindex > totalimages-1) {
    document.getElementById('area_img'+i).href ="";
	document.getElementById('area_img'+i).style.visibility="hidden";
	}
	else 
	{
	document.getElementById('img'+i).src=imgArray[startindex+i][0];
	document.getElementById('img'+i).alt=imgArray[startindex+i][2];
	document.getElementById('area_img'+i).href ="javascript:manualupdate('"+(startindex+i)+"');";
	document.getElementById('area_img'+i).style.visibility="visible";
	}
  }
}

function slideshowNext() {
  indexthumb = indexthumb+5;
  if (indexthumb > totalimages-1) 
    {
    indexthumb = totalimages-1
	}
  aggiornathumb(indexthumb);
}

function slideshowBack() {
  indexthumb = indexthumb-5;
  if (indexthumb < 0) {indexthumb=0}
  
  aggiornathumb(indexthumb);
}

function aggiungiimg(thumb,normal,testo){
var k = imgArray.length	
totalimages++;
imgArray[k] = new Array();	
imgArray[k][0] = thumb;
imgArray[k][1] = normal;
imgArray[k][2] = testo;
	
}

function donothing(){
	//nothing to do
};

function AutoStop()
{
    if(timerRunning)
        clearTimeout(timerID)
    timerRunning = false
    document.getElementById('ImgStop').src = "Stop_En.png"
    document.getElementById('ImgPlay').src = "Play.png"
}

function AutoPlay()
{
    
    timerRunning = true;
    indexthumb = indexthumb+1;
    if (indexthumb >= totalimages) 
      {
       indexthumb = 0;
	  }
    aggiornathumb(indexthumb);
    aggiornabig(indexthumb);
   
    document.getElementById('ImgPlay').src = "Play_En.png"
    document.getElementById('ImgStop').src = "Stop.png"
    timerID = self.setTimeout("AutoPlay()", delay)
}
