
		
    var map;
    var GOverviewMap;
    var ovmap;
    var trafficInfo=new Array();
    var trafficMarkers=new Array();
    var infoFocus=-1;
    var index;
    var default_zoom_level=12;
    //var italia_zoom_level=5;
    var italia_zoom_level=6;
    var italia_center_lat=41.677015;
    var italia_center_lng=12.135773;
    var max_zoom=5;
    // var max_zoom_eventi=10;
    var max_zoom_eventi=5;
    //
    var max_zoom_percorsi=9
    
    var zoom_out=0;
    var percorsoPolyline;
    //var persorso;
    var percorso;
    var query;

    var gLargeMapControl; 
    var gMapTypeControl;
    var gOverviewMapControl; 

    
    
    var lat;
	var lng;
    
    var latNE;
    var lngNE;
    var latSW;
    var lngSW;
    
    var times=0;
    
    var relPath="";
    
    var trafficPolylines;
    var statusCoda =-1;
    var statusCantiere =-1;
    var statusWebcam =-1;
    var toggleState = -1;
    var toggleWebcamStatus = 0;
    var directionsPanel;
    //var directions;
    var directions2;
    var head;
    var head2;
    var mWebcam;
    
    var tipiDiIcone= "-ABL-ACC-ACT-AIC-AIR-ANH-APL-AQD-AVL-BKD-BRB-BSI-CAC-CAL-CD1-CD2-CD3-CD4-CHI-CLS-COO-CTR-CYC-DDS-DIV-DO-EAM-EBA-ECR-ECY-EGT-EIS-EMT-EMV-END-EQU-ETT-EWT-EXH-EXS-FIG-FLD-FOD-FOP-FOS-FPR-FSN-GAS-GIU-GOO-GP-HAZ-HBD-HLT-IBU-INC-LAP-LB1-LB2-LBC-LBD-LBE-LBL-LBT-LBV-LCW-LLT-LO1-LO2-LOS-MHZ-NCL-OBR-OCL-OCM-OHZ-OMV-OSI-PEO-PAR-PRA-PRE-PRV-PSS-PTV-RAF-RAH-RBX-RCE-RES-RES1-RET-RIM-RMT-ROU-RPC-RSR-RWR-SAB-SAT-SHZ-SM-SN-SNE-SNO-SPC-SR-SRC-SUN-TLI-TUB-USI-VFR-VIR-WHI-WIN-";

	

		function toggleCoda()
		{
			if (statusCoda==-1)
			{			   
			   directions = new GDirections();
			   //directions2 = new GDirections();
			   
			   GEvent.addListener(directions, "load", onGDirectionsLoad); 
			   //GEvent.addListener(directions2, "load", onGDirectionsLoad2); 
			   
			   var query="from:"+coda.beginLat+","+coda.beginLng+" to: "+coda.endLat+","+coda.endLng;
			   //var query2="from:"+coda2.beginLat+","+coda2.beginLng+" to: "+coda2.endLat+","+coda2.endLng;
			   
			   directions.load(query,{preserveViewport:true, getPolyline:true, locale: 'it_IT'});
			   //directions2.load(query2,{preserveViewport:true, getPolyline:true});
			   
			   statusCoda=1;
			}
			else if (statusCoda==1)
			{
				statusCoda=0;
				directions.getPolyline().hide();
				head.hide();
				//directions2.getPolyline().hide();
				//head2.hide();

			}
			else
			{
				statusCoda=1;
				directions.getPolyline().show();
				head.show();

				//directions2.getPolyline().show();
				//head2.show();
			}

		}

		function toggleCantiere()
		{
			if (statusCantiere==-1)
			{			   
			   
			   directions2 = new GDirections();
			   
			   
			   GEvent.addListener(directions2, "load", onGDirectionsLoad2); 
			   
			   
			   var query2="from:"+coda2.beginLat+","+coda2.beginLng+" to: "+coda2.endLat+","+coda2.endLng;
			   
			   
			   directions2.load(query2,{preserveViewport:true, getPolyline:true, locale: 'it_IT'});
			   
			   statusCantiere=1;
			}
			else if (statusCantiere==1)
			{
				statusCantiere=0;
				directions2.getPolyline().hide();
				head2.hide();

			}
			else
			{
				statusCantiere=1;

				directions2.getPolyline().show();
				head2.show();
			}

	}

