var rapporto=0
var delta = 5
var daLooppare=0
var testo_visibile=0
var playBloccata=1
var stopBloccata=0
var pauseBloccata=0
var rapportoTempoSettato=0

var durata_video = 0
var startTime;
var finishTime = null;
var timerID;
var totPct = 0;
var fetchInterval = 0;
var pctIncr  = 0.01;
//var pb1;
var inizio;

// Duration of crossfade (seconds)
var crossFadeDuration = 3

var t
var j = 0
var p = Pic.length


var preLoad = new Array()
for (i = 0; i < p; i++){
   preLoad[i] = new Image()
   preLoad[i].src = Pic[i]
}


function runSlideShow(){
   if(Pic.length!=0){
	if (document.all){
      document.images.SlideShow.style.filter="blendTrans(duration=2)"
      document.images.SlideShow.style.filter='blendTrans(duration=crossFadeDuration)'
      document.images.SlideShow.filters.blendTrans.Apply()
   }
   document.images.SlideShow.src = preLoad[j].src
   if (document.all){
      document.images.SlideShow.filters.blendTrans.Play()
   }
   
   
   j = j + 1
   if (j <= (p-1)){
   	if(picCaption.length!=0){
   		caption = "<span class='titolo-box'>Descrizione dell'immagine</span><br /><br /> "+picCaption[j];
	}else{
		caption = "<span class='titolo-box'>Descrizione dell'immagine</span><br /><br /> ";
	}
	if(current_active=="caption"){
		document.getElementById('rightpanel').innerHTML = caption;
		document.getElementById('bottone_testo').innerHTML = bottone_testo_text; 
	}
	//current_active = "caption";
   	t = setTimeout('runSlideShow()', slideShowSpeed)
   }
   }
}

function settaTempoBarra(tempo)
{
	fetchInterval=tempo
}



function stoppaBarra()
{
	  clearTimeout(timerID);
	  totPct=0;
	  //pb1.setPercent(totPct);
}


function setProgress_DELETEME() {//da commentare e controllare TODO
  clearTimeout(timerID);
  totPct += pctIncr;

  //pb1.setPercent(totPct);


  if (totPct < 1.0) timerID = setTimeout("setProgress()", fetchInterval);
  else if (finishTime == null) {
    finishTime = new Date();
    }
  }


function initPage() {
	  //MM_preloadImages('gif/audio_play2.gif','gif/audio_stop2.gif','gif/audio_pause2.gif','gif/showtext_up.gif');
	  //pb1 = new jt_ProgressBar(document.getElementById("esp"), 458, 5, "bgBarRed");
	  settaSlide();
	  inizio = setTimeout("StartMeUp()", 3000);	 
}

function settaSlide()
{
	//tempoBarra1=Math.round(durata_audio1*10)
	numero=Pic.length
	
	if(numero!=0){
		slideShowSpeed=Math.round((durata_audio1/numero)*1000)
	} else {
		slideShowSpeed = durata_audio1;
	}
	//settaTempoBarra(tempoBarra1)

}
function disattiva(daDisattivare)
{
	document.getElementById('playImage').src=playImage_off;
	document.getElementById('stopImage').src=stopImage_off;
	document.getElementById('pauseImage').src=pauseImage_off;

}
function attiva(daAttivare)
{
	disattiva();
	if (daAttivare==1)
	{
		document.getElementById('playImage').src=playImage_on;
		playBloccata=1
		stopBloccata=0
		pauseBloccata=0
	}
	else
	if (daAttivare==2)
	{
		document.getElementById('stopImage').src=stopImage_on;
		playBloccata=0
		stopBloccata=1
		pauseBloccata=0
	}
	if (daAttivare==3)
	{
			document.getElementById('pauseImage').src=pauseImage_on;
			playBloccata=0
			stopBloccata=0
			pauseBloccata=1
	}

}

function trovaAttiva()
{
	if (playBloccata==1)
		return 1;
	else if (stopBloccata==1)
		return 2;
	else
		return 3;

}
function StartMeUp () //questa  fa partire
{
    if(picCaption.lenght == 0){
    	caption = "<span class='titolo-box'>Descrizione dell'immagine</span><br /><br /> Nessuna didascalia disponibile";
		document.getElementById('rightpanel').innerHTML = caption;
	}
    
	
	clearTimeout(inizio);
 	if(durata_audio1!=0){
    progressBar('run');
    sendEvent('start,'+audioFileFullAddress); //manda cmd a flash
    t = setTimeout('runSlideShow()', slideShowSpeed) //fa partire slideshow
    attiva(1);
 	}
    //timerID = setTimeout("setProgress()", fetchInterval); TODO
}

function ShutMeDown ()
{
	
	sendEvent('stop');
	attiva(2);
    clearTimeout(t);
    if(Pic.length!=0){
    	slide=p-1;
    	document.images.SlideShow.src = preLoad[slide].src
    } else document.images.SlideShow.src = blank;
    j=0;
    
    rapporto=0;
	progressBar('stop');
    
}

function PauseMe ()
{
    a=trovaAttiva()
    if(a==2)
    	return;
    //audio1.controls.pause();
    sendEvent('pause');
    clearTimeout(t);
    rapporto=0;
	progressBar('pause');
    attiva(3);
}



function switcha()
{
	if (current_active == "caption"){
		document.getElementById('rightpanel').innerHTML = alttext;
		document.getElementById('bottone_testo').innerHTML = bottone_testo_caption; 
		current_active = "alttext";
	} else if (current_active == "alttext"){
		if(picCaption.length!=0){
			caption = "<span class='titolo-box'>Descrizione dell'immagine</span><br /><br /> "+picCaption[j];
		}else{
			caption = "<span class='titolo-box'>Descrizione dell'immagine</span><br /><br /> ";
		}
		document.getElementById('rightpanel').innerHTML = caption;
		document.getElementById('bottone_testo').innerHTML = bottone_testo_text; 
		current_active = "caption";
	}	
}


function full(){
window.open('pagina.html','','fullscreen=1,scrollbars=0');
}

function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
    	
}

function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
	currentActive = "alttext"
  	var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}
