﻿ var map = null;

 var Kihei =         new VELatLong(20.7475,  	-156.4539);
 var KiheiSurfside = new VELatLong(20.70595, 	-156.44652);
 var Keawakapu =     new VELatLong(20.70449, 	-156.44651);
 
 
 var rainbowMall = new VELatLong(20.719029184918923,-156.4461922645569);
 var kamaoleShopping = new VELatLong(20.71835684073393, -156.44607424736026);
 var dolphinCenter = new VELatLong(20.719982503647752, -156.4465034008026);
 var kamaoleBeachCenter = new VELatLong(20.71944061794836, -156.4464282989502);
 var moose = new VELatLong(20.716871651957735, -156.44600987434387);
 var fivePalms = new VELatLong(20.704738, -156.44662);
 var sarentos= new VELatLong(20.70385, -156.4460849);


 var KiheiTownCenter = new VELatLong(20.73468, -156.452393);
 var KiheiKalamaVillage = new VELatLong(20.73168274, -156.451578);
 var PiilaniVillageShoppingCenter = new VELatLong(20.75222121, -156.448338);
 var KukuiMall = new VELatLong(20.733107587194787, -156.45185708999634);
 var AlohaOpenMarket = new VELatLong(20.735174583797157, -156.45339131355288);


 var walkingDistanceCenter = new VELatLong(20.71044, -156.44634);

 
 var pinPoint = null;
 var pinPixel = null;

function CenterZoomMaui() {
	map.SetCenterAndZoom(Kihei,9);
}
function CenterZoomSurfside() {
	map.SetCenterAndZoom(Keawakapu ,17);
}
function CenterZoomKihei() {
	map.SetCenterAndZoom(Kihei,12);
}
function CenterZoomAirportDrive() {
	var ctr =     new VELatLong(20.75611, -156.44222)
	map.SetCenterAndZoom(ctr,11);
}


