﻿google.load("maps", "2");
        
// This preloads images for the getting started divs
if (document.images)
{
	//at a glance
	aag = new Image(92,28);
	aag.src="/_layouts/PeopleToPeople/Includes/Images/Destination/Nav_destination_01_atGlance.jpg";
	aagon = new Image(92,28);
	aagon.src="/_layouts/PeopleToPeople/Includes/Images/Destination/Nav_destination_01_atGlance_active.jpg";
	
	// itinerary detail
	id = new Image(138,28);
	id.src="/_layouts/PeopleToPeople/Includes/Images/Destination/Nav_destination_02_itineraryDetail.jpg";
	idon = new Image(138,28);
	idon.src="/_layouts/PeopleToPeople/Includes/Images/Destination/Nav_destination_02_itineraryDetail_active.jpg";
	
	// map
	m = new Image(68,28);
	m.src="/_layouts/PeopleToPeople/Includes/Images/Destination/Nav_destination_03_map.jpg";
	mon = new Image(68,28);
	mon.src="/_layouts/PeopleToPeople/Includes/Images/Destination/Nav_destination_03_map_active.jpg";
	
	// get started
	gs = new Image(120,28);
	gs.src="/_layouts/PeopleToPeople/Includes/Images/Destination/Nav_destination_04_getStarted.jpg";
	gson = new Image(120,28);
	gson.src="/_layouts/PeopleToPeople/Includes/Images/Destination/Nav_destination_04_getStarted_active.jpg";
	
	// clear and go
	c = new Image(81,21);
	c.src="/_layouts/PeopleToPeople/Includes/Images/Buttons/btn_clear.jpg";
	g = new Image(60,21);
	g.src ="/_layouts/PeopleToPeople/Includes/Images/Buttons/btn_go.jpg"
}


//This function creates markers for the map
function createMarker(point, filename, markerOptions) {
  // Create a lettered icon for this point using our icon class
  var marker = new google.maps.Marker(point, markerOptions);                                                                                                               
  google.maps.Event.addListener(marker, "click", function() {
  marker.openInfoWindowHtml(filename);});
  return marker;
}              

// Call this function when the page has been loaded
function initialize(zoomlevel, centerLat, centerLong, markers, target) {
  if (GBrowserIsCompatible()) {
    function createMap() {  
      // cheat code javascript:void(prompt('',gApplication.getMap().getCenter()));
      var map = new google.maps.Map2(document.getElementById(target));
      var center = new google.maps.LatLng(centerLat, centerLong);
      map.setCenter(center, zoomlevel);
      
      
      //Create Map Controls
      var mapTypeControl = new google.maps.SmallMapControl();
      var topRight = new google.maps.ControlPosition(G_ANCHOR_BOTTOM_RIGHT, new google.maps.Size(10,50));
      var bottomRight = new google.maps.ControlPosition(G_ANCHOR_BOTTOM_RIGHT, new google.maps.Size(10,20));
      map.addControl(mapTypeControl, topRight);
      map.addControl(new google.maps.MapTypeControl(), bottomRight);
      
      //kml overlay
                                                      
      // Create our "ptp" marker icon
      var PTPIcon = new GIcon();
      PTPIcon.image = "http://www.studentambassadors.org/maps_data/PTPmarker.png";
      PTPIcon.shadow = "http://www.studentambassadors.org/maps_data/shadow50.png";
      PTPIcon.iconSize = new GSize(20, 34);
      PTPIcon.shadowSize = new GSize(37, 34);
      PTPIcon.iconAnchor = new GPoint(9, 34);
      PTPIcon.infoWindowAnchor = new GPoint(9, 2);
      PTPIcon.infoShadowAnchor = new GPoint(18, 25);
      
      // Set up our GMarkerOptions object literal
      markerOptions = { icon:PTPIcon };
      
      
      //Load Markers from XML
      var linepoints = new Array;
      for (var i = 0; i < markers.length; i++) {
        var name = markers[i][2];
        var point = new google.maps.LatLng(parseFloat(markers[i][0]),
                                parseFloat(markers[i][1]));
        var marker = createMarker(point, name, markerOptions);
        linepoints[i] = point;
        map.addOverlay(marker);
      }
      // Create Polyline
      var polyline = new google.maps.Polyline(linepoints, "#003366", 4);
      map.addOverlay(polyline);
    }
    //End createMap();
    createMap();
  }
}


function showResultsDiv(resultsDiv, tab) { 
 //get resultsDiv element
 var theDiv = document.getElementById(resultsDiv);
 
 //make sure all div's are hidden
 var allDivs = document.getElementById('DestinationGroup').getElementsByTagName('div');
 for(i=0; i<allDivs.length; i++){
     if(allDivs[i].className == "DestinationContainer")
      allDivs[i].style.display = "none";
 }
 
 //show appropriate div
 theDiv.style.display = "block";
 
 //reset tabbed nav
  var tabsA = document.getElementById('nav2').getElementsByTagName('a');
  var tabsS = document.getElementById('nav2').getElementsByTagName('span');
 
 for(i=0; i<tabsA.length; i++){
  tabsA[i].className = "off";
  tabsS[i].className = "off";
 }
 //set current tab state
 tab.className = "on";
 tab.firstChild.className = "on";
}

function getQueryString () {
 var querystring = new Array;
 //parse current url into an array with the keys/values
 var location = String (document.location);
 var index = location.indexOf('?');
 if (!index && index==0) return false;
 var q = location.substring(index, location.length);
 //var replaceString = ;
 q = q.replace(/\?/g, "&");
 q = q.split('&');
 for (var i = 0 ; i < q.length; i++)
 {
   //for each key/value, split them at the '=' 
   //and add them to the querystring array
   var o = q[i].split('=');
   querystring[o[0]] = o[1];
 }

 //return the querystring
 return querystring;
}

function setTab() {
  var qs = getQueryString();
  if(qs['tab']) {
    switch(qs['tab']) {
      case '1':
        showResultsDiv('AtAGlanceContainer', document.getElementById('AtAGlanceTab').firstChild);
        break;
      case '2':
        showResultsDiv('ItineraryDetailContainer', document.getElementById('ItineraryDetailTab').firstChild);
        break;
      case '3':
        showResultsDiv('MapContainer', document.getElementById('MapTab').firstChild);
        break;
      case '4':
        showResultsDiv('GetStartedContainer', document.getElementById('GetStartedTab').firstChild);
        break;
    }
  }
}
