//<![CDATA[

	var map;
    var geocoder;
	var placeName;
	
	var sportsparksX = null;
	var buildingsX = null;
	var landmarksX = null;
	var centerslocationsX = null;
	var parkingX = null;
	var mapstylesX = null;
	var housingX = null;
	var handiparkingX = null;
	var visitorparkingX = null;
	var emergencyphoneX = null;
	var wifiX = null;
	var computerlabsX = null;
	var diningX = null;
	
	//var string path name
	
	var sportsparksPath = "http://www.tarleton.edu/virtualtour/sportsparks.xml";
	var buildingsPath = "http://www.tarleton.edu/virtualtour/buildings.xml";
	var landmarksPath = "http://www.tarleton.edu/virtualtour/landmarks.xml";
	var centerslocationsPath = "http://www.tarleton.edu/virtualtour/centerslocations.xml";
	var parkingPath = "http://www.tarleton.edu/virtualtour/parking.xml";
	var mapstylesPath = "http://www.tarleton.edu/virtualtour/mapstyles.xml";
	var housingPath = "http://www.tarleton.edu/virtualtour/housing.xml";
	var handiparkingPath = "http://www.tarleton.edu/virtualtour/handicapparking.xml";
	var visitorparkingPath = "http://www.tarleton.edu/virtualtour/visitorparking.xml";
	var emergencyphonePath = "http://www.tarleton.edu/virtualtour/emergencyphone.xml";
	var wifiPath = "http://www.tarleton.edu/virtualtour/wifi.xml";
	var computerlabsPath = "http://www.tarleton.edu/virtualtour/computerlabs.xml";
	var diningPath = "http://www.tarleton.edu/virtualtour/dining.xml";
	
	var marker;
	var overlayInstance = null;
	var map;
	var client;
	var lastMarkerLocation;
	var panorama;
	
	
	
    function load() {
		
		client = new GStreetviewClient();
		var options = {
			suppressInitialResultSelection : true,
			showOnLoad : true,
			searchFormHint : "search TSU", 
			resultList : document.getElementById('results')
			};
		
      	if (GBrowserIsCompatible()) 
		{
			
			// Create and Center a Map
			map = new GMap2(document.getElementById("map_canvas"), {googleBarOptions: options}); 
			latlng = new GLatLng(32.214748, -98.214323);
			
			var guyIcon = new GIcon(G_DEFAULT_ICON);
  			guyIcon.image = "http://maps.google.com/intl/en_us/mapfiles/cb/man_arrow-0.png";
  			guyIcon.transparent = "http://maps.google.com/intl/en_us/mapfiles/cb/man-pick.png";
  			guyIcon.imageMap = [26,13, 30,14, 32,28, 27,28, 28,36, 18,35, 18,27, 16,26, 16,20, 16,14, 19,13, 22,8];
 			guyIcon.iconSize = new GSize(49, 52);
  			guyIcon.iconAnchor = new GPoint(25, 35);  // near base of guy's feet
  			guyIcon.infoWindowAnchor = new GPoint(25, 5);  // top of guy's head
			
			map.setCenter(latlng, 15);
			 
			map.addControl(new GSmallMapControl());
			map.addControl(new GMapTypeControl());
			map.addControl(new GOverviewMapControl());
			map.enableGoogleBar();
			map.enableScrollWheelZoom();
			
		
			
			
			
			
			/*GEvent.addListener(map, "moveend", function() 
			{
          		var center = map.getCenter();
          		document.getElementById("message").innerHTML = center.toString();
        	});*/
			
			geocoder = new GClientGeocoder();
	
			//Find Lat and Long.
			/*GEvent.addListener(map,"click", function(overlay,latlng)
			{     
				var myHtml = "The GLatLng value is: " + latlng;
				document.getElementById("message").innerHTML = myHtml.toString();
			 });*/
					
			sportsparksX = new GGeoXml(sportsparksPath);
			buildingsX = new GGeoXml(buildingsPath);
			landmarksX = new GGeoXml(landmarksPath);
			centerslocationsX = new GGeoXml(centerslocationsPath);
			parkingX = new GGeoXml(parkingPath);
			mapstylesX = new GGeoXml(mapstylesPath);
			housingX = new GGeoXml(housingPath);
			handiparkingX = new GGeoXml(handiparkingPath);
			visitorparkingX = new GGeoXml(visitorparkingPath);
			emergencyphoneX = new GGeoXml(emergencyphonePath);
			wifiX = new GGeoXml(wifiPath);
			computerlabsX = new GGeoXml(computerlabsPath);
			diningX = new GGeoXml(diningPath);
			
			initializeMapOverlays();
			
			
			
			marker = new GMarker(latlng, {icon: guyIcon, draggable: true});
  			map.addOverlay(marker); /* Streetview Marker */
 	 		lastMarkerLocation = latlng;
			
			GEvent.addListener(marker, "dragend", onDragEnd);
  			GEvent.addListener(marker, "click", openPanoramaBubble);
			/*toggleOverlay();*/

		}
		else
		{
			document.write("<p>Unable to display the Google Map.</p>");
		}
    }
	
	/*---------- StreetViewControl -----------------*/
	
	function openPanoramaBubble() 
	{
		  var contentNode = document.createElement('div');
		  contentNode.style.textAlign = 'center';
		  contentNode.style.width = '500px';
		  contentNode.style.height = '300px';
		  contentNode.innerHTML = 'Loading panorama';
		 
		  var smallNode = document.createElement('div');
		  smallNode.style.width = '300px';
		  smallNode.style.height = '250px';
		  smallNode.id = 'pano';
		  marker.openInfoWindow(smallNode, {maxContent: contentNode, maxTitle: "Full screen"});
		 
		  panorama = new GStreetviewPanorama(smallNode);
		  panorama.setLocationAndPOV(marker.getLatLng(), null);
		  GEvent.addListener(panorama, "newpano", onNewLocation);
		  GEvent.addListener(panorama, "yawchanged", onYawChange); 
		 
		  var iw = map.getInfoWindow();
		  GEvent.addListener(iw, "maximizeend", function() 
			{
				panorama.setContainer(contentNode);  
				window.setTimeout("panorama.checkResize()", 5);
		  	});
		  GEvent.addListener(iw, "closeclick", function()
			{
				panorama.remove();
		  	});
	}
	
	function toggleOverlay() {
  if (!overlayInstance) {
    overlayInstance = new GStreetviewOverlay();
    map.addOverlay(overlayInstance);
  } else {
    map.removeOverlay(overlayInstance);
    overlayInstance = null;
  }
}
	 
	function onYawChange(newYaw) {
	  var GUY_NUM_ICONS = 16;
	  var GUY_ANGULAR_RES = 360/GUY_NUM_ICONS;
	  if (newYaw < 0) {
		newYaw += 360;
	  }
	  guyImageNum = Math.round(newYaw/GUY_ANGULAR_RES) % GUY_NUM_ICONS;
	  guyImageUrl = "http://maps.google.com/intl/en_us/mapfiles/cb/man_arrow-" + guyImageNum + ".png";
	  marker.setImage(guyImageUrl);
	}
	 
	function onNewLocation(lat, lng) {
	  var newLatLng = new GLatLng(lat, lng);
	  marker.setLatLng(newLatLng);
	}
	 
	function onDragEnd() {
	  var newLatLng = marker.getLatLng();
	  if (panorama) {
		client.getNearestPanorama(newLatLng, onResponse);
		marker.setLatLng(newLatLng);
		lastMarkerLocation = newLatLng;
		openPanoramaBubble();
	  }
	}
	 
	function onResponse(response) {
	  if (response.code != 200) {
		marker.setLatLng(lastMarkerLocation);
	  } else {
		var newLatLng = new GLatLng(response.Location.lat, response.Location.lng);
		marker.setLatLng(newLatLng);
		lastMarkerLocation = newLatLng;
		openPanoramaBubble();
	  }
	}
	
	/* ------------ END StreetViewControl ------------------------ */
	
	function initializeMapOverlays()
	{
		newToggleMarkers(sportsparksX, 'sportsparksXbox');
		newToggleMarkers(landmarksX, 'landmarksXbox');
		newToggleMarkers(buildingsX, 'buildingsXbox'); 
		newToggleMarkers(centerslocationsX, 'centerslocationsXbox'); 
		newToggleMarkers(parkingX, 'parkingXbox'); 
		newToggleMarkers(housingX, 'housingXbox'); 
		newToggleMarkers(handiparkingX, 'handiparkingXbox');
		newToggleMarkers(visitorparkingX, 'visitorparkingXbox');
		newToggleMarkers(emergencyphoneX, 'emergencyphoneXbox');
		newToggleMarkers(wifiX, 'wifiXbox');
		newToggleMarkers(computerlabsX, 'computerlabsXbox');
		newToggleMarkers(diningX, 'diningXbox');
		map.addOverlay(mapstylesX);
		
	}
	
	function newPrintLandmarks(markerType)
	{
		try //Internet Explorer
		{
		  	xmlDoc=new ActiveXObject("Microsoft.XMLDOM");
		}
		catch(e)
		{
			try //Firefox, Mozilla, Opera, etc.
			{
				xmlDoc=document.implementation.createDocument("","",null);
			}
			catch(e)
			{
				alert(e.message);
				return;
			}
		}
		xmlDoc.async=false;
		xmlDoc.load(markerType);
			
		var points=xmlDoc.getElementsByTagName("Placemark");
		document.write("<ul>&#10;");
		for (var i = 0; i < points.length; i++) 
		{
			
			var latlngPoint = points[i].getElementsByTagName("coordinates")[0].childNodes[0].nodeValue;
			var latlngXY = latlngPoint.split(",");
			var lat = latlngXY[0];
			var lng = latlngXY[1];
				
			var nameStr = points[i].getElementsByTagName("name")[0].childNodes[0].nodeValue;
			
			/*document.write("<li><a href='#'");
			document.write(" onclick=\"findLocation(");
			document.write("'");
			document.write(lng);
			document.write(",");
			document.write(lat);
			document.write("'");
			document.write(", ");
			document.write("'");
			document.write(nameStr);
			document.write("'");
			document.write(");return false;\">");
			document.write(nameStr);
			document.write("</a></li>&#10;");*/
			
			document.write("<li><a href=\"#\"");
			document.write(" onclick=\"findLocation(");
			document.write("&#39;");
			document.write(lng);
			document.write(",");
			document.write(lat);
			document.write("&#39;");
			document.write(", ");
			document.write("&#39;");
			document.write(nameStr);
			document.write("&#39;");
			document.write(");return false;\" >");
			document.write(nameStr);
			document.write("</a></li>&#10;");
		}
		document.write("</ul>&#10;");
	}
	
	function newToggleMarkers(markerType, idCheckbox)
	{
		if (document.getElementById(idCheckbox).checked == true)
		{
			
			addMarkers(markerType);			
		}
		else
		{
			
			removeMarkers(markerType);			
		}
	}
	
	function toggleMarkers(markerType, idCheckbox)
	{
		if (document.getElementById(idCheckbox).checked == true)
		{
			/*alert("if checked = " + document.getElementById(idCheckbox).checked);*/
			addMarkers(markerType);			
			document.getElementById(idCheckbox).checked = true;
			/*alert("if checked = " + document.getElementById(idCheckbox).checked);*/
		}
		else
		{
			/*alert("else checked = " + document.getElementById(idCheckbox).checked);*/
			removeMarkers(markerType);			
			document.getElementById(idCheckbox).checked = false;
			/*alert("else checked = " + document.getElementById(idCheckbox).checked);*/
		}
	}
	
	function removeMarkers(nameMarkerType)
	{
		map.removeOverlay(nameMarkerType);
	}
	
	function addMarkers(nameMarkerType)
	{
		map.addOverlay(nameMarkerType);
	}
	
	function removeAllMarkers()
	{
		map.clearOverlays();
	}

	// addAddressToMap() is called when the geocoder returns an
    // answer.  It adds a marker to the map with an open info window
    // showing the nicely formatted version of the address and the country code.
    function addAddressToMap(response) 
	{
		if (!response || response.Status.code != 200) 
		{
			alert("Sorry, that location is currently unavailable.");
		} 
		else 
		{
			place = response.Placemark[0];
			point = new GLatLng(place.Point.coordinates[1],
								place.Point.coordinates[0]);
			var myHtml = "<p><strong>" + placeName + "</strong></p>";
			map.openInfoWindow(point, myHtml);
		}
    }
	
	// showLocation() is called when you click on the Search button
    // in the form.  It geocodes the address entered into the form
    // and adds a marker to the map at that location.
    function showLocation() {
      var address = document.forms[0].goog.value;
      geocoder.getLocations(address, addAddressToMap);
    }
	
	// findLocation() is used to enter the sample addresses into the form.
    function findLocation(address, name) {
      document.forms[0].goog.value = address;
      showLocation();
	  placeName = name;
	  geocoder.getLocations(address, addAddressToMap);
    }
	
    //]]>