function showWebcam(lat,lng, indirizzo, citta)
{
statusWebcam=-1;
webcam.lat=lat;
webcam.lng=lng;
initializeMap(lat, lng, -1);
toggleWebcam();
if (!(document.getElementById("indirizzo")===undefined))
	{ document.getElementById("indirizzo").value=indirizzo; }

if (!(document.getElementById("citta")===undefined))
	{ document.getElementById("citta").value=citta; }

}



	  function onGDirectionsLoad() 
	  { 
           var polyline = directions.getPolyline(); 
           polyline.setStrokeStyle({color:"#0000C0",weight:8,opacity: 0.5}); 
                      
           
           var iconLIC = new GIcon(); 
        	 iconLIC.image = relPath+"images/gmaps/lavori_in_corso.gif"; 
            
           iconLIC.iconAnchor = new GPoint(15, 13); 
           iconLIC.infoWindowAnchor = new GPoint(15, 0); 
           iconLIC.iconSize = new GSize(30, 26); 
           //icon.shadow = "images/"  + IMAGES[i] + "-shadow.png"; 
           //icon.shadowSize = new GSize(59, 32); 
           
           head = new GMarker(polyline.getVertex(0), { icon: iconLIC });
           GEvent.addListener(head, "mouseover", function() {map.closeInfoWindow(); head.openInfoWindowHtml("2008-11-20 9:34<br/>Rallentamenti per lavori di rifacimento del manto stradale");}); 
           GEvent.addListener(head, "mouseout", function() {map.closeInfoWindow();}); 

        
           map.addOverlay(polyline); 
           map.addOverlay(head); 
    } 


	  function onGDirectionsLoad2() 
	  { 
           var polyline2 = directions2.getPolyline(); 
           polyline2.setStrokeStyle({color:"#ff0000",weight:12,opacity: 0.7}); 
                      
           
           var iconLIC = new GIcon(); 
        	 iconLIC.image = relPath+"images/gmaps/incidente.gif"; 
            
           iconLIC.iconAnchor = new GPoint(15, 15); 
           iconLIC.infoWindowAnchor = new GPoint(15, 0); 
           iconLIC.iconSize = new GSize(30, 30); 
           //icon.shadow = "images/"  + IMAGES[i] + "-shadow.png"; 
           //icon.shadowSize = new GSize(59, 32); 
           
           head2 = new GMarker(polyline2.getVertex(0), { icon: iconLIC });
           GEvent.addListener(head2, "mouseover", function() {map.closeInfoWindow(); head2.openInfoWindowHtml("2008-11-21 12:34<br/>Code per incidente");}); 
           GEvent.addListener(head2, "mouseout", function() {map.closeInfoWindow();}); 

        
           map.addOverlay(polyline2); 
           map.addOverlay(head2); 
    } 


	function setAbsPath()
	{
		var iPos = "";
		
		var foo = window.location.href;
		var bar = foo.split("/");
		
		// ciclo in modo da prendere: protocollo//host/appname
		for(var i = 0;i<4;i++)
		{
			iPos=iPos+bar[i]+"/";
		}
		relPath=iPos;
	}

    function initializeMap(lat, lng, i) 
    {
      //alert("initializeMap");
	  setAbsPath();
      
      if (GBrowserIsCompatible()) 
      {
        map = new GMap2(document.getElementById("map_canvas")); 
        
        latlng= new GLatLng(lat,lng);   
        center = new GMarker(latlng);
             
        map.setCenter(new GLatLng(lat,lng), 16);
        
        
        
        if (lat!=italia_center_lat)
        {        	
        	map.setZoom(default_zoom_level);

        	map.addControl(new GLargeMapControl()); 
        	map.addControl(new GMapTypeControl());
        	map.addControl(new GOverviewMapControl(new GSize(120,96)));
        	
        	 
        }
        else
        {
        	map.setZoom(italia_zoom_level);

        	map.addControl(new GLargeMapControl()); 
        	map.addControl(new GMapTypeControl());
 			document.getElementById("check_webcam").style.visibility="hidden";
			document.getElementById("testoNetcam").innerHTML="<span  class=\"bea-portal-body-header-font\">Per il livello di zoom selezionato non &egrave possibile visualizzare le netcam.<br/></span>";       	

        }
        
        
	    setMapBoundBox();
	    enableLiveLoading();

		if (lat!=italia_center_lat)
		{	
			//init_webcam(map); 
			//init_sensori(map);
		}

	    
	    if (i!==undefined && i!==null)
	    {
	    	getEventiIndirizzo(i);
	    }
	    else
	    {
			getEventi();
		}
		
		
			
			
		zoom_out=0;
		webcamMarkerArray=new Array();
		sensoriMarkerArray=new Array();
		
       /* } */
       
       
        /*
        //alert(i);
        if (i!=-1)
        {
        		map.addOverlay(center);
		        var objResult= jsResults[i];
		        var infoHtml="<span class=\"cciss-home-news cciss-home-news-titolo\">"+objResult.stradaTO.descrizioneStrada+" - "+objResult.cittaTO.name+"<br/><br/>";
		        if (id_preferito==='') 
		        {
		        
		        	objResult.stradaTO.descrizioneStrada=objResult.stradaTO.descrizioneStrada.split("'").join("\'");
		        	objResult.stradaTO.name=objResult.stradaTO.name.split("'").join("\'");
		        	objResult.cittaTO.name=objResult.cittaTO.name.split("'").join("\'");
		        
		        	infoHtml=infoHtml+"<div id=\"div_popup_salva\" class=\"cciss-home-news cciss-home-news-link\"><a href=\"javascript:salvaPreferito('"+objResult.stradaTO.descrizioneStrada+"','"+objResult.stradaTO.name+"','"+objResult.numeroCivico+"','"+objResult.cittaTO.name+"','"+objResult.coordinateMappaTO.coordinateMappaCY+"','"+objResult.coordinateMappaTO.coordinateMappaCX+"','div_popup_salva','1');\">Aggiungi ai preferiti</a></div>";
		        }
		        else
		        {
		        	infoHtml=infoHtml+"<div id=\"div_popup_rimuovi\" class=\"cciss-home-news cciss-home-news-link\"><a href=\"javascript:rimuoviPreferito('"+id_preferito+"','div_popup_rimuovi');\">Rimuovi dai preferiti</a></div>";
		        }
		        center.openInfoWindowHtml(infoHtml);
		        //setMapBoundBox();
		        //getEventi();
		        //enableLiveLoading(); 
        }
        */
            
      }
    }
    
    
    function visualizzaCallOutIndirizzo(i)
    {
    	if (!(i===undefined || i===null))
    	{
    		
	        if (i!=-1)
	        {
	        		map.addOverlay(center);
			        var objResult= jsResults[i];
					var infoHtml="";
					if (objResult.stradaTO.descrizioneStrada===null || objResult.stradaTO.descrizioneStrada==='')
					{
						infoHtml="<span class=\"cciss-home-news cciss-home-news-titolo\">"+objResult.cittaTO.name+", "+objResult.cittaTO.provinciaTO.code +" - "+ objResult.regione.name+"<br/><br/>";
					}
					else
					{
						infoHtml="<span class=\"cciss-home-news cciss-home-news-titolo\">"+objResult.stradaTO.descrizioneStrada+" - "+objResult.cittaTO.name+"<br/><br/>";
					}		       
//var infoHtml="<span class=\"cciss-home-news cciss-home-news-titolo\">"+objResult.cittaTO.name+" - "+objResult.cittaTO.provinciaTO.code +" - "+ objResult.regione.name"<br/><br/>";
			       
			        
			        if (id_preferito==='') 
			        {
			        
			        	objResult.stradaTO.descrizioneStrada=objResult.stradaTO.descrizioneStrada.split("'").join("\'");
			        	objResult.stradaTO.name=objResult.stradaTO.name.split("'").join("\'");
			        	objResult.cittaTO.name=objResult.cittaTO.name.split("'").join("\'");
			        
			        	infoHtml=infoHtml+"<div id=\"div_popup_salva\" class=\"cciss-home-news cciss-home-news-link\"><a href=\"javascript:salvaPreferito('"+objResult.stradaTO.descrizioneStrada+"','"+objResult.stradaTO.name+"','"+objResult.numeroCivico+"','"+objResult.cittaTO.name+"','"+objResult.coordinateMappaTO.coordinateMappaCY+"','"+objResult.coordinateMappaTO.coordinateMappaCX+"','div_popup_salva','1');\">Aggiungi ai preferiti</a></div>";
			        }
			        else
			        {
			        	infoHtml=infoHtml+"<div id=\"div_popup_rimuovi\" class=\"cciss-home-news cciss-home-news-link\"><a href=\"javascript:rimuoviPreferito('"+id_preferito+"','div_popup_rimuovi',1);\">Rimuovi dai preferiti</a></div>";
			        }
			        center.openInfoWindowHtml(infoHtml);
			        //setMapBoundBox();
			        //getEventi();
			        //enableLiveLoading(); 
	        }
		}    
    }
    
    
    
    function setMapBoundBox()
    {
    	//alert("sono dentro setMapBoundBox() ");
    	var localBB = map.getBounds();
		var localLatNE=localBB.getNorthEast().lat();
		var localLngNE=localBB.getNorthEast().lng();
		var localLatSW=localBB.getSouthWest().lat();
		var localLngSW=localBB.getSouthWest().lng();
		
		latNE = localLatNE+(localLatNE-localLatSW)*times;
		latSW = localLatSW-(localLatNE-localLatSW)*times;

		lngNE = localLngNE+(localLngNE-localLngSW)*times;
		lngSW = localLngSW-(localLngNE-localLngSW)*times;    
    }
    
	function getEventi()
	{ 	
		//alert("getEventi();");
		var testoEventi= '<span  class=\"cciss-home-news cciss-home-news-titolo\">Caricamento in corso...<br/></span>';
                                    
        var divEventi=document.getElementById("testoEventi");
        if (!((divEventi===undefined) ||(divEventi===null)))
        {
        	document.getElementById("testoEventi").innerHTML=testoEventi;
        }
        
		var zoom_level=map.getZoom();
		if (zoom_level<max_zoom)
		{
			map.setZoom(max_zoom);
			zoom_out=1;
		}
		
		 
		
		if (zoom_level<max_zoom_eventi)
		{
			map.clearOverlays();
			
			
			if (percorsoPolyline!==undefined && percorsoPolyline!==null)
			{
				map.addOverlay(percorsoPolyline);
			}
			
			if (percorso!==undefined && percorso!==null && query!==null && query!==undefined)
			{
				    if (document.getElementById("check_autostrade").checked) 
	        		{
	           			percorso.load(query,{preserveViewport:true, getPolyline:true, locale: 'it_IT',avoidHighways:true});
	        		}
				   	else
				   	{	   
				   		percorso.load(query,{preserveViewport:true, getPolyline:true, locale: 'it_IT'});
				   	}
			}
			
			trafficInfo=new Array();
			trafficMarkers= new Array();
			testoEventi= '<span  class=\"cciss-home-news cciss-home-news-titolo\">Livello di zoom troppo elevato per visualizzare eventi di traffico.<br/></span>';
                                    
                                    
            divEventi=document.getElementById("testoEventi");
        	if (!((divEventi===undefined) ||(divEventi===null)))
        	{
        		document.getElementById("testoEventi").innerHTML=testoEventi;
        	}
			
		}
		else
		{
			
			setMapBoundBox();
			trafficInfo=new Array();
			trafficMarkers= new Array();
			
				
			var upperLat=latNE;
			var upperLng=lngNE;
			var lowerLat=latSW;
			var lowerLng=lngSW;
			var zoomLevel=zoom_level
			//alert("("+upperLat+";"+upperLng+")-("+lowerLat+";"+lowerLng+")");
			
               var dataUrl = relPath+'ajax/RetrieveEventsServlet?upperLat='+upperLat+'&upperLng='+upperLng+'&lowerLat='+lowerLat+'&lowerLng='+lowerLng+'&zoomLevel='+zoomLevel;
               
               //alert(dataUrl);
                 
                var xmlhttp = new bea.wlp.disc.io.XMLHttpRequest(); 
                if (xmlhttp.readyState === 4 || xmlhttp.readyState === 0)
                { 
                        xmlhttp.open('GET', dataUrl, true); 
                        
                        xmlhttp.onreadystatechange = function() { 
                                if (xmlhttp.readyState == 4)
                                {                                 	
                                    var data = eval('(' + xmlhttp.responseText + ')');
                                    
                                    trafficInfo=data;
                                   
									map.clearOverlays();
									if (percorsoPolyline!=null)
									{
										map.addOverlay(percorsoPolyline);
									}
									
									// M netcam
									if ((zoomLevel>10))
									{
									    webcamMarkerArray=new Array();
									    init_webcam(map);								
										if (document.getElementById("check_webcam").checked==false)
										{										
											for (i=0; i<webcamMarkerArray.length;i++)
                                                {
   												 webcamMarkerArray[i].hide();
                                                }
			                                status_webcam=0;        	
										}
									}
									else
									{
 									   document.getElementById("check_webcam").style.visibility="hidden";
									   document.getElementById("testoNetcam").innerHTML="<span  class=\"bea-portal-body-header-font\">Per il livello di zoom selezionato non &egrave possibile visualizzare le netcam.<br/></span>";
									}
									// M netcam
									
									if (percorso!=null && query!=null)
									{
										    if (document.getElementById("check_autostrade").checked) 
							        		{
							           			percorso.load(query,{preserveViewport:true, getPolyline:true, locale: 'it_IT',avoidHighways:true});
							        		}
										   	else
										   	{	   
										   		percorso.load(query,{preserveViewport:true, getPolyline:true, locale: 'it_IT'});
										   	}
									}
									


									//trafficMarkers= new Array(data.length);
		      						//alert("eventi da Ajax su bound box: "+data.length);
		      						
		      						//map.clearOverlays();
		      						
		      							      						
		      						//for (i=0;i<data.length;i++)
								    //{
								    //	showCoda(data[i].percorsoTO.coordinateMappaInizioTO, data[i].percorsoTO.coordinateMappaFineTO,i);
								    //}
		      						/*
		      						testoEventi= '<span  class=\"cciss-home-news cciss-home-news-titolo\">Caricamento in corso...<br/></span>';
                                    
                                    
                                    
                                    divEventi=document.getElementById("testoEventi");
                                    if (!((divEventi==undefined) ||(divEventi==null)))
                                    {
                                    	document.getElementById("testoEventi").innerHTML=testoEventi;
                                    }
                                    */
                                    
                                    testoEventi=getTestoEventi();
                                    if (!((divEventi==undefined) ||(divEventi==null)))
                                    {
                                    	document.getElementById("testoEventi").innerHTML=testoEventi;
                                    }
                                    
                                }
                        };
                        xmlhttp.send(null);
                        
                }    
    	}
    }    
    


	function getEventiIndirizzo(i)
	{ 	
		//alert("getEventiIndirizzo();");
		var testoEventi= '<span  class=\"cciss-home-news cciss-home-news-titolo\">Caricamento in corso...<br/></span>';
                                    
        var divEventi=document.getElementById("testoEventi");
        if (!((divEventi===undefined) ||(divEventi===null)))
        {
        	document.getElementById("testoEventi").innerHTML=testoEventi;
        }
        
		var zoom_level=map.getZoom();
		if (zoom_level<max_zoom)
		{
			map.setZoom(max_zoom);
			zoom_out=1;
		}
		
		 
		
		if (zoom_level<max_zoom_eventi)
		{
			map.clearOverlays();
			
			
			if (percorsoPolyline!==undefined && percorsoPolyline!==null)
			{
				map.addOverlay(percorsoPolyline);
			}
			
			
			
			if (percorso!==undefined && percorso!==null && query!==null && query!==undefined)
			{
				    if (document.getElementById("check_autostrade").checked) 
	        		{
	           			percorso.load(query,{preserveViewport:true, getPolyline:true, locale: 'it_IT',avoidHighways:true});
	        		}
				   	else
				   	{	   
				   		percorso.load(query,{preserveViewport:true, getPolyline:true, locale: 'it_IT'});
				   	}
			}
			
			trafficInfo=new Array();
			trafficMarkers= new Array();
			testoEventi= '<span  class=\"cciss-home-news cciss-home-news-titolo\">Livello di zoom troppo elevato per visualizzare eventi di traffico.<br/></span>';
                                    
                                    
            divEventi=document.getElementById("testoEventi");
        	if (!((divEventi===undefined) ||(divEventi===null)))
        	{
        		document.getElementById("testoEventi").innerHTML=testoEventi;
        	}
			
			
			
		}
		else
		{
			
			setMapBoundBox();
			trafficInfo=new Array();
			trafficMarkers= new Array();
			//alert(trafficInfo);
				var upperLat=latNE;
				var upperLng=lngNE;
				var lowerLat=latSW;
				var lowerLng=lngSW;
				var zoomLevel=zoom_level;
				//alert("("+upperLat+";"+upperLng+")-("+lowerLat+";"+lowerLng+")");
				
                var dataUrl = relPath+'ajax/RetrieveEventsServlet?upperLat='+upperLat+'&upperLng='+upperLng+'&lowerLat='+lowerLat+'&lowerLng='+lowerLng+'&zoomLevel='+zoomLevel;
                
                //alert(dataUrl);
                 
                var xmlhttp = new bea.wlp.disc.io.XMLHttpRequest(); 
                if (xmlhttp.readyState === 4 || xmlhttp.readyState === 0)
                { 
                        xmlhttp.open('GET', dataUrl, true); 
                        
                        xmlhttp.onreadystatechange = function() { 
                                if (xmlhttp.readyState == 4)
                                {                                 	
                                    var data = eval('(' + xmlhttp.responseText + ')');
                                    
                                    trafficInfo=data;
                                   
									map.clearOverlays();
									if (percorsoPolyline!==undefined && percorsoPolyline!=null)
									{
										map.addOverlay(percorsoPolyline);
									}
									
									// M netcam
									if ((zoomLevel>10))
									{
									    webcamMarkerArray=new Array();
									    init_webcam(map);								
										if (document.getElementById("check_webcam").checked==false)
										{										
											for (i=0; i<webcamMarkerArray.length;i++)
                                                {
   												 webcamMarkerArray[i].hide();
                                                }
			                                status_webcam=0;        	
										}
									}
									else
									{
 									   document.getElementById("check_webcam").style.visibility="hidden";
									   document.getElementById("testoNetcam").innerHTML="<span  class=\"bea-portal-body-header-font\">Per il livello di zoom selezionato non &egrave possibile visualizzare le netcam.<br/></span>";
									}
									// M netcam
									
									//alert(trafficInfo);
									if (percorso!=null && query!=null && percorso!=undefined && query!=undefined)
									{
										    if (document.getElementById("check_autostrade").checked) 
							        		{
							           			percorso.load(query,{preserveViewport:true, getPolyline:true, locale: 'it_IT',avoidHighways:true});
							        		}
										   	else
										   	{	   
										   		percorso.load(query,{preserveViewport:true, getPolyline:true, locale: 'it_IT'});
										   	}
									}
									


									//trafficMarkers= new Array(data.length);
		      						//alert("eventi da Ajax su bound box: "+data.length);
		      						
		      						//map.clearOverlays();
		      						
		      							      						
		      						//for (i=0;i<data.length;i++)
								    //{
								    //	showCoda(data[i].percorsoTO.coordinateMappaInizioTO, data[i].percorsoTO.coordinateMappaFineTO,i);
								    //}
		      						/*
		      						testoEventi= '<span  class=\"cciss-home-news cciss-home-news-titolo\">Caricamento in corso...<br/></span>';
                                    
                                    
                                    
                                    divEventi=document.getElementById("testoEventi");
                                    if (!((divEventi==undefined) ||(divEventi==null)))
                                    {
                                    	document.getElementById("testoEventi").innerHTML=testoEventi;
                                    }
                                    */
                                    
                                    testoEventi=getTestoEventi();
                                    if (!((divEventi==undefined) ||(divEventi==null)))
                                    {
                                    	document.getElementById("testoEventi").innerHTML=testoEventi;
                                    }
                                    
                                }
                                visualizzaCallOutIndirizzo(i);
                        };
                        xmlhttp.send(null); 
                }    
                
    	}
    }    


  /*  
    function enableLiveLoading() {
	moveend = GEvent.bind(map, "moveend", this, function() {
	
		var zoom_level=map.getZoom();
		if (zoom_level<max_zoom)
		{
			map.setZoom(max_zoom);
			zoom_out=1;
		}
		
		//alert(zoom_level);
			
			
		var currentBB = map.getBounds();
		var NEpoint= new GLatLng(latNE,lngNE);
		var SWpoint= new GLatLng(latSW,lngSW);
		
		var globalBB= new GLatLngBounds(SWpoint,NEpoint);
		if (globalBB.containsBounds(currentBB))
		{
			//alert("sono dentro");
			if (zoom_out==1 && zoom_level>max_zoom_eventi)
			{
				zoom_out=0;
				setMapBoundBox();
				map.clearOverlays();
				trafficInfo=new Array();
				trafficMarkers= new Array();
				getEventi();			
			}
			else
			{
				if (zoom_out==0)
				{
					var testoEventi;
        			testoEventi=getTestoEventi();
        			document.getElementById("testoEventi").innerHTML=testoEventi;
				}
			
			}
			
		}
		else
		{
			//alert("sono fuori");
			
			
						
			if (zoom_level<max_zoom_eventi)
			{				
				//avvertire che non il livello di zoom supera quello consentito per la visualizzazione degli eventi
				zoom_out=1;
				map.clearOverlays();
				trafficInfo=new Array();
				var testoEventi;
        		testoEventi=getTestoEventi();
        		document.getElementById("testoEventi").innerHTML=testoEventi;
				trafficMarkers= new Array();
				
			
				
				
				
			}
			else
			{
				//alert("carico eventi");
				setMapBoundBox();
				map.clearOverlays();
				trafficInfo=new Array();
				trafficMarkers= new Array();
				getEventi();
				
				
			}
		}
		
		 
        //setMapBoundBox();
	});
} */

    function enableLiveLoading() {
    
    	if (ovmap!==null && ovmap!==undefined)
    	{
    	dragovend = GEvent.bind(ovmap, "dragend", this, function() {
	
		var testoEventi= '<span  class=\"cciss-home-news cciss-home-news-titolo\">Caricamento in corso...<br/></span>';
                                    
                                    
                                    
        var divEventi=document.getElementById("testoEventi");
        if (!((divEventi===undefined) ||(divEventi===null)))
        {
        	document.getElementById("testoEventi").innerHTML=testoEventi;
        }
        
		var zoom_level=map.getZoom();
		if (zoom_level<max_zoom)
		{
			map.setZoom(max_zoom);
			zoom_out=1;
			zoom_level=max_zoom;
		}
		
		if (zoom_level<max_zoom_eventi)
		{
			map.clearOverlays();
			if (percorsoPolyline!==undefined && percorsoPolyline!==null)
			{
				map.addOverlay(percorsoPolyline);
			}
			
			if (percorso!==undefined && percorso!==null && query!==null && query!==undefined)
			{
				    if (document.getElementById("check_autostrade").checked) 
	        		{
	           			percorso.load(query,{preserveViewport:true, getPolyline:true, locale: 'it_IT',avoidHighways:true});
	        		}
				   	else
				   	{	   
				   		percorso.load(query,{preserveViewport:true, getPolyline:true, locale: 'it_IT'});
				   	}
			}
			
			trafficInfo=new Array();
			trafficMarkers= new Array();
			testoEventi= '<span  class=\"cciss-home-news cciss-home-news-titolo\">Livello di zoom troppo elevato per visualizzare eventi di traffico.<br/></span>';
                                    
                                    
                                    
        	divEventi=document.getElementById("testoEventi");
        	if (!((divEventi===undefined) ||(divEventi===null)))
        	{
        		document.getElementById("testoEventi").innerHTML=testoEventi;
        	}
			
		}
		else
		{
			
			setMapBoundBox();
			trafficInfo=new Array();
			trafficMarkers= new Array();
			getEventi();
			
		
		}
		
	});
    }
    
    
    
	moveend = GEvent.bind(map, "dragend", this, function() {
	
		var testoEventi= '<span  class=\"cciss-home-news cciss-home-news-titolo\">Caricamento in corso...<br/></span>';
                                    
                                    
                                    
        var divEventi=document.getElementById("testoEventi");
        if (!((divEventi===undefined) ||(divEventi===null)))
        {
        	document.getElementById("testoEventi").innerHTML=testoEventi;
        }
        
		var zoom_level=map.getZoom();
		if (zoom_level<max_zoom)
		{
			map.setZoom(max_zoom);
			zoom_out=1;
			zoom_level=max_zoom;
		}
		
		if (zoom_level<max_zoom_eventi)
		{
			map.clearOverlays();
			if (percorsoPolyline!==undefined && percorsoPolyline!==null)
			{
				map.addOverlay(percorsoPolyline);
			}
			
			if (percorso!==undefined && percorso!==null && query!==null && query!==undefined)
			{
				    if (document.getElementById("check_autostrade").checked) 
	        		{
	           			percorso.load(query,{preserveViewport:true, getPolyline:true, locale: 'it_IT',avoidHighways:true});
	        		}
				   	else
				   	{	   
				   		percorso.load(query,{preserveViewport:true, getPolyline:true, locale: 'it_IT'});
				   	}
			}
			
			trafficInfo=new Array();
			trafficMarkers= new Array();
			testoEventi= '<span  class=\"cciss-home-news cciss-home-news-titolo\">Livello di zoom troppo elevato per visualizzare eventi di traffico.<br/></span>';
                                    
                                    
                                    
        	divEventi=document.getElementById("testoEventi");
        	if (!((divEventi===undefined) ||(divEventi===null)))
        	{
        		document.getElementById("testoEventi").innerHTML=testoEventi;
        	}
			
		}
		else
		{
			
			setMapBoundBox();
			trafficInfo=new Array();
			trafficMarkers= new Array();
			getEventi();
			
		
		}
			
		
		//setTimeout("checkOverview()",100);
		 
        //setMapBoundBox();
	});
	
	
	dblclick = GEvent.bind(map, "dblclick", this, function() {
	
		var testoEventi= '<span  class=\"cciss-home-news cciss-home-news-titolo\">Caricamento in corso...<br/></span>';
                                    
                                    
                                    
        var divEventi=document.getElementById("testoEventi");
        if (!((divEventi==undefined) ||(divEventi==null)))
        {
        	document.getElementById("testoEventi").innerHTML=testoEventi;
        }
        
		var zoom_level=map.getZoom();
		if (zoom_level<max_zoom)
		{
			map.setZoom(max_zoom);
			zoom_out=1;
			zoom_level=max_zoom;
		}
		
		if (zoom_level<max_zoom_eventi)
		{
			map.clearOverlays();
			if (percorsoPolyline!==undefined && percorsoPolyline!==null)
			{
				map.addOverlay(percorsoPolyline);
			}
			
			if (percorso!==undefined && percorso!==null && query!==null && query!==undefined)
			{
				    if (document.getElementById("check_autostrade").checked) 
	        		{
	           			percorso.load(query,{preserveViewport:true, getPolyline:true, locale: 'it_IT',avoidHighways:true});
	        		}
				   	else
				   	{	   
				   		percorso.load(query,{preserveViewport:true, getPolyline:true, locale: 'it_IT'});
				   	}
			}
			trafficInfo=new Array();
			trafficMarkers= new Array();
			testoEventi= '<span  class=\"cciss-home-news cciss-home-news-titolo\">Livello di zoom troppo elevato per visualizzare eventi di traffico.<br/></span>';
                                    
                                    
                                    
        	divEventi=document.getElementById("testoEventi");
        	if (!((divEventi===undefined) ||(divEventi===null)))
        	{
        		document.getElementById("testoEventi").innerHTML=testoEventi;
        	}
			
		}
		else
		{
			
			setMapBoundBox();
			trafficInfo=new Array();
			trafficMarkers= new Array();
			getEventi();
			
		
		}
			
		
		//setTimeout("checkOverview()",100);
		 
        //setMapBoundBox();
	});

	zoomend = GEvent.bind(map, "zoomend", this, function() {
	
		var testoEventi= '<span  class=\"cciss-home-news cciss-home-news-titolo\">Caricamento in corso...<br/></span>';
                                    
                                    
                                    
        var divEventi=document.getElementById("testoEventi");
        if (!((divEventi==undefined) ||(divEventi==null)))
        {
        	document.getElementById("testoEventi").innerHTML=testoEventi;
        }
        
		var zoom_level=map.getZoom();
		if (zoom_level<max_zoom)
		{
			map.setZoom(max_zoom);
			zoom_out=1;
			zoom_level=max_zoom;
		}
		
		if (zoom_level<max_zoom_eventi)
			{
				map.clearOverlays();
				if (percorsoPolyline!==null && percorsoPolyline!==undefined)
				{
					map.addOverlay(percorsoPolyline);
				}
				trafficInfo=new Array();
				trafficMarkers= new Array();
				var testoEventi= '<span  class=\"cciss-home-news cciss-home-news-titolo\">Livello di zoom troppo elevato per visualizzare eventi di traffico.<br/></span>';
	                                    
	                                    
	                                    
	        	var divEventi=document.getElementById("testoEventi");
	        	if (!((divEventi==undefined) ||(divEventi==null)))
	        	{
	        		document.getElementById("testoEventi").innerHTML=testoEventi;
	        	}
				
			}
		else
			{
				setMapBoundBox();
				trafficInfo=new Array();
				trafficMarkers= new Array();
				getEventi();
				
			
			}
				
		
		//setTimeout("checkOverview()",100);
		 
        //setMapBoundBox();
	});

	
	var testoEventi;
    testoEventi=getTestoEventi();
    document.getElementById("testoEventi").innerHTML=testoEventi;
}
    
    	function getTestoEventi()
    	{
    		//alert("getTestoEventi");
    		var testoEventi='';
    		var count=0;
    		var bounds=map.getBounds();
    		trafficMarkers=new Array();
   		
    		
    		//for (i=0;i<trafficInfo.length;i++){
    		//mod carica eventi in ordine inverso 
    		for (i=trafficInfo.length-1;i>=0;i--){
		    	var _lat=trafficInfo[i].percorsoTO.coordinateMappaInizioTO.coordinateMappaCY;
		    	var _lng=trafficInfo[i].percorsoTO.coordinateMappaInizioTO.coordinateMappaCX;
		    	var headCoda=new GLatLng(_lat,_lng);
						    	
		    	
		    	if (bounds.containsLatLng(headCoda))
		    	{
		    		var styleDiv;
		    		if (infoFocus==i)
		    		{
		    			styleDiv='inline';
		    		}
		    		else
		    		{
		    			styleDiv='none';
		    		}
		    		
		    		
		    		if (relPath=="")
					{
						setAbsPath();
					}
	
	
	  				var tipoIcona="default";
               
               
    				if (trafficInfo[i].codiceImmagine!=null)
	  				{
	  					if (tipiDiIcone.indexOf(trafficInfo[i].codiceImmagine)!=-1)
	   						{ tipoIcona=trafficInfo[i].codiceImmagine; }
	  				}
		    		
		    		
		    		//testoEventi+='- <b><a href=\"javascript:focusOnNews('+i+');\"><span class=\"cciss-home-news cciss-home-news-link\">'+trafficInfo[i].evento+'</span></a></b><br/><div id=\"evento_'+i+'\" style=\"display : '+styleDiv+';\"><span class=\"cciss-generic-font cciss-home-news-titolo-light\">'+trafficInfo[i].dataPubblicazione+'</span><br/><span  class=\"cciss-home-news cciss-home-news-dettaglio\">'+trafficInfo[i].dettaglio+'</span><br/></div><br/>';
		    		//testoEventi+='<span class="cciss-generic-font cciss-home-news-titolo-light">'+trafficInfo[i].dataPubblicazione+'</span><br/><a href=\"javascript:focusOnNews('+i+');\"><span class=\"cciss-home-news cciss-home-news-link\">'+trafficInfo[i].evento+'</span></a><br/><div id=\"evento_'+i+'\" style=\"display : '+styleDiv+';\"><span  class=\"cciss-home-news cciss-home-news-dettaglio\">'+trafficInfo[i].dettaglio+'</span><br/></div><br/>';

					//max Priorita Pallino
		    		//testoEventi+='<table cellspacing=\"0\" cellpadding=\"0\" border=\"0\" width=\"200\"><tr><td width=\"30\"><img src=\"'+relPath+'images/gmaps/'+tipoIcona+'.gif\" border="0"/></td><td width=\"6\"></td><td width=\"164\" valign=\"middle\"><span class=\"cciss-generic-font cciss-home-news-titolo-light\">'+trafficInfo[i].dataPubblicazione+'</span><br/><span class=\"cciss-home-news cciss-home-news-link\"><a href=\"javascript:focusOnNews('+i+');\">'+trafficInfo[i].titolo+'</a></span></td></tr><tr><td colspan=\"3\" width=\"200\"><div id=\"evento_'+i+'\" style=\"display : '+styleDiv+';\"><span class=\"cciss-home-news cciss-home-news-dettaglio\">'+trafficInfo[i].dettaglio+'<br/></span></div></td></tr></table><br/>';
		    		
		    		// testoEventi+='<table cellspacing=\"0\" cellpadding=\"0\" border=\"0\" width=\"200\"><tr><td width=\"30\"><img src=\"'+relPath+'images/gmaps/'+tipoIcona+'.gif\" border="0"/></td><td width=\"4\"></td><td width=\"154\" valign=\"middle\"><span class=\"cciss-generic-font cciss-home-news-titolo-light\">'+trafficInfo[i].dataPubblicazione+'</span><br/><span class=\"cciss-home-news cciss-home-news-link\"><a href=\"javascript:focusOnNews('+i+');\">'+trafficInfo[i].titolo+ " " +' </a></span></td><td width=\"12\"><img src=\"'+relPath+'images/'+trafficInfo[i].priorita+'.gif\" border="0"/></td></tr><tr><td colspan=\"4\" width=\"200\"><div id=\"evento_'+i+'\" style=\"display : '+styleDiv+';\"><span class=\"cciss-home-news cciss-home-news-dettaglio\">'+trafficInfo[i].dettaglio+'<br/></span></div></td></tr></table><br/>';
		    		//mod carica eventi in ordine inverso
		    		testoEventi='<table cellspacing=\"0\" cellpadding=\"0\" border=\"0\" width=\"200\"><tr><td width=\"30\"><img src=\"'+relPath+'images/gmaps/'+tipoIcona+'.gif\" border="0"/></td><td width=\"4\"></td><td width=\"154\" valign=\"middle\"><span class=\"cciss-generic-font cciss-home-news-titolo-light\">'+trafficInfo[i].dataPubblicazione+'</span><br/><span class=\"cciss-home-news cciss-home-news-link\"><a href=\"javascript:focusOnNews('+i+');\">'+trafficInfo[i].titolo+ " " +' </a></span></td><td width=\"12\"><img src=\"'+relPath+'images/'+trafficInfo[i].priorita+'.gif\" border="0"/></td></tr><tr><td colspan=\"4\" width=\"200\"><div id=\"evento_'+i+'\" style=\"display : '+styleDiv+';\"><span class=\"cciss-home-news cciss-home-news-dettaglio\">'+trafficInfo[i].dettaglio+'<br/></span></div></td></tr></table><br/>'+testoEventi;
		    		// genero i marker e le code
		    		
		    		showCoda(trafficInfo[i].percorsoTO.coordinateMappaInizioTO, trafficInfo[i].percorsoTO.coordinateMappaFineTO,i);
		    		
		    		count++;
		    	}
		    }
		    var singolarePlurale='i';
		    if (count==1)
		    {
		    	singolarePlurale='o';
		    }
		    
		   //testoEventi= '<span  class=\"cciss-home-news cciss-home-news-titolo\">'+count+' event'+singolarePlurale+':<br/></span>'+testoEventi;
		   //Priorita Testo
		    var zoom_level_map=map.getZoom();
			     if (zoom_level_map<10)
			     {
					    var PrioritaTesto=" molto alta ";
					    if (zoom_level_map>6)
					    {
					    PrioritaTesto=" alta e molto alta ";
					    }
					    testoPriorita='<table cellspacing=\"0\" cellpadding=\"0\" border=\"0\" width=\"200\"><tr><td width=\"5\"></td><td width=\"190\" valign=\"middle\"><span style="color:red;font-weight: bold;font-family: Verdana, Arial;font-size: 10px;"> Per il livello di zoom selezionato, sono visualizzati solo gli eventi di severit&agrave '+ PrioritaTesto +'<br/></span></td><td width=\"5\"></tr></table> <br/>';
					    
					    testoEventi=testoPriorita + '<span  class=\"cciss-home-news cciss-home-news-titolo\">'+count+' event'+singolarePlurale+':<br/></span>'+testoEventi;
	    		}
	    		else
	    		{
	    				testoEventi= '<span  class=\"cciss-home-news cciss-home-news-titolo\">'+count+' event'+singolarePlurale+':<br/></span>'+testoEventi;
	    		}
    		//Priorita Testo
		    
    		return testoEventi;
    	}
  
    
