	var arrTrattoDa = new Array("Ponte Ferrovia", "Scomensera", "Rio Novo", "Scalzi", "Cannaregio", "S. Sofia", "Ss. Apostoli", "Rialto", "San Silvestro", "Sant'Angelo", 
								"San Tomà", "Ca' Rezzonico", "Accademia", "Salute");
	var arrTrattoA = new Array("Scomensera", "Rio Novo", "Scalzi", "Cannaregio", "S. Sofia", "Ss. Apostoli", "Rialto", "San Silvestro", "Sant'Angelo", "San Tomà", 
							   "Ca' Rezzonico", "Accademia", "Salute", "Bacino San Marco")
	var curCella;
	var curImmagine = -1;
	var totSecondiFilm = 15;
	var arrayDaCaricare = 0;
	var arrayDaVisualizzare=1;
	var idSC;
	var g_images0 = new Array();
	var g_images1 = new Array();

	switch (window.navigator.appName) {
		case "Microsoft Internet Explorer":
			g_intNavigator 						= 0;
			break;
		case "Netscape":
			g_intNavigator 						= 1;
			break;
		default:
			g_intNavigator 						= 1;
			break;
	}

	function preloadImg() {
			var i;
			var g_images;
			
			
			if( arrayDaCaricare==0 ) {
					g_images=g_images0;
			} else {
					g_images=g_images1;
			}
			for (i=0;i<totSecondiFilm;i++) {
				g_images[i] 		= new Image();
				g_images[i].name	= i;
				g_images[i].width	= 450;
				g_images[i].height	= 150;
				g_images[i].src 	= "video/" + idSC + "/HL_" + i + ".jpg?" + (new Date()).getTime();
			}
			attendi();
		}
		
		function attendi() {
			var g_images;

			if( arrayDaCaricare==0 ) {
					g_images=g_images0;
			} else {
					g_images=g_images1;
			}
			if( g_images[5].complete ) {
				if( curImmagine==0 || curImmagine==-1 ) {
					arrayDaVisualizzare = (arrayDaVisualizzare+1) % 2;
					setTimeout(viewImmagini,0);
				} else {
					setTimeout(attendi,300);
				}
			} else {
			//if( !g_images[9].complete ) {
				setTimeout(attendi,300);
			} 
			
		}

		function xmlStateChange() {
			var oldIdSC;

			if (xmlhttp.readyState==4) {
			// 4 = "loaded"
				if (xmlhttp.status==200) {
				// 200 = "OK"
					//scriviDebug("xmlStateChange");
					xml = xmlhttp.responseXML;
					oldIdSC=idSC;					
					idSC 			= xml.documentElement.attributes[1].nodeValue;
					numNatanti		= xml.documentElement.attributes[2].nodeValue;
					numInfraz		= xml.documentElement.attributes[3].nodeValue;
					sAppo			= new String(xml.documentElement.attributes[4].nodeValue);

					if( oldIdSC!=idSC ) {
						//if( curImmagine==0 ) {
							window.setTimeout(preloadImg, 0);
						//}
					} else {
						//alert(curImmagine);
						if(curImmagine<totSecondiFilm) {
							window.setTimeout(getNumCella, 1050);
						} else {
							window.setTimeout(preloadImg, 1000);
						}
						
						//window.setTimeout(getNumCella, 1050);
					}
					//curImmagine = 0;
					//window.setTimeout(viewImmagini, 4000);
				} else {
					//alert("Problem retrieving XML data:" + xmlhttp.statusText);
					window.setTimeout(getNumCella, 200);
				}
			}
		}
		
		function getNumCella() {
			//scriviDebug("in getNumCella");
			curCella = 0;
			url='video/webXML.xml?'+(new Date()).getTime();
			xmlhttp=null;
			xml=null;
			if (window.XMLHttpRequest) {
				// IE7, Firefox, Opera
				xmlhttp=new XMLHttpRequest();
			}
			else if (window.ActiveXObject) {
				// IE6, IE5
				xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
			}
			if (xmlhttp!=null) {
				xmlhttp.onreadystatechange=xmlStateChange;
				xmlhttp.open("GET", url, true );
				xmlhttp.send(null);
			} else {
				alert("Your browser does not support XMLHTTP.");
			}
		}

		function FadeOutIE(intOpacity) {
			//scriviDebug("FadeOutIE(" + intOpacity + ")");
			intOpacity = intOpacity - 3;

			document.imgCella.style.filter = "alpha(opacity="+intOpacity+")";
			if (intOpacity >= 10) {
				setTimeout("FadeOutIE("+ intOpacity + ")",60);
			} else {
				intOpacity = 0;
				curImmagine=0;
				//window.setTimeout(getNumCella, 0);
			}
		}
		function FadeOutMZ(intOpacity) {
			//scriviDebug("FadeOutMZ(" + intOpacity + ")");
			intOpacity = intOpacity - 3;
			document.imgCella.style.MozOpacity = intOpacity/100;
			if (intOpacity >= 0) {
				setTimeout("FadeOutMZ("+ intOpacity+")",60);
			} else {
				intOpacity = 0;
				curImmagine=0;
				//window.setTimeout(getNumCella, 0);
			}
		}
		function FadeInIE(intOpacity) {
			intOpacity = intOpacity + 3;
			document.imgCella.style.filter = "alpha(opacity="+intOpacity+")";
			if (intOpacity >= 100) {
				intOpacity = 100;
				window.setTimeout(viewImmagini, 500);
			} else {
				setTimeout("FadeInIE("+ intOpacity + ")",60);
			}
		}
		function FadeInMZ(intOpacity) {
			intOpacity = intOpacity + 3;
			document.imgCella.style.MozOpacity = intOpacity/100;
			if (intOpacity >= 100) {
				intOpacity = 100;
				window.setTimeout(viewImmagini, 500);
			} else {
				setTimeout("FadeInMZ("+ intOpacity+")",60);
			}
		}
		

	function viewImmagini() {
		var imgCella;
		var spanTitolo;;
		
		if( curImmagine==-1 ) {
				if (g_intNavigator == 0) {
					document.imgCella.style.filter = "alpha(opacity=0)";
				} else {
					document.imgCella.style.MozOpacity = 0;
				}
				curImmagine=0;
		}
		//scriviDebug("curImmagine=" + curImmagine + " arrayDaCaricare=" + arrayDaCaricare + " arrayDaVisualizzare=" + arrayDaVisualizzare);
		imgCella = document.getElementById("imgCella");
		//imgCella.src = "video/" + idSC + "/HL_" + curImmagine + ".jpg?"+(new Date()).getTime();
		//alert(g_images[curImmagine].src);
		if( arrayDaVisualizzare==0 ) {
				imgCella.src = g_images0[curImmagine].src;
		} else {
				imgCella.src = g_images1[curImmagine].src;
		}
		if( curImmagine==0 ) {
			cellaAttualeDa = arrTrattoDa[idSC-1];
			cellaAttualeA = arrTrattoA[idSC-1];
			superamenti = sAppo.split("|");
			if( superamenti.length != totSecondiFilm ) {
				superamenti = new array(totSecondiFilm);
				for(i=0; i<totSecondiFilm; i++) {
					superamenti[i] = numInfraz;
				}
			}
		}
		spanTitolo = document.getElementById("titolo");
		stx = '';
		if( lang=='' ) {
			stx = "da <strong>" + cellaAttualeDa + "</strong> a <strong>" + cellaAttualeA + "</strong><BR>";
			if( superamenti[curImmagine]==0 ) {
				 stx = stx + "nessun natante ";
			} else {
				stx = stx + "<span style='font-size:1.2em;font-weight:bold;color:#ffcc00;'>" + superamenti[curImmagine] + " natant";
				if( superamenti[curImmagine]==1 ) {
					stx = stx + "e";
				} else {
					stx = stx + "i";
				}
			}
			stx = stx + " oltre il limite di velocit&agrave;";
			if(superamenti[curImmagine]>0) {
				stx = stx + "</span>";
			}
			spanTitolo.innerHTML = stx;
		} else {
			stx = "from <strong>" + cellaAttualeDa + "</strong> to <strong>" + cellaAttualeA + "</strong><BR>";
			if( superamenti[curImmagine]==0 ) {
				 stx = stx + "no boats ";
			} else {
				stx = stx + "<span style='font-size:1.2em;font-weight:bold;color:#ffcc00;'>" + superamenti[curImmagine] + " boat";
				if( superamenti[curImmagine]>1 ) {
					stx = stx + "s";
				}
			}
			stx = stx + " above speed limit";
			if(superamenti[curImmagine]>0) {
				stx = stx + "</span>";
			}
			spanTitolo.innerHTML = stx;
		}
		
		if( curImmagine==0 ) {
			if (g_intNavigator == 0) {
				setTimeout("FadeInIE(0)",100);
			} else {
				setTimeout("FadeInMZ(0)",100);
			}
			curImmagine++;
			return;
		}
		curImmagine++;
		if(curImmagine<totSecondiFilm) {
			window.setTimeout(viewImmagini, 1100);
			if( curImmagine==Math.round(totSecondiFilm/2,0) ) {
				arrayDaCaricare = (arrayDaCaricare+1) % 2;
				window.setTimeout(getNumCella, 0);
			}
		} else {
			//curImmagine=0;
			//scriviDebug("parto col fadeout");
			if (g_intNavigator == 0) {
				FadeOutIE(100);
			} else {
				FadeOutMZ(100);
			}
			//scriviDebug("metto curImmagine=0");
			//window.setTimeout(getNumCella, 1000);
		}
	}
	
	function load() {
		window.setTimeout(getNumCella, 0);		
	}
	
	function scriviDebug(stringa) {
		var testoDebug;
		testoDebug = document.getElementById("debug");
		testoDebug.innerHTML = stringa + "<BR>" + testoDebug.innerHTML;
		if( testoDebug.innerHTML.length>500 )  {
				testoDebug.innerHTML = testoDebug.innerHTML.substring(0,500);
		}
		
	}

