
		var curwin;
		var mapcenter   = new VELatLong(36.7830, 14.5545);
		var mapzoom     = 14;
		var map;

		var fl3dn = null;
		var fl3ds = null;
		var fl3de = null;
		var fl3do = null;
		var fl2d  = null;
			
		var curshape    = null;
		var curtimer    = null;
		var cur3d	= 0;

		var mapRotation = 1;
		var animStep    = 0;

		var icon  ="<div style='width:26px;height:26px;'><div style='margin:9px;background:red;   width:8px;height:8px;'></div></div>";
		var icon2 ="<div style='width:26px;height:26px;'><div style='margin:9px;background:black; width:8px;height:8px;'></div></div>";
		var icon3 ="<div style='width:26px;height:26px;'><div style='margin:9px;background:blue;  width:8px;height:8px;'></div></div>";
		
		function CreateBookmarkLink()
		{
			var title = "Marina di Ragusa";
			var url = "http://www.marinadiragusa.info";
	
			if (window.sidebar)
			{ // Mozilla Firefox Bookmark
				window.sidebar.addPanel(title, url,"");
			}
			else if(window.external)
			{ // IE Favorite
				window.external.AddFavorite( url, title);
			}
			else if(window.opera && window.print)
			{ // Opera Hotlist
				return true;
			}
		}

		function openmapinfo()
      		{
			if ( curwin != null ) 
				curwin.close();

			curwin = dhtmlwindow.open('divbox', 'div', 'mapinfodiv', 'Marina di Ragusa', 'width=450px,height=350px,left=200px,top=150px,resize=1,scrolling=1', 'recal');
      		}

      		function GetRMap()
      		{
         		map = new VEMap( 'myMap' );
			map.HideDashboard();

			map.onLoadMap = onLoadMap;
         		map.LoadMap( mapcenter, mapzoom ,'r' , false );

			var x = new VECustomIconSpecification();				
			x.ImageOffset = new VEPixel(parseInt(4-13),parseInt(4-13))
	     	}   

      		function onLoadMap()
      		{
	 		map.SetScaleBarDistanceUnit( VEDistanceUnit.Kilometers );
	        	map.SetShapesAccuracy( VEShapeAccuracy.None );

	        	fl3dn = new VEShapeLayer();
			fl3ds = new VEShapeLayer();
			fl3de = new VEShapeLayer();
			fl3do = new VEShapeLayer();
	        	var ls3d = new VEShapeSourceSpecification( VEDataType.GeoRSS, 'http://www.marinadiragusa.info/reqfeed.aspx?l=' + FLANG + '&f=3d_' + FNAME, fl3dn );
	     			   
	        	fl2d = new VEShapeLayer();
	        	var ls2d = new VEShapeSourceSpecification( VEDataType.GeoRSS, 'http://www.marinadiragusa.info/reqfeed.aspx?l=' + FLANG + '&f=' + FNAME, fl2d );

			map.AddShapeLayer( fl3ds );
	        	map.AddShapeLayer( fl3de );
	        	map.AddShapeLayer( fl3do );
	        	fl3ds.Hide();
	        	fl3de.Hide();
	        	fl3do.Hide();
			
	        	map.ImportShapeLayerData( ls2d, onFeedLoad2d, false );
	        	map.ImportShapeLayerData( ls3d, onFeedLoad3d, false );
			map.AttachEvent( 'onchangeview', mapchangeview );

      		}

	    	function onFeedLoad2d( layer )
	    	{
	        	var numShapes = layer.GetShapeCount();
			var txt;
			var i;
	
	        	for( i=0; i < numShapes; ++i )
	        	{
	            		var s = layer.GetShapeByIndex(i);
				txt = "<br>" + s.GetDescription();
				txt += "<div style='padding-top:5px;text-align:left;'><a href='javascript:show3d(" + i + ");'>" + TXTCONST_SATELLITE + "</a>";
				txt += "<br><a href='javascript:startroute(" + i + ");'>" + TXTCONST_FINDPATH + "</a></div>";
				s.SetDescription( txt ); 
	            		s.SetCustomIcon( icon );
	       	 	}

			i = window.location.toString().indexOf( '?i=', 0 );
			if ( i > -1 )
	        	{
				txt = window.location.toString().substr( i+3 );
				if ( !isNaN( txt ) )
	        		{	
					setTimeout( "show(" + txt + ")", 500 );
	       	 		}
			}

	    	}

	    	function onFeedLoad3d( layer )
	    	{
			layer.Hide();

	        	var numShapes = layer.GetShapeCount();

			var s;
			var n;
			
			var tmp1;
			var tmp2;
			var txtt;
			var txtd;
			var j;


			for(var i=0; i < numShapes; ++i)
	        	{
	            		s = layer.GetShapeByIndex(i);
	            		s.SetCustomIcon( icon );
				
				txtd = s.GetDescription();
				txtt = s.GetTitle();
				tmp1 = txtd;

				j = tmp1.indexOf( "<mc>" );
				if ( j == -1 )
					continue;

				txtd = txtd.substring( 0, j );

				tmp1 = tmp1.substring( j + 4 );
				tmp1 = tmp1.split("-");

				s.SetDescription( txtd );

				tmp2 = tmp1[0].split(";");
          			n = new VEShape( VEShapeType.Pushpin, new VELatLong( tmp2[0], tmp2[1] ) );
            			n.SetTitle( txtt + " sud" );
				n.SetDescription( txtd );
	            		n.SetCustomIcon( icon );
				fl3ds.AddShape( n );

				tmp2 = tmp1[1].split(";");
          			n = new VEShape( VEShapeType.Pushpin, new VELatLong( tmp2[0], tmp2[1] ) );
            			n.SetTitle( txtt + " est" );
				n.SetDescription( txtd );
	            		n.SetCustomIcon( icon );
				fl3de.AddShape( n );

				tmp2 = tmp1[2].split(";");
          			n = new VEShape( VEShapeType.Pushpin, new VELatLong( tmp2[0], tmp2[1] ) );
            			n.SetTitle( txtt + " ovest" );
				n.SetDescription( txtd );
	            		n.SetCustomIcon( icon );
				fl3do.AddShape( n );
	       	 	}

			cur3d = 0;
	    	}

      		function mapchangeview( e )
		{	
			if ( e.mapStyle == 'r' )
            		{
				if ( curshape == null )
					return;

				setTimeout( "animShape()", 500 );
				return;
			}
 
			
			if ( !map.IsBirdseyeAvailable())
            		{
				document.getElementById( 'myMap' ).style.display = 'none';
				setTimeout("rotate()", 500);
             		}
			else
           		{
				document.getElementById( 'myMap' ).style.display = 'block';
             		}
		
		}

      		function ResetMap()
      		{
			cur3d = 0;

			if ( fl3dn != null ) 
				fl3dn.Hide();

			if ( fl3ds != null ) 
				fl3ds.Hide();

			if ( fl3de != null ) 
				fl3de.Hide();

			if ( fl3do != null ) 
				fl3do.Hide();

			if ( fl2d != null ) 
				fl2d.Show();

			document.getElementById("sBack").style.visibility = "hidden";
			document.getElementById("sRotate").style.visibility = "hidden";
			
         		map.SetMapStyle( VEMapStyle.Road );
			map.SetCenterAndZoom( mapcenter, mapzoom ); 	       
	     	}   	         

      		function show( i )
      		{	
			if ( curshape )
      			{
				clearTimeout( curtimer );
				curshape.SetCustomIcon( icon );
	     		}

			if ( map.GetMapStyle() != VEMapStyle.Road )
      			{
				document.getElementById("sBack").style.visibility = "hidden";
				document.getElementById("sRotate").style.visibility = "hidden";

         			map.SetMapStyle( VEMapStyle.Road );
	     		}   	         

			if ( !fl2d.IsVisible() )
				fl2d.Show();

			if ( fl3dn.IsVisible() )
				fl3dn.Hide();

			if ( fl3ds.IsVisible() )
				fl3ds.Hide();

			if ( fl3de.IsVisible() )
				fl3de.Hide();

			if ( fl3do.IsVisible() )
				fl3do.Hide();

	            	curshape = fl2d.GetShapeByIndex( i );
	            	var p = curshape.GetPoints();

			map.DeleteRoute();			
			map.HideInfoBox();
			map.SetCenter( p[0] );
      		}

      		function show3d( i )
      		{	
			document.getElementById("sRotate").style.visibility = "visible";
			document.getElementById("sBack").style.visibility = "visible";

	            	var s;

			switch( cur3d )
            		{
             	 		case 0: 
					s = fl3dn.GetShapeByIndex(i);
                             		break;

               			case 1: 
					s = fl3ds.GetShapeByIndex(i);
                             		break;

               			case 2:  
					s = fl3de.GetShapeByIndex(i);
                             		break;
               			
				case 3:
					s = fl3do.GetShapeByIndex(i);
                             		break;
      			}



	            	var p = s.GetPoints();

			map.DeleteRoute();			
			map.HideInfoBox();
			map.SetCenter( p[0] );			
			map.SetBirdseyeScene( p[0] );		

			switch( cur3d )
            		{
             	 		case 0: 
					fl3dn.Show();
                             		break;

               			case 1: 
					fl3ds.Show();
                             		break;

               			case 2:  
					fl3de.Show();
                             		break;
               			
				case 3:
					fl3do.Show();
                             		break;
      			}

			if ( fl2d != null ) 
				fl2d.Hide();

      		}

      		function showstep( x, y )
      		{	
			map.SetCenter( new VELatLong( x, y ) );
      		}
		
		function startroute( i )
      		{
	            	curshape = fl2d.GetShapeByIndex( i );

			if ( curwin != null ) 
				curwin.close();

			curwin = dhtmlwindow.open('divbox', 'div', 'spdiv', TXTCONST_STARTADDR, 'width=350px,height=150px,left=200px,top=150px,resize=1,scrolling=1', 'recal');
      		}

      		function route()
      		{	
			if ( curshape == null )
				return;

			var start = "";
			start = document.getElementById("spnum").value + ", ";
			start += document.getElementById("spaddr").value + ", ";
			start += "97010 Ragusa RG, Sicily, Italy";

			curwin.close();
	       		
			map.Find( null, start, null, null, 0, 10, false, false, false, false, GotFindResults );
      		}

		function GotFindResults(layer, resultsArray, places, hasMore, veErrorMessage)
      		{			
			var x1 = 36.77711745986356;
			var y1 = 14.583320617675774;
			var x2 = 36.81876733567169;
			var y2 = 14.507446289062501;
			var x;	
			var y;

			for ( var i = 0; i < places.length; i++ )
	      		{
				x = places[i].LatLong.Latitude;
				y = places[i].LatLong.Longitude;

				if ( ( x1 <= x ) && ( x <= x2 ) && ( y1 >= y ) && ( y >= y2 ) )
				{	
	            			var pts = curshape.GetPoints();
					var options = new VERouteOptions;
					var locations = new Array( places[i].LatLong, pts[0] );

            				options.DrawRoute = true;
            				options.DistanceUnit = VERouteDistanceUnit.Kilometer;			
    					options.SetBestMapView = true;
      					options.ShowDisambiguation = false;
					options.RouteCallback = onGotRoute;
					map.GetDirections( locations, options );

					return;
				}
     			}

			alert( TXTCONST_STARTADDRNOTFOUND );
      		}

     		function onGotRoute( route )
         	{
            		var legs     = route.RouteLegs;
           		var turns    = "<div style='text-align:left;'>";
           		var leg      = null;
				
			for(var i = 0; i < legs.length; i++)
            		{
               			leg = legs[i];
               			var turn = null;
                  
               			for( var j = 0; j < leg.Itinerary.Items.length; j++ )
               			{
					
                  			turn = leg.Itinerary.Items[j];

					if ( j == 0 )
					{
						turn.Shape.SetCustomIcon( icon3 );
                  				turns += TXTCONST_START; 
					}
					else if( j == leg.Itinerary.Items.length - 1 )
					{
						turn.Shape.SetCustomIcon( icon3 );
						turns += TXTCONST_END;
					}
					else
						turns += j;

					turns += "&nbsp;" + turn.Text + " ";
					turns += "<a href='javascript:showstep(" + turn.LatLong.Latitude + "," + turn.LatLong.Longitude + ")'>" + TXTCONST_MAP + "</a><br>";
               			}
            		}
		
			turns += "</div>";

			if ( curwin != null )
				curwin.close();

			curwin = dhtmlwindow.open('divbox', 'inline', turns, TXTCONST_PATH, 'width=350px,height=350px,left=200px,top=100px,resize=1,scrolling=1' );
         	}

      		function animShape()
      		{
			if ( animStep % 2 == 0 )
      			{
				curshape.SetCustomIcon( icon );				
      			}
			else
      			{
				curshape.SetCustomIcon( icon2 );
      			}

			if ( ++animStep == 7 )
      			{
				map.ShowInfoBox( curshape );
				curshape = null;
				animStep = 0;
      			}
			else
      			{
				curtimer = setTimeout( "animShape()", 500 );
      			}	
      		}

      		function zoomin()
      		{
			map.ZoomIn();
      		}

      		function zoomout()
      		{
			map.ZoomOut();
      		}

		function rotate()
      		{
			if ( map.GetMapStyle() == VEMapStyle.Road )
				return;

			fl3dn.Hide();
                        fl3ds.Hide();
                        fl3de.Hide();
                        fl3do.Hide();
                        
			switch( mapRotation )
            		{
             	 		case 0: 
					mapRotation = 1;	
					cur3d = 0;
					map.SetBirdseyeOrientation(VEOrientation.North);
                             		break;

               			case 1: 
					mapRotation = 2;
					cur3d = 2;
					map.SetBirdseyeOrientation(VEOrientation.East);      
                             		break;

               			case 2:  
					mapRotation = 3;
					cur3d = 1;
					map.SetBirdseyeOrientation(VEOrientation.South);
                             		break;
               			
				default:
					mapRotation = 0;
					cur3d = 3;
					map.SetBirdseyeOrientation(VEOrientation.West);
                             		break;
      			}

			switch( cur3d )
            		{
             	 		case 0: 
					fl3dn.Show();
                             		break;

               			case 1: 
					fl3ds.Show();
                             		break;

               			case 2:  
					fl3de.Show();
                             		break;
               			
				case 3:
					fl3do.Show();
                             		break;
      			}

      		}