function focusOnNews(i)
    	{
    		
    		if (i==infoFocus)
    		{
    			var divT='evento_'+i;
    			var divNews=document.getElementById(divT);
    		
    			divNews.style.display='none';
    			infoFocus=-1;
    		}
    		else
    		{
    		
	    		for (j=0;j<trafficInfo.length;j++)
	    		{
	    			var divT='evento_'+j;
	    			var divNews=document.getElementById(divT);
	    			if ((!(divNews==undefined))|| !(divNews==null))
	    			{
		    			if (i==j)
		    			{
		    				divNews.style.display='inline';
		    				infoFocus=i;
		    			}
		    			else
		    			{
		    				divNews.style.display='none';
		    			}
		    		}
	    		}
				map.closeInfoWindow();
	    		map.panTo(new GLatLng(trafficInfo[i].percorsoTO.coordinateMappaInizioTO.coordinateMappaCY,trafficInfo[i].percorsoTO.coordinateMappaInizioTO.coordinateMappaCX));
	    		
	    		
	    		
	    		var iconLIC = new GIcon();
                var tipoIcona="default";
               
               
                if (trafficInfo[i].codiceImmagine!=null)
                {
               	 	if (tipiDiIcone.indexOf(trafficInfo[i].codiceImmagine)!=-1)
               			{ tipoIcona=trafficInfo[i].codiceImmagine; }
                }
               
        	    iconLIC.image = relPath+"images/gmaps/"+tipoIcona+".gif"; 
                iconLIC.shadow = relPath+"images/gmaps/shadow.png"; 
              
               
                iconLIC.iconAnchor = new GPoint(15, 13); 
                iconLIC.infoWindowAnchor = new GPoint(15, 0); 
                //iconLIC.iconSize = new GSize(30, 26);
                //test priorita
						var map_zoom_level=map.getZoom();
						if (map_zoom_level<10)
						     {
					        	iconLIC.iconSize = new GSize(20, 18);
 								iconLIC.shadowSize= new GSize(30,26);      
						     } 
    					else
         					 {
 				          		iconLIC.iconSize = new GSize(30, 26);
          					 }
          					 
          		//test priorita 
           
           		
           		var GLLMarker= new GLatLng(trafficInfo[i].percorsoTO.coordinateMappaInizioTO.coordinateMappaCY,trafficInfo[i].percorsoTO.coordinateMappaInizioTO.coordinateMappaCX);
           		
                var headMarker = new GMarker(GLLMarker, { icon: iconLIC });
	    		
	    		
	    		map.addOverlay(headMarker);
	    		
	    		headMarker.openInfoWindowHtml('<table width=\"350\"><tr><td><span class="cciss-generic-font cciss-home-news-titolo-light">'+trafficInfo[i].dataPubblicazione+'</span><br/><span class=\"cciss-home-news cciss-home-news-link\">'+trafficInfo[i].titolo+'</span><br/><span  class=\"cciss-home-news cciss-home-news-dettaglio\">'+trafficInfo[i].dettaglio+'</span></td></tr></table>');
    		}
    	}
    	
    	
    
		function showCoda(inizio, fine, i)
		{
//testMAX
    var map_zoom_level=map.getZoom();   
       if (map_zoom_level>max_zoom_percorsi)
			{
				
			   var directions = new GDirections();
			   
			   GEvent.addListener(directions, "load", function() {
			   
               var polyline = directions.getPolyline(); 
               polyline.setStrokeStyle({color:"#0000C0",weight:8,opacity: 0.5}); 
                      
           		/*
               var iconLIC = new GIcon();
               var tipoIcona="default";
               
               
               if (trafficInfo[i].codiceImmagine!=null)
               {
               		if (tipiDiIcone.indexOf(trafficInfo[i].codiceImmagine)!=-1)
               			{ tipoIcona=trafficInfo[i].codiceImmagine; }
               }
               
        	   iconLIC.image = relPath+"images/gmaps/"+tipoIcona+".gif"; 
               iconLIC.shadow = relPath+"images/gmaps/shadow.png"; 
              
               
               iconLIC.iconAnchor = new GPoint(15, 13); 
               iconLIC.infoWindowAnchor = new GPoint(15, 0); 
               iconLIC.iconSize = new GSize(30, 26); 
           
           		if (polyline.getVertex(0)===null)
           		{
           			alert("vertex null");
           		}
               head = new GMarker(polyline.getVertex(0), { icon: iconLIC });
               */            
               map.addOverlay(polyline); 
               //map.addOverlay(head); 
               
               /*
               
               if ((!(trafficInfo==undefined)) && (trafficInfo!=null))
               { 
               		
	               GEvent.addListener(trafficMarkers[i], "click", function() {
	          		
	          		//alert("click su marker!");
	          		
	               map.openInfoWindowHtml(trafficMarkers[i].getLatLng(),"<span  class=\"cciss-home-news cciss-home-news-titolo\">"+trafficInfo[i].evento+"</span><br/><span class=\"cciss-home-news cciss-home-news-dettaglio\">"+trafficInfo[i].dettaglio+"</span>", {maxWidth:250}); 
	             
	               });
               
			   
			   }  
			   */

			});
				var query;
				if (fine.coordinateMappaCY==null)
				{
					/*
					var latFine=inizio.coordinateMappaCY+0.000000000001;
					var lngFine=inizio.coordinateMappaCX+0.000000000001;
					
			   		query="from: "+inizio.coordinateMappaCY+", "+inizio.coordinateMappaCX+" to: "+latFine+", "+lngFine;
			   		*/
			   	}
			   	else
				{
			   		query="from: "+inizio.coordinateMappaCY+", "+inizio.coordinateMappaCX+" to: "+fine.coordinateMappaCY+", "+fine.coordinateMappaCX;
			   		
			   		directions.load(query,{preserveViewport:true, getPolyline:true, locale: 'it_IT'});
			   	}
}
//testMax			   	
			   	var GLLHead= new GLatLng(inizio.coordinateMappaCY,inizio.coordinateMappaCX);
			   	
			   	var iconLIC = new GIcon();
                var tipoIcona="default";
               
               
               if (trafficInfo[i].codiceImmagine!=null)
               {
               		if (tipiDiIcone.indexOf(trafficInfo[i].codiceImmagine)!=-1)
               			{ tipoIcona=trafficInfo[i].codiceImmagine; }
               }
               
        	   iconLIC.image = relPath+"images/gmaps/"+tipoIcona+".gif"; 
               iconLIC.shadow = relPath+"images/gmaps/shadow.png"; 
              
               
               iconLIC.iconAnchor = new GPoint(15, 13); 
               iconLIC.infoWindowAnchor = new GPoint(15, 0); 
               //iconLIC.iconSize = new GSize(30, 26);
               var map_zoom_level=map.getZoom();
						//test priorita
						
						if (map_zoom_level<10)
						     {
					        	iconLIC.iconSize = new GSize(20, 18);
 								iconLIC.shadowSize= new GSize(30,26);      
						     } 
    					else
         					 {
 				          		iconLIC.iconSize = new GSize(30, 26);
          					 }
          					 
          				//test priorita	 
               
                
           
               head = new GMarker(GLLHead, { icon: iconLIC ,zIndexProcess:orderOfCreation});  
               
               
			   map.addOverlay(head);
			   trafficMarkers[i]=head;
			   
				GEvent.addListener(trafficMarkers[i], "click", function() {
	          		
	          		//alert("click su marker!");
	          		
	            map.openInfoWindowHtml(trafficMarkers[i].getLatLng(),"<table width=\"350\"><tr><td><span class=\"cciss-generic-font cciss-home-news-titolo-light\">"+trafficInfo[i].dataPubblicazione+"</span><br/><span class=\"cciss-home-news cciss-home-news-link\">"+trafficInfo[i].titolo+"</span><br/><span  class=\"cciss-home-news cciss-home-news-dettaglio\">"+trafficInfo[i].dettaglio+"</span></td></tr></table>", {maxWidth:250}); 
	             
	            });
			   

		}
