﻿
        var centerLatitude = 46.74677123196261;
        var centerLongitude = 14.187211990356452;
        var centerCoordinates = new VELatLong(centerLatitude, centerLongitude); 
     
        var pinid = 0;
        var icon = "<img src='App_Themes/icon.png' onclick=theMap.ZoomIn(); />";
        var infobox = "<div style='width:160px;z-index:2'><strong>Hotel Alpenblick</strong><br /><br/><br>"
                    +""
                    +"</div>";
        var theMap;  
           
         function loadMap() {  
             theMap = new VEMap("theMap"); 
                           
             theMap.onLoadMap = function() {  
                 theMap.SetZoomLevel(13);  
                 theMap.ZIndex = 1;
                 theMap.HideDashboard();     
                 theMap.SetCenter(centerCoordinates); 
                 theMap.SetScaleBarDistanceUnit(VEDistanceUnit.Kilometers);  
             }  
               
             theMap.LoadMap();
               
             myShapeLayer = new VEShapeLayer();
             theMap.AddShapeLayer(myShapeLayer);
             
             var myShape = new VEShape(VEShapeType.Pushpin, centerCoordinates);
             myShape.SetCustomIcon(icon);

             theMap.ClearInfoBoxStyles();
             myShape.SetTitle("<h2 style='margin-top:0px;'>Hier sind wir!</h2>");
             myShape.SetDescription(infobox);
             pinid++;

             theMap.AddShape(myShape);

         }  

 function Route()
  {         
    var myLocations = new Array();
    myLocations[0] = document.getElementById('routestart').value;
    myLocations[1] = centerCoordinates, "Kärnten, Österreich";

    var myRouteOptions = new VERouteOptions();
    myRouteOptions.SetBestMapView = true; // change map view
    myRouteOptions.RouteCallback = myRouteHandler;  // Gets VERoute
    myRouteOptions.DistanceUnit = VERouteDistanceUnit.Kilometer; // because we are germans!
    theMap.GetDirections(myLocations, myRouteOptions);
  }         
   
          
  function ZoomIn()
  {
   if (document.getElementById('theMap2').style.display == "inline") {
       theMap.SetMapStyle(VEMapStyle.Road);
       document.getElementById('theMap2').style.display = "none";
       document.getElementById('theMap').style.display = "inline";
   }
   theMap.ZoomIn();
  }
  
  function ZoomOut()
  {
   if (document.getElementById('theMap2').style.display == "inline") {
       theMap.SetMapStyle(VEMapStyle.Road);
       document.getElementById('theMap2').style.display = "none";
       document.getElementById('theMap').style.display = "inline";
   }
   theMap.ZoomOut();
  }
  
  function MapStyleRoad()
  {           
   theMap.SetMapStyle(VEMapStyle.Road);
   document.getElementById('theMap2').style.display = "none";
   document.getElementById('theMap').style.display = "inline";
  }
   
  function MapStyleHybrid()
  {           
   theMap.SetMapStyle(VEMapStyle.Hybrid);
   theMap.SetZoomLevel(13);
   document.getElementById('theMap').style.display = "inline";
   document.getElementById('theMap2').style.display = "none";
  }
  
  function MapStyleSpider()
  {           
   document.getElementById('theMap').style.display = "none";
   document.getElementById('theMap2').style.display = "inline";
  }
  
  function MapHideLayer()
  {           
   myShapeLayer.Hide();
   document.getElementById('HideLayer').style.display = "none";
   document.getElementById('ShowLayer').style.display = "inline";
  }
  
  function MapShowLayer()
  {           
   myShapeLayer.Show();
   document.getElementById('ShowLayer').style.display = "none";
   document.getElementById('HideLayer').style.display = "inline";
  }
  
  function deleteRoute()
  {
  try
  {
  theMap.DeleteRoute();
  //document.getElementById('route').style.display = 'none';
  document.getElementById('routestart').value = "";
  document.getElementById('routestart').style.background ='url(App_Themes/route_01.gif) no-repeat';
  new Effect.Fade(document.getElementById('route'));
  }
  catch (err)
  {
  alert(err.message);
  }
  }
         
  function myRouteHandler(route)
{
   // Unroll route and populate alert text
   var legs          = route.RouteLegs;
   var turns         = "<h3>Ihre Route</h3><br /><br />";
   var leg           = null;
   var turnNum       = 0;  // The turn #
   var totalDistance = 0;  // The sum of all leg distances

   // Get intermediate legs
   for(var i = 0; i < legs.length; i++)
   {
      // Get this leg so we don't have to derefernce multiple times
      leg = legs[i];  // Leg is a VERouteLeg object

      // Unroll each intermediate leg
      var turn        = null;  // The itinerary leg
      var legDistance = null;  // The distance for this leg

      for(var j = 0; j < leg.Itinerary.Items.length; j ++)
      {
         turnNum++;
         // turn is a VERouteItineraryItem object
         turn = leg.Itinerary.Items[j];  
         turns += turnNum + ":  " + turn.Text;
         legDistance    = turn.Distance;
         totalDistance += legDistance;

         // Round distances to 1/10ths
         // Note that miles is the default
         turns += " (" + legDistance.toFixed(1) + " km)<br>";
      }
   }
   turns += "<br /><strong>Enfernung (gesamt):  " + totalDistance.toFixed(1) + " km</strong><br>";

   // Show directions
   document.getElementById('route').innerHTML = turns;
   new Effect.Appear(document.getElementById('route'));
   //document.getElementById('route').style.display = 'block';
}
