var s=0;
var g=0;
var fromId;
var toId;

function galleria(fromId, toId, maxel){
	var speed = Math.round(500 / 100); 
    var timer = 0; 
	if((fromId <= 0)||(fromId==null)||(fromId=='')) {
		fromId = fotoattiva(maxel);
	}
	if(fromId > 0) {
		var OpStart=100;
		var OpStop=0;
		for(i = OpStart; i >= OpStop; i--) {
			setTimeout("opaco('foto" + fromId +"', " + i + ",false)", (timer * speed));
			setTimeout("opaco('fotoTXT" + fromId +"', " + i + ",false)", (timer * speed));
			timer++; 
		}
	}
	var OpStart=0;
	var OpStop=100;
	for(var i = OpStart; i <= OpStop; i++) { 
		setTimeout("opaco('foto" + toId +"', " + i + ",false)", (timer * speed));
		setTimeout("opaco('fotoTXT" + toId +"', " + i + ",false)", (timer * speed));
		timer++; 
	}
}

function fotoattiva(maxel){
	var identificato = 0;
	for(var y = 1; y <= maxel; y++ ) {
		var nomeid="foto" + y;
		var nomeTXTid="fotoTXT" + y;
		var ds=document.getElementById(nomeid).style.display;
		if(ds=="block") {
			identificato = y;
		} 
		if((identificato > 0)&&(y!=identificato)) {
			document.getElementById(nomeid).style.display="none";
			document.getElementById(nomeTXTid).style.display="none";
		}
	}
	return identificato;
}

function slideshow(maxel, opera) {
	fromId = fotoattiva(maxel);
	toId=fromId + 1;
	if((toId > maxel)||(opera=="stop")) toId=1;
	if(opera=="play") {
		g=setTimeout("galleria("+ fromId +","+ toId +","+maxel+")", 1000);
		s=setTimeout("slideshow("+maxel+", '"+opera+"')", 6000);
	} else if(opera=="pause"){
		clearTimeout(s);
	} else if(opera=="stop"){
		galleria(fromId,1,maxel);
		clearTimeout(s);
	}
}

function playslide(maxel) {
	document.slidetool.opera.value="play";	
	slideshow(maxel);
}
function stopslide(maxel) {
	document.slidetool.opera.value="stop";	
	clearTimeout(s);
}
function pauseslide(maxel) {
	document.slidetool.opera.value="pause";
	slideshow(maxel);
}
function toFoto(fromId, toId, maxel) {
	document.slidetool.opera.value="stop";	
	clearTimeout(s);
	galleria(fromId, toId, maxel);
}

