<!--  Inizio - Nascondiamo lo script ai vecchi browser
/*
	Image Cross Fade Redux
	Version 1.5
	Last revision: 30.12.2008
	steve@slayeroffice.com adn giancarlo.lucarini#alice.it

	Rewrite of old code found here: http://slayeroffice.com/code/imageCrossFade/index.html
*/

window.addEventListener?window.addEventListener('load',so_init,false):window.attachEvent('onload',so_init);

var d=document, imgs = new Array(), zInterval = null, current=0, pause=false;
var w = window;
var chiamata;
var refresh;
var d, n, tinf, tsup, minuti=10; // aggiorna le immagini da webcam ogni 10 minuti

//self.resizeTo("360","460");
self.left = 20;
self.top = 20;

function rinfresca(){ w.location.reload(); }

function ferma() { clearTimeout(chiamata); }

function ResetRefresh() { refresh = 0; }
function SetRefresh() { refresh = -1; }
function setAlign(obj)
{
		if (obj.id == "left")
		{
		   obj.style.position = "relative"; 
		   obj.style.left = "0px";
		   obj.style.right = "160px"; 
		   //obj.style.align = "left";
		   //alert ("Align of image: left");
		}
		else if (obj.id == "right")
		{
		   obj.style.position = "relative"; 
		   obj.style.left = "-160px";
		   obj.style.right = "0px";
		   //obj.style.align = "right";
		   //alert ("Align of image: right");
		}
}

function so_init()
{
//	if(!d.getElementById || !d.createElement)return; // togliere il segno di commento per bloccare il funzionalemnto su Opera

//	css = d.createElement('link');
//	css.setAttribute('href','slideshow2.css');
//	css.setAttribute('rel','stylesheet');
//	css.setAttribute('type','text/css');
//	d.getElementsByTagName('head')[0].appendChild(css);

	imgs = d.getElementById('slideshow').getElementsByTagName('img');
	for(i=1;i<imgs.length;i++) 
	{
	 	imgs[i].xOpacity = 0;
		setAlign(imgs[i]);		
	}
	imgs[0].style.display = 'block';
	imgs[0].xOpacity = .99;
	setAlign(imgs[0]);
	
	SetRefresh();
	chiamata=setTimeout(so_xfade,3000);
}

function so_xfade()
{
    if (refresh == -1) 
	{ 
	  d = new Date();
	  tinf = d.getTime(); 
	  //alert("Refresh " + refresh + "; Set Date: " + d + " millisecond: " + tinf);
	  ResetRefresh();
	  //alert("Refresh " + refresh);
	}
	else {
	   n = new Date();
	   tsup = n.getTime();
	   //alert("tinf " + tinf + "; tsup " + tsup);
	   if (tinf<tsup-60000*minuti) {
	   	   //alert("refresh Image:" + n + " millisecond: " + tsup);
		   SetRefresh();
		   ferma;
		   rinfresca(); //esegue ogni 5000 millisecondi
	   }
	}
	
	cOpacity = imgs[current].xOpacity;
	cAlign = imgs[current].align;
	nIndex = imgs[current+1]?current+1:0;
	nOpacity = imgs[nIndex].xOpacity;
	nAlign = imgs[nIndex].align;
	//alert("cAlign: " + cAlign + "; nAlign: " + nAlign);
	cOpacity-=.05;
	nOpacity+=.05;

	imgs[nIndex].style.display = 'block';
	imgs[current].xOpacity = cOpacity;
	imgs[nIndex].xOpacity = nOpacity;

	//setAlign(imgs[nIndex]);
	//setAlign(imgs[current]);
	setOpacity(imgs[current]);
	setOpacity(imgs[nIndex]);

	if(cOpacity<=0)
	{
		imgs[current].style.display = 'none';
		current = nIndex;
		setTimeout(so_xfade,3000);
	}
	else
	{
		setTimeout(so_xfade,50);
	}

	function setOpacity(obj)
	{
		if(obj.xOpacity>.99)
		{
			obj.xOpacity = .99;
			return;
		}

		obj.style.opacity = obj.xOpacity;
		obj.style.MozOpacity = obj.xOpacity;
		obj.style.filter = 'alpha(opacity=' + (obj.xOpacity*100) + ')';
	}
}

//    Fine - Nascondiamo lo script ai vecchi browser  -->