function AddPin(title, loc, descrip)
{
	p1Shape = new VEShape(VEShapeType.Pushpin, loc);
	p1Shape.SetTitle(title);
	p1Shape.SetDescription(descrip);
	map.AddShape(p1Shape);
}
          
 function GetMap()
 {
 	GetMap2(Keawakapu, 'myMap', 17, VEMapStyle.Hybrid);

	AddPin("Kihei Surfside", KiheiSurfside, "Kihei Surfside condo");
	AddPin("Keawakapu beach", Keawakapu, "One of the top beaches in the world - just a few steps away");
 }
 
 function GetMapAirport()
 {
	var ctr =     new VELatLong(20.75611, -156.44222)
 	GetMap2(Kihei, 'myMap', 11, VEMapStyle.Road);
 	AirportDirections(); //note: updates map view zoom/pan to view the directions
 }

 function GetMapMaui()
 {
 	GetMap2(Kihei, 'myMap', 9, VEMapStyle.Hybrid);
 }

 function GetMapKihei()
 {
 	GetMap2(Kihei, 'myMap', 13, VEMapStyle.Road);

	AddPin("Kihei Surfside", KiheiSurfside, "Kihei Surfside condo");
	AddPin("Shopping and restaurants", rainbowMall, "Shops and restaurants at the Dolphin Center, Rainbow mall, Kamaole Beach Center, and Kamaole Shopping Center ");
	AddPin("Kihei Town Center", KiheiTownCenter, "Foodland");
	AddPin("Kihei Kalama Village", KiheiKalamaVillage, "Restaurants and open air shops");
	AddPin("Piilani Village Shopping Center", PiilaniVillageShoppingCenter, "Safeway, Starbucks, Blockbuster and much more");
	AddPin("Kukui Mall", KukuiMall, "");
	AddPin("Aloha Open Market", AlohaOpenMarket, "");

 }

 function GetMapKeawakapu()
 {
 	GetMap2(Keawakapu, 'myMap', 17, VEMapStyle.Hybrid);

	AddPin("Kihei Surfside", KiheiSurfside, "Our condo - the tip of this push pin is at the lanai of unit #108");
	AddPin("Keawakapu beach", Keawakapu, "One of the top beaches in the world - just a few steps away");
 }

 function GetMapWalkingDistance()
 {
 	GetMap2(walkingDistanceCenter , 'myMap', 15, VEMapStyle.Hybrid);

	AddPin("Kihei Surfside", KiheiSurfside, "Our condo - the tip of this push pin is at the lanai of unit #108");

	AddPin("Rainbow mall", rainbowMall, "shops");
	AddPin("Kamaole Shopping Center", kamaoleShopping, "shops");
	AddPin("Dolphin Center", dolphinCenter, "shops");
	AddPin("Kamaole Beach Center", kamaoleBeachCenter, "shops");
	AddPin("Moose McGillicuddy's", moose, "Restaurant");
	AddPin("Five Palms restaurant", fivePalms, "We love to have breakfast here");
	AddPin("Sarento's On The Beach restaurant", sarentos, "Five-star dining");
 }


 function GetMap2(loc, divid, zoom, mapstyle)
 {
    map = new VEMap(divid);
    map.LoadMap(loc, zoom, mapstyle, false, VEMapMode.Mode2D, true, 1);
 }

 function getInfo()
 {
    var info;

    if (map.IsBirdseyeAvailable())
    {
        var be = map.GetBirdseyeScene();

        info  = "ID: "          + be.GetID() + "\n";
        info += "orientation: " + be.GetOrientation()+ "\n";
        info += "height: "      + be.GetHeight() + "\n";
        info += "width: "       + be.GetWidth() + "\n";

        var pixel = be.LatLongToPixel(map.GetCenter(), map.GetZoomLevel());

        info += "LatLongToPixel: " + pixel.x + ", " + pixel.y + "\n";

        // Check to see if the current birdseye view contains the pushpin pixel point.
        info += "contains pixel " + pinPixel.x + ", " + pinPixel.y + ": " + 
                be.ContainsPixel(pinPixel.x, pinPixel.y, map.GetZoomLevel()) + "\n";
        
        // Check to see if the current view contains the pushpin LatLong.
        info += "contains latlong " + pinPoint + ": " + be.ContainsLatLong(pinPoint) + "\n";
        
        // This method may return null, depending on the selected view and map style.
        info += "latlong: " + map.PixelToLatLong(pixel);

       alert(info);
    }
    else
    {
        var center = map.GetCenter();

        info  = "Zoom level:\t" + map.GetZoomLevel() + "\n";
        info += "Latitude:\t"   + center.Latitude    + "\n";
        info += "Longitude:\t"  + center.Longitude;

        alert(info);
    }
 }
 
 
 /* based on code from The JavaScript Source!! http://javascript.internet.com */

function SetInner(
    divID, //id of div
    text) { //string we want to stick in
  var elem;
  if(document.getElementById) // this is the way the standards work
  {
    elem = document.getElementById(divID);
  }
  else if(document.all) // this is the way old msie versions work
  {
      elem = document.all[PopupID];
  }
  else if(document.layers) // this is the way nn4 works
  {
    elem = document.layers[PopupID];
  }
  elem.innerHTML = text;
}

 //use this to fill a div with id "directions"
 function myRouteHandler(route)
{
   // Unroll route and populate alert text
   var legs          = route.RouteLegs;
   var turns         = "Turn-by-Turn Directions<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 dereference 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) + " miles)<br/>";
      }
   }
   
   turns += "Total distance:  " + totalDistance.toFixed(1) + " miles\n";

   // Show directions
   //alert(turns);
   SetInner("directions", turns);
}
 
 function AirportDirections()
 {
	 
	var myOptions = new VERouteOptions();
	myOptions.SetBestMapView = true; // update map view
//	myOptions.RouteCallback = myRouteHandler;  // Gets VERoute 
//	CenterZoomAirportDrive();
	map.GetDirections(["OGG", "2936 South Kihei Rd, Kihei, HI"], myOptions);
 }
// function AddPin()
// {
    // Add a new pushpin to the center of the map.
//    pinPoint = map.GetCenter();
//    pinPixel = map.LatLongToPixel(pinPoint);
//    map.AddPushpin(pinPoint);
// }