function orderOfCreation(marker,b) {
        return 1;
      }

/*
    	function onGDirectionsLoad(directions) 
	  	{ 
	  		
           var polyline = directions.getPolyline(); 
           polyline.setStrokeStyle({color:"#0000C0",weight:8,opacity: 0.5}); 
                      
           
           var iconLIC = new GIcon(); 
        	 iconLIC.image = relPath+"images/gmaps/lavori_in_corso.gif"; 
            
           iconLIC.iconAnchor = new GPoint(15, 13); 
           iconLIC.infoWindowAnchor = new GPoint(15, 0); 
           iconLIC.iconSize = new GSize(30, 26); 
           
           head = new GMarker(polyline.getVertex(0), { icon: iconLIC })
           //GEvent.addListener(head, "mouseover", function() {map.closeInfoWindow(); head.openInfoWindowHtml("2008-11-20 9:34<br/>Rallentamenti per lavori di rifacimento del manto stradale");}); 
           //GEvent.addListener(head, "mouseout", function() {map.closeInfoWindow();}); 

           map.addOverlay(polyline); 
           map.addOverlay(head); 
    } */
    
    
    function initStaticMap() 
    {
      
	
      var staticMap=document.getElementById("static_map");
      if (!((staticMap==undefined) || (staticMap==null)))
      {
      	  setAbsPath();
          trafficInfo=latestEvento;
          trafficMarkers= new Array(1);
          	lat=trafficInfo[0].percorsoTO.coordinateMappaInizioTO.coordinateMappaCY;
	        lng=trafficInfo[0].percorsoTO.coordinateMappaInizioTO.coordinateMappaCX;
          
          if (!((lat==0) && (lng==0)))
          {
		      if (GBrowserIsCompatible()) 
		      {
		        map = new GMap2(document.getElementById("static_map")); 
		        
		       
		        //lat=trafficInfo[0].percorsoTO.coordinateMappaInizioTO.coordinateMappaCY;
		        //lng=trafficInfo[0].percorsoTO.coordinateMappaInizioTO.coordinateMappaCX;
		       
		        var lat2=trafficInfo[0].percorsoTO.coordinateMappaFineTO.coordinateMappaCY;
		        var lng2=trafficInfo[0].percorsoTO.coordinateMappaFineTO.coordinateMappaCX;
		       
		       	if (lat2==null)
		       	{
		       		lat2=lat+0.000000000000000001;
		       		lng2=lng+0.000000000000000001;
		       	}
		       	 
		       	
		    var latMin;
	        var lngMin;
	        var latMax;
	        var lngMax;
	        
	        if (lat<lat2)
	        {
	        	latMin=lat;
	        	latMax=lat2;
	        }
	        else
	        {
	        	latMin=lat2;
	        	latMax=lat;
	        }
	        
	        if (lng<lng2)
	        {
	        	lngMin=lng;
	        	lngMax=lng2;
	        }
	        else
	        {
	        	lngMin=lng2;
	        	lngMax=lng;
	        }        
	        
	        var gInizio= new GLatLng(latMin, lngMin);
	        var gFine= new GLatLng(latMax, lngMax);
	        
	        
	        
	        var latAverage=(lat+lat2)/2;
	        var lngAverage=(lng+lng2)/2;
	        
	        var boundsPercorso= new GLatLngBounds(gInizio,gFine);
		    var zoom= map.getBoundsZoomLevel(boundsPercorso);     	 
		       	 	    
		        
		        
		        map.disableDragging();
				map.disableInfoWindow();
				map.disableDoubleClickZoom();
				map.disableDoubleClickZoom();
				map.disableGoogleBar();
				map.disableScrollWheelZoom();
		        enableClickOnStatic();
		       
		        
		        
		        var boundsCoda= new GLatLngBounds(gInizio,gFine);
		        zoom= map.getBoundsZoomLevel(boundsCoda);
		        
		       	if (zoom>default_zoom_level)
		       	{
		       		zoom=default_zoom_level;
		       	}
		        //var latCenter=(trafficInfo[0].percorsoTO.coordinateMappaInizioTO.coordinateMappaCY+trafficInfo[0].percorsoTO.coordinateMappaFineTO.coordinateMappaCY)/2;
		        //var lngCenter=(trafficInfo[0].percorsoTO.coordinateMappaInizioTO.coordinateMappaCX+trafficInfo[0].percorsoTO.coordinateMappaFineTO.coordinateMappaCX)/2;
		        
		        
		        
		        var centerCoda=new GLatLng(latAverage,lngAverage);
		        map.setCenter(centerCoda, zoom);
		       
		        showCoda(trafficInfo[0].percorsoTO.coordinateMappaInizioTO, trafficInfo[0].percorsoTO.coordinateMappaFineTO,0);
		      }
	     } 
     else
     {
      //staticMap.innerHTML='<img src=\"(${pageContext.request.contextPath}/images/banner1518_max.gif)\">';
      staticMap.innerHTML='<img src=\"/portale/images/mappa_non_disponibile.jpg\">';
      staticMap.style.cursor='default';
     //staticMap.innerHTML='style=\" width: 298px; height: 163px; border: 1px solid rgb(205, 205,207);background-image: url(/portale/images/banner1518_max.gif)\">'
     }
     
     }
    }
    
    function enableClickOnStatic() {
	    click = GEvent.bind(map, "click", this, function() {
	    goToEventoMap();
	});
    }
    
    
    function goToEventoMap()
    {
    	var formStaticMap=document.getElementById("staticGMapPortlet.staticMapForm");
    	
    	
	    if (!((formStaticMap==undefined) || (formStaticMap==null)))
	    {
	    	var inputZoom= document.getElementById("zoom");
	    	var latCenter= document.getElementById("latCenter");
	    	var lngCenter= document.getElementById("lngCenter");
	    	
	    	inputZoom.value= map.getZoom();
	    	latCenter.value= map.getCenter().lat();
	    	lngCenter.value= map.getCenter().lng();
	    	formStaticMap.submit();
	    }
	    else
	    {
			//alert("click!");
		}
		
    }

    
    function initResultStaticMap() 
    {
      //alert("initResultStaticMap");
      var mapTemp=document.getElementById("map_canvas");
     
      if (!((mapTemp==undefined) || (mapTemp==null)))
      {
      	  setAbsPath();
          map=document.getElementById("map_canvas");
	      if (GBrowserIsCompatible()) 
	      {
	      	if (!((_zoom==undefined) ||(_zoom==null)))
	      	{
		        map = new GMap2(document.getElementById("map_canvas")); 
		        
		        var _center = new GLatLng(_latCenter,_lngCenter);
		              
		        map.setCenter(_center, _zoom);
		        map.addControl(new GLargeMapControl()); 
		        map.addControl(new GOverviewMapControl(new GSize(120,96))); 
		        
		        
		        setMapBoundBox();
		        getEventi();
		        //enableLiveLoading(); 
	      	}
	        
	      }
     }
    }
    
    //funzioni per i percorsi
    
    function initialize(latInizio, lngInizio,latFine, lngFine) 
    {
	  setAbsPath();
    
      if (GBrowserIsCompatible()) 
      {
        map = new GMap2(document.getElementById("map_canvas")); 
        
        
        //alert(latFine);
        
        
        var latMin;
        var lngMin;
        var latMax;
        var lngMax;
        
        if (latInizio<latFine)
        {
        	latMin=latInizio;
        	latMax=latFine;
        }
        else
        {
        	latMin=latFine;
        	latMax=latInizio;
        }
        
        if (lngInizio<lngFine)
        {
        	lngMin=lngInizio;
        	lngMax=lngFine;
        }
        else
        {
        	lngMin=lngFine;
        	lngMax=lngInizio;
        }        
        
        var gInizio= new GLatLng(latMin, lngMin);
        var gFine= new GLatLng(latMax, lngMax);
        
        
        
        var latAverage=(latInizio+latFine)/2;
        var lngAverage=(lngInizio+lngFine)/2;
        
        var boundsPercorso= new GLatLngBounds(gInizio,gFine);
	    var zoomPercorso= map.getBoundsZoomLevel(boundsPercorso);
        
        //alert(latInizio+" "+lngInizio);
        //alert(latFine+" "+lngFine);
        //alert(zoomPercorso);
        
        var gCenter= new GLatLng(latAverage,lngAverage);
        map.setCenter(gCenter, zoomPercorso);
        
        map.addControl(new GLargeMapControl());
        map.addControl(new GMapTypeControl()); 
        map.addControl(new GOverviewMapControl(new GSize(120,96))); 
        
        showPercorso(latInizio, lngInizio, latFine, lngFine);
        
        setMapBoundBox();
        getEventi();
        enableLiveLoading();
        //init_webcam(map); 
		//init_sensori(map); 
      }
    }
    
    
    		function showPercorso(latInizio, lngInizio, latFine, lngFine)
		{
			   directionsPanel = document.getElementById("route");
			   percorso = new GDirections(map, directionsPanel);
			   
			   GEvent.addListener(percorso, "load", function() {
			   
               percorsoPolyline = percorso.getPolyline(); 
               percorsoPolyline.setStrokeStyle({color:"red",weight:7,opacity: 1.00}); 
                      
           
               //var iconLIC = new GIcon(); 
        	   //iconLIC.image = relPath+"images/gmaps/lavori_in_corso.gif"; 
            
               //iconLIC.iconAnchor = new GPoint(15, 13); 
               //iconLIC.infoWindowAnchor = new GPoint(15, 0); 
               //iconLIC.iconSize = new GSize(30, 26); 
           
               //head = new GMarker(polyline.getVertex(0), { icon: iconLIC });
          
               map.addOverlay(percorsoPolyline); 
               //map.addOverlay(head); 
               //trafficMarkers[i]=head;
               
			   
			   } ); 
			    
			   query="from: "+latInizio+", "+lngInizio+" to: "+latFine+", "+lngFine;
			   		 
			   		 
        		
        		if (document.getElementById("check_autostrade").checked) 
        		{
           			percorso.load(query,{preserveViewport:true, getPolyline:true, locale: 'it_IT',avoidHighways:true});
        		}
			   	else
			   	{	   
			   		percorso.load(query,{preserveViewport:true, getPolyline:true, locale: 'it_IT'});
			   	}

		}
    
    
    function initGMaps()
    {
    	
    	var mapTemp=document.getElementById("map_canvas");
     	
      	if (!((mapTemp==undefined) || (mapTemp==null)))
      	{
      		
    		if (!(lat==undefined)){
		    	if ((!(lat==undefined) && !(lng==undefined) && !(index==undefined))	&& (!(lat==null) && !(lng==null) && !(index==null)))
		    	{    	 	     
		      	 		initializeMap(lat, lng, index);
		    	 } 
		    	 
	    	 }
	    	 else
	    	 {
	    	 	if ((!(_latCenter==undefined) && !(_lngCenter==undefined) )	&& (!(_latCenter==null) && !(_lngCenter==null)))
	    	 	{
	    	 		initializeMap(_latCenter,_lngCenter,-1);
	    	 	}
	    	  	else
	    	  	{
	    	 		initializeMap(italia_center_lat,italia_center_lng,-1);
	    	 	}
	    	 }
    	}
    	
    	
    }
    
    
// WEBCAM    
    

