// JavaScript Document
// prod dir key: ABQIAAAAd8Icg8vbMub9Bu1jGPgYBhT0AePcYkmOrAPZ3EkPsejYrGWUNxTvXTBU_dmsiHUN8BeuzfAWC54ITw
// beta dir key: ABQIAAAAd8Icg8vbMub9Bu1jGPgYBhRAmHyHKf8BIHFiQ8yuC6i5FII6YRQq0tGWlBaqb1vpwJzerOUaEQoOeQ
//var IconIndex = 0;
//var Search_Results = new Array();
//var fred;
//var marks = new Array();
//var parkData = new Array();
//var search_marks = new Array();
//var sched_array = new Array();
//var bmap = new Array();
//var Search_HTML = "";
var blistMode = "";
var findUnique = false;
var blistOn = false;

//NEW VARS
var ufFeatures = new Array();
var loadedFeatures = new Array();
var currentFeatureCnt = 0;
var polyFeatutePnts = new Array();
var baseIcon;
var leedIcon;
var treeIcon;
var aedIcon;
var pcbIcon;
var clearMapInfo = true;
var ImOn = new Array();
var request;
var map;
var h;
var meActive = new Array("Feature", 0);
//var for calculate dist functions
var dist_mode = false;
var dbl_event;
var distArray = new Array();
var distTotal = 0;
var distType = "feet";
var distMulti = 3.2808399;

//MAIN INIT FUNCTION/MAP FUNCTIONALITY
	function init( center, zoom, html ) {
		// ***** Use SVG to draw and fill polygons
		//_mSvgEnabled = true;
		//_mSvgForced = true;
		
		if (center == null){
			var center = new GLatLng(29.639947397183935,-82.35600471496582);
			var zoom = 14;
		}
		
		h = document.getElementById("mapinfo");
		
		if (html != null){
			h.innerHTML = html;
		}
		
		map = new GMap2(document.getElementById("map"));
		
		GEvent.addListener(map, "click", function(overlay, spot) {
			if (!dist_mode){
				if (document.queries.searchfor.value == "FWP"){
					alert("You clicked on "+spot);
				} else {
					find_item_new( spot );
				}
			}
		});
	
		var copyright = new GCopyright(1, new GLatLngBounds(new GLatLng(-90,-180), new GLatLng(90,180)),14,"&copy;2006 University of Florida");
		var copyrightCollection = new GCopyrightCollection('UF');
		copyrightCollection.addCopyright(copyright);
		var tilelayers = [new GTileLayer(copyrightCollection,14,18)];
		tilelayers[0].getTileUrl = CustomGetTileUrl;
		
		function CustomGetTileUrl(a,b) {
			//if (b==18){
				//alert("X: "+a.x+" Y: "+a.y+" Z: "+b);
			//}
			var f = "/gmaptiles/x"+a.x+"y"+a.y+"z"+b+".gif";
			return f;
		}
		
		var custommap = new GMapType(tilelayers, new GMercatorProjection(19),"UF", {errorMessage:"No data available"});
		map.addMapType(custommap);
		
		map.addControl(new GLargeMapControl());
		map.addControl(new GScaleControl());
		map.addControl(new GMapTypeControl());
		
		map.setCenter(center, zoom);
		map.setMapType( custommap );
		//map.addControl(new GOverviewMapControl(), new GControlPosition(G_ANCHOR_BOTTOM_RIGHT, new GSize(10, 10)));	
		// Create a base icon for all of our markers that specifies the
		// shadow, icon dimensions, etc.
		makeBaseIcon();
		makeLeedBaseIcon();
		makeTreeBaseIcon();
		makePCBBaseIcon();
		//Create a place holder for spot click finds
		addToUfFeatures( "spot", "PNT", 0, 0, "", "", "", "N", "" );
		logFeature("spot",1, "PNT", "", "", "Clicked Feature");
		ClearMap();
	
		request = GXmlHttp.create();
		//request.open("GET", "ufcampusz.xml", true);
		request.open("GET", "ufcampus_sde.xml", true);
		request.onreadystatechange = function() {
			if (request.readyState == 4) {
				//alert(request.responseText);
			}
		}
		request.send(null);
	}//end init


	function find_item_new( spot ){ //This uses the new XML
		if (spot == undefined){ //This prevent the x js error
			return;
		}
		var xmlDoc = request.responseXML;
		var looking = xmlDoc.documentElement.getElementsByTagName("*");
		var xoffset = 100;
		var yoffset = 100;
		var x = spot.x;
		var y = spot.y;
		x = x*1;
		y = y*1;
		var tempArray = new Array();
		ClearMap(true);
		
			for (b = 0; b < looking.length; b++){
				var lng = looking[b].getAttribute("lng");
				var lat = looking[b].getAttribute("lat");
	
				lat = lat*1;
				lng = lng*1;
				var dify = (y-lat);
				var difx = (x-lng);
				dify = Math.abs(dify);
				difx = Math.abs(difx);
				var ave_dif = (difx + dify)/2;
				var ave_offset = ((xoffset*1) + (yoffset*1))/2;
					if (ave_dif < ave_offset){
						var sustain = "NA";
						var url = "NA";
						var descrip = "";
						yoffset = dify;
						xoffset = difx;
						if (looking[b].getAttribute("id").length > 1){
							descrip = "Bldg Number: "+looking[b].getAttribute("id");
							if (looking[b].getAttribute("t") != " ") descrip += "<br>"+looking[b].getAttribute("t");
							descrip += "<br><a href=\"http://campusmap.ufl.edu/details.php?bldg="+looking[b].getAttribute("id")+"\" target=\"_blank\">Building Information</a>";
						} else {
							descrip = looking[b].getAttribute("t");
						}
						if (looking[b].getAttribute("g") == 'Y') sustain = 'Y';
						if (looking[b].getAttribute("u") != ' ') url = looking[b].getAttribute("u");
						tempArray = [looking[b].getAttribute("id"),looking[b].getAttribute("n"),looking[b].getAttribute("lat"),looking[b].getAttribute("lng"),descrip, url, sustain];
					}
			}
			var myPoint = new GLatLng(tempArray[2],tempArray[3]);
			ufFeatures[0][2] = myPoint;
			ufFeatures[0][4] = tempArray[1];
			ufFeatures[0][5] = tempArray[4];
			ufFeatures[0][6] = tempArray[5];
			ufFeatures[0][8] = tempArray[3];
			ufFeatures[0][9] = tempArray[2];
			ufFeatures[0][10] = tempArray[6]; //sustainable
			showUfFeatures( "spot", 0 );
	} //end find_item_new

	function searchmap(){
		var s = document.queries.searchfor.value;
		ClearMap( true );
		if (s=='PPDMan'){
			alert("Manholes Alive!");
			 xajax_showManholes();
		}//end if
		else
			LocateTextNew(s.toUpperCase());
	}//end searchmap
	function LocateTextNew( str, zoomLvl ){ //new function to search the XML

		var searchKey = "search:"+str;
		setFeatureStart();
		var cnt = 0;
		
		var isLoaded = checkLoad( searchKey );
		if (isLoaded) {
			showUfFeatures( searchKey );
			return;
		}

		var xmlDoc = request.responseXML;
		var looking = xmlDoc.documentElement.getElementsByTagName("*");
		var bnum = padme(str);
		
		for (b = 0; b < looking.length; b++){ //search the entire xml doc
			var sustain = "NA";
			var url = "NA";
			if ((looking[b].getAttribute("id") == bnum) || (looking[b].getAttribute("n").toUpperCase().indexOf(str) >= 0) || (looking[b].getAttribute("s").toUpperCase().indexOf(str) >= 0) || (looking[b].getAttribute("t").toUpperCase().indexOf(str) >= 0) ){
				var descrip = "";
				if (looking[b].getAttribute("id").length > 1){
					descrip = "Bldg Number: "+looking[b].getAttribute("id");
					if (looking[b].getAttribute("t") != " ") descrip += "<br>"+looking[b].getAttribute("t");
					descrip += "<br><a href=\"http://campusmap.ufl.edu/details.php?bldg="+looking[b].getAttribute("id")+"\" target=\"_blank\">Building Information</a>";
				} else {
					descrip = looking[b].getAttribute("t");
				}
				if (looking[b].getAttribute("g") == 'Y') sustain = 'Y';
				if (looking[b].getAttribute("u") != ' ') url = looking[b].getAttribute("u");
				cnt++;
				addToUfFeatures( searchKey, "PNT", looking[b].getAttribute("lat"), looking[b].getAttribute("lng"), looking[b].getAttribute("n"), descrip, url, sustain);
			} // end if
		} // end for
		logFeature(searchKey, cnt, "PNT");
		showUfFeatures(searchKey);
		if (zoomLvl != undefined){
			ZoomToObject(searchKey, zoomLvl);
		}
	}
	
	function ZoomToObject(searchKey, zoomLvl){
		zoomLvl = zoomLvl*1;
		var i = 0;
		for (i=0; i<ufFeatures.length; i++){ //ufFeatures.length
			if (ufFeatures[i][0] == searchKey){
				map.setZoom(zoomLvl);
				map.panTo(ufFeatures[i][2]);
			}//end if
		}//end for
		
	}//end of function ZoomToObject
	
	function padme( s ){
		if (s.length < 4){
			var z = 0;
			for (z = s.length; z <= 3; z++){
				s='0'+s;
			}
		}
		return s;
	}
	function ClearMap( clearChecks ){
		if (clearChecks == null){
			clearChecks = false;
		}
		h.innerHTML = "";
		//IconIndex = 0;
		map.clearOverlays();
		//marks = new Array();
		//search_marks = new Array();
		//Search_HTML = "";
		
		if (clearChecks){
			document.transpoform.reset();
			document.naturalform.reset();
			document.cultureform.reset();
			document.sportsform.reset();
			document.clform.reset();
			document.technoform.reset();
			toggleLayerStatus('parking', 'off');
		}//end if
		if (dist_mode){ ClearDist(); }
		//ajaxpage('welcome.htm', 'mapinfo');
	}//end ClearMap
	function LoadPano( panoid ){
		var URL = "http://www.ufspace.ufl.edu/gis/panotour/pano.jsp?panoid="+panoid;
		window.open(URL,'panowindow','scrollbars=no,width=720,height=485');
	}//end LoadPano
	function BldgInfo( bldg ){
		var URL = "details.php?bldg="+bldg;
		window.open(URL,'panowindow','scrollbars=no,width=720,height=620');
	}//end BldgInfo
	function FindBldg( bldg ){
		var foundit = false;
		var xmlDoc = request.responseXML;
		var looking = xmlDoc.documentElement.getElementsByTagName("Z");
		for (b = 0; b < looking.length; b++){
			if (looking[b].getAttribute("ot") == "BLD"){
				if (looking[b].getAttribute("abv") == bldg){
					foundit = true;
					var tempArray = [looking[b].getAttribute("id"),looking[b].getAttribute("abv"),looking[b].getAttribute("name"),looking[b].getAttribute("lat"),looking[b].getAttribute("lng"),"SCHD",looking[b].getAttribute("sk")," "," "," "];
				} // end if
			}
		}
		if (foundit) { return tempArray; }
	}//end FindBldg
	function PrintMap(){
		//alert("Search Results is: "+Search_Results.length);
		printzoom =  map.getZoom();
		printcenter = map.getCenter();
		var newwindow = window.open('printmap.php',"printwindow");
		newwindow.focus();
	}//end PrintMap	
	function ShowBlist( mode ){ //Loads the pick lists
		if (blistMode != mode){
			document.locate.sblist.options.length = 0;
			blistMode = mode;
			if (mode == "BLDG"){
				document.locate.alist.checked = false;
			} else {
				document.locate.blist.checked = false;
			}
		}
		//DispMessage("<hr><strong>Generating building list, please wait...</strong>");
		if ((!document.locate.blist.checked || !document.locate.alist.checked) && !blistOn){
			//toggleLayer('dblist');
			blistOn = true;
		} else 	if (!document.locate.blist.checked && !document.locate.alist.checked && blistOn){
			//toggleLayer('dblist');
			blistOn = false;
		}
	
		if (document.locate.sblist.options.length == 0){
			BuildBldgList();
		}
			h.innerHTML = "<hr><strong>Select building name from list to display on map.</strong>";
	}//end showBlist
//END FUNCTIONS NEEDING TO BE REVIEWED/UPDATED/DELETED ETC
	function FindBldg(){
		var theBldg = document.locate.sblist.options[document.locate.sblist.selectedIndex].value;
		
		if (blistMode == "ABBREV"){
			var tosp=theBldg.indexOf(' ');
			theBldg = '('+theBldg.substr(0,tosp)+')';
		}
		findUnique = true;
		LocateTextNew(theBldg);
		findUnique = false;
	}//end FindBldg
	function DispMessage(message){
		h.innerHTML = message;
	}//end DispMessage
	function BuildBldgList(){
			var theList = new Array();
			var xmlDoc = request.responseXML;
			var looking = xmlDoc.documentElement.getElementsByTagName("*");
				for (b = 0; b < looking.length; b++){
					if (blistMode == "BLDG"){
						if (looking[b].getAttribute("id").length > 1 ){
							theList.push(looking[b].getAttribute("n"));
						}
					} else {
						var xHere = looking[b].getAttribute("n").indexOf('- (')+3;
						var zHere = looking[b].getAttribute("n").lastIndexOf(')');
						
						if (xHere > 3){
							theList.push(looking[b].getAttribute("n").substring(xHere, zHere)+' - '+looking[b].getAttribute("n").substring(0,xHere-3));
						}
					}
				}
			
			theList.sort();
			
			for (b=0;b<theList.length;b++){
				document.locate.sblist.options[b] = new Option(theList[b],theList[b]);
			}
	}//end BuildBldgList

//ICON CREATION
	function makeBaseIcon(){
		baseIcon = new GIcon();
		baseIcon.shadow = "http://www.google.com/mapfiles/shadow50.png";
		baseIcon.iconSize = new GSize(20, 34);
		baseIcon.shadowSize = new GSize(37, 34);
		baseIcon.iconAnchor = new GPoint(9, 34);
		baseIcon.infoWindowAnchor = new GPoint(9, 2);
		baseIcon.infoShadowAnchor = new GPoint(18, 25);
	}//end makeBaseIcon
	function makeLeedBaseIcon(){
		leedIcon = new GIcon();
		leedIcon.shadow = "/library/images/none.gif";
		leedIcon.iconSize = new GSize(25, 25);
		leedIcon.shadowSize = new GSize(37, 34);
		leedIcon.iconAnchor = new GPoint(9, 34);
		leedIcon.infoWindowAnchor = new GPoint(9, 2);
		leedIcon.infoShadowAnchor = new GPoint(18, 25);	
	}//end makeLeedBaseIcon	
	function makeTreeBaseIcon(){
		treeIcon = new GIcon();
		treeIcon.shadow = "/library/images/none.gif";
		treeIcon.iconSize = new GSize(30, 30);
		treeIcon.shadowSize = new GSize(37, 34);
		treeIcon.iconAnchor = new GPoint(9, 34);
		treeIcon.infoWindowAnchor = new GPoint(9, 2);
		treeIcon.infoShadowAnchor = new GPoint(18, 25);	
	}//end makeTreeBaseIcon	
	function makeAEDBaseIcon(){
		aedIcon = new GIcon();
		aedIcon.shadow = "/library/images/none.gif";
		aedIcon.iconSize = new GSize(17, 15);
		aedIcon.shadowSize = new GSize(17, 15);
		aedIcon.iconAnchor = new GPoint(9, 34);
		aedIcon.infoWindowAnchor = new GPoint(9, 2);
		aedIcon.infoShadowAnchor = new GPoint(18, 25);	
	}//end makeAEDBaseIcon
	function makePCBBaseIcon(){
		pcbIcon = new GIcon();
		pcbIcon.shadow = "/library/images/none.gif";
		pcbIcon.iconSize = new GSize(15, 15);
		pcbIcon.shadowSize = new GSize(15, 15);
		pcbIcon.iconAnchor = new GPoint(0, 0);
		pcbIcon.infoWindowAnchor = new GPoint(9, 2);
		pcbIcon.infoShadowAnchor = new GPoint(18, 25);	
	}//end makePCBBaseIcon
//END ICON CREATION

//GENERIC MAP/MARKER/HTML/ARRAY FUNCTIONS
	function AddPolyPnts( x, y ){ //use to populate generic poly points
		var point = new GLatLng(parseFloat(x),parseFloat(y));
		polyFeatutePnts.push( point );
	}//end AddPolyPnts	
	function ClearPolyPnts(){ //use to clear points from poly array
		polyFeatutePnts = new Array();
	}//end ClearPolyPnts	
	function AddPolyFeatures(fclass, ftype, strokeColor,  strokeWeight,  strokeOpacity,  fillColor,  fillOpacity){
		if (ftype = "PGON"){
			var thisPolygon = new GPolygon(polyFeatutePnts, strokeColor,  strokeWeight,  strokeOpacity,  fillColor,  fillOpacity);
			var tempArray = [fclass, ftype, "na", 0, "na", "na", "na", thisPolygon, 0, 0];
		} else {
			var thisPolyline = new GPolyline(polyFeatutePnts, strokeColor, strokeWeight, strokeOpacity);	
			var tempArray = [fclass, ftype, "na", 0, "na", "na", "na", thisPolyline, 0, 0];
		}
		ufFeatures.push(tempArray);
	}//end AddPolyFeatures
	function addToUfFeatures( fclass, ftype, y, x, name, descrip, url, sustain, icon, url2 ){
		if (sustain == undefined) sustain = "NA";
		if (url2 == undefined) url2 = "NA";
		var point = new GLatLng(parseFloat(y),parseFloat(x));
		var tempArray = [fclass, ftype, point, 0, name, descrip, url, "ZZ", x, y, sustain, icon, url2];
		ufFeatures.push(tempArray);
	}//end addToUfFeatures
	function logFeature(fclass, cnt, type, url, limit, label){
		if (url == undefined||url=='') url = "na";
		if (limit == undefined||limit=='')	limit = "Y";
		if (label == undefined) label = fclass;
		loadedFeatures.push([fclass, currentFeatureCnt, cnt, type, url, limit, label]);
	}//end logFeature
	function showUfFeatures( fclass, startRow ){
	
		var mapHTML = "";
		var displayStart = 1;
		var featureStats = locateStats( fclass );
		var arrayStart = featureStats[1]*1;
		var totalElements = featureStats[2]*1;
		var type = featureStats[3];
		var limit = featureStats[5];
		var label = featureStats[6];
		var endRow = 0;
		var endDisplayRow = 0;
		var prevHTML = "";
		var nextHTML = "";
		var showHTML = true;
		
		if (startRow == undefined) startRow = arrayStart;
			startRow = startRow*1;
			if (type == "PNT" && limit == "Y"){
			
			if (startRow >= arrayStart) removeUfFeatures(fclass);
			if (startRow+10 > arrayStart+totalElements) endRow = arrayStart+totalElements;
			else endRow = startRow+10;
			if (startRow > featureStats[1]) displayStart = startRow - featureStats[1];
		
			if (featureStats[2] > 10){
				endDisplayRow = startRow-arrayStart+10;
				if (startRow > arrayStart)
					prevHTML = "<strong><a href=\"javascript:showUfFeatures('"+fclass+"',"+(startRow-10)+")\">&lt;&lt;Previous</a></strong>";
				if (endRow != (arrayStart+totalElements))
					nextHTML = "<strong><a href=\"javascript:showUfFeatures('"+fclass+"',"+endRow+")\">Next>></a></strong>";
			}//end if over 10
			else endDisplayRow = totalElements;
		
			mapHTML = "<div class=\"infohead\"><table width=\"100%\"><tr><td colspan=\"3\"><div align=\"center\"><strong>"
						+label+"</strong></div></td></tr><tr><td width=\"33%\"><div align=\"left\">"+prevHTML;
			mapHTML += "</td><td width=\"33%\"><center>"+(startRow-arrayStart+1)+" - "+(endDisplayRow)
					+" of "+totalElements+"</center></td><td width=\"33%\"><div align=\"right\">"+nextHTML;
			mapHTML += "</div></td></tr></table></div><br>";
		
		} else endRow = arrayStart + totalElements;
		
		meActive[0,0] = fclass;
		meActive[0,1] = startRow;
		//alert("StartRow = "+startRow+" EndRow = "+endRow);
		var j = 0;

		for (i=(startRow*1); i<endRow; i++){ //ufFeatures.length
			if (ufFeatures[i][0] == fclass){
				if (ufFeatures[i][1] == "PNT"){
					var letter = String.fromCharCode("A".charCodeAt(0) + j++);
					mapHTML += makeMapHTML(ufFeatures[i], letter);
					var iconHTML = makeHTML(ufFeatures[i]);
					ufFeatures[i][7] = makeMarkerNew(ufFeatures[i], letter, iconHTML);
				} else showHTML = false;
				map.addOverlay(ufFeatures[i][7]);
			}//end if PNT
		}//end for
		
		if (featureStats[4] != "na") {PlaceTheHTML( featureStats[4] ); }
		if (showHTML && limit == "Y"){
			mapHTML += "";
			PlaceTheHTML( mapHTML );
		}//end if 
	}//endshowUfFeatures
	function removeUfFeatures( fclass, clear ){
		for (i=0; i<ufFeatures.length; i++){
			if (ufFeatures[i][0] == fclass){
				if (ufFeatures[i][7] != "NA"){
					map.removeOverlay(ufFeatures[i][7]);
				}
			}
		}
		if (clear==undefined)
			clear = true;
		clearMapInfo = clear;
		if (clearMapInfo)
			PlaceTheHTML( "" );
			//toggleLayerStatus('mapinfo','off');
	}//end removeUfFeatures
	function FlipOn(myElement, fclass, loadState){
		var i = 0;
		var j = 0;
		if (loadState){
			for (i=0; i<ImOn.length; i++){
				if (ImOn[i][1] != fclass){
					ImOn[i][0].checked = false;
					removeUfFeatures(ImOn[i][1]);
					ImOn.splice(i, 1);
					i = i-1;
				}
			}
			ImOn.push([myElement, fclass]);
		} else {
			for (j=0; i<ImOn.length; j++){
				if (ImOn[j][1] == fclass){
					ImOn.splice(j, 1);
					j = j-1;
				}
			}
		}
	}//end FlipOn
	function locateStats( fclass ){
		for (i=0; i<loadedFeatures.length; i++){
			if (loadedFeatures[i][0] == fclass){
				return loadedFeatures[i];
			}
		}
	}//end locateStats
	function setFeatureStart(){ //determine the starting element of a feature
		currentFeatureCnt = ufFeatures.length;
	}//end setFeatureStart
	function findClassStart( fclass ){ //Locate the start of an element when not known
		for (i=0; i<loadedFeatures.length; i++){
			if (loadedFeatures[i][0] == fclass){
				return i;
			}
		}
		return 0;
	}//end findClassStart
	function makeMarkerNew(tempArray, letter, html) {
	  // Create a lettered icon for this point using our icon class
	  //alert("HTML = "+html);
		var makeHTML = true;
		var icon;
		if (tempArray[0] == "LEED"){
			icon = new GIcon(leedIcon);
			icon.image = "/library/images/leed/"+tempArray[11]+".png";
		} else if (tempArray[0] == "TW") {
			icon = new GIcon(treeIcon);
			icon.image = "/library/images/icons/"+tempArray[11]+".png";
		} else if (tempArray[0] == "PCBs") {
			icon = new GIcon(baseIcon);
			icon.image = "/library/images/markers/largeTDYellowIcons/marker"+tempArray[11]+".png";
		} else if (tempArray[0] == "Disabled Parking" || tempArray[0] == "Parking Meters" || tempArray[0] == "Carpool Zone (Carpool Decal Required)" || tempArray[0] == "Scooter/Motorcycle Zone" || tempArray[0] == "Auto Restricted Area" || tempArray[0] == "BUSSTOP" || tempArray[0] == "PUBLICSAFETY" || tempArray[0] == "PARKBLDG" || tempArray[0] == "Flexcar"){
			icon = new GIcon(baseIcon);
			icon.image = "/library/images/icons/"+tempArray[11]+".png";
			makeHTML = false;
		} else if (tempArray[0]=='Panoramas') {
			icon = new GIcon(baseIcon);
			icon.image = "/library/images/icons/"+tempArray[11]+".png";
		} else if (tempArray[0]=='Manholes') {
			icon = new GIcon(baseIcon);
			//icon.image = "/library/images/bullet.png";
			icon.image = "/library/images/markers/blue_MarkerM.png";
		} else if (tempArray[0].substr(0,7)=='Recycle') {
			icon = new GIcon(baseIcon);
			icon.image = "/library/images/markers/"+tempArray[11]+".png";
		} else if (tempArray[0]=='Conservation Area') {
			icon = new GIcon(baseIcon);
			icon.image = "/library/images/markers/green_Marker" + letter + ".png";
		}  else if (tempArray[0]=='Lakes and Ponds') {
			icon = new GIcon(baseIcon);
			icon.image = "/library/images/markers/blue_Marker" + letter + ".png";
		} else {
			icon = new GIcon(baseIcon);
			if (tempArray[10]=='Y')
				icon.image = "/library/images/markers/green_Marker" + letter + ".png";
			else
				icon.image = "/library/images/icons/marker" + letter + ".png";			
		}//end else
		
		//alert(tempArray[2]);
		var marker = new GMarker(tempArray[2], icon);

		if (makeHTML){
			GEvent.addListener(marker, "click", function() {
				marker.openInfoWindowHtml(html);
			});
		}
		//alert("Returning marker "+marker);
		return marker;
	}//end makeMarkerNew
	function makeHTML( tempArray ){
		var html = "";
		if (tempArray[10] != "NA"){
			html += "<img src=\"../../library/images/icons/ico-06.gif\" />";
		}
		html += "<strong> "+tempArray[4]+"</strong>";
			
		if (tempArray[5] != "NA"){
			html += "<br>"+tempArray[5];
		}
		if (tempArray[12] != "NA"){
			html += "<br><a href='"+tempArray[12]+"' target='_blank'>Building Information</a>";
		}//end if
		if (tempArray[6] != "NA"){
			if (tempArray[0] == "Panoramas"){
				html += "<br><a href=\"javascript:showPano('img=/library/images/pano/"+tempArray[6]+"&horzangle=360&projection=spherical')\">View Panorama</a>";
			} else {
				html += "<br><a href=\"javascript:JumpURL('"+tempArray[6]+"')\">More Information</a>";
			}
		}
		return html;
	}//end makeHTML
	function makeMapHTML( tempArray, letter ){
		var html = "<p>";
		if (tempArray[10] != "NA"){
			html += "<img src=\"../../library/images/icons/ico-06.gif\" />";
		}
			html += "<strong> <a href=\"javascript:panTo("+tempArray[8]+","+tempArray[9]+")\">"+letter+" - "+tempArray[4]+"</a></strong>";
		if (tempArray[5] != "NA"){
			html += "<br>"+tempArray[5];
		}
		if (tempArray[12] != "NA"){
			html += "<br><a href='"+tempArray[12]+"' target='_blank'>Building Information</a>";
		}//end if
		if (tempArray[6] != "NA"){
			html += "<br><a href=\"javascript:JumpURL('"+tempArray[6]+"')\">More Information</a><br>";
		} else {
			html += "<br>";
		}
		html += "<br></p>";
		return html;
	}//end makeMapHTML
	function PlaceTheHTML( infoHTML ){
		h.innerHTML = infoHTML;	
	}//end PlaceTheHTML
	function clearText(){
		h.innerHTML = '';
	}//end removeDecal
//END GENERIC MAP FEATURES

//DISTANCE CALCULATION FUNCTIONS
	function ShowDistance(){
		if (document.calcicon.src==minus.src)
			document.calcicon.src=plus.src;
		else
			document.calcicon.src=minus.src;
		if (dist_mode){
			ClearDist();
		} else {
			ClearMap();
			toggleLayer('distform');
			if (distArray.length < 2){
				h.innerHTML = "<p>In distance mode!<br>Double click to set points on map.</p><br>";
			}
			dist_mode = true;
			dbl_event = GEvent.addListener(map, "dblclick", function(overlay, spot) {
				map.addOverlay(new GMarker(spot));
				distArray.push(spot);
				if (distArray.length > 1){
					//alert("Distance = "+distArray[distArray.length -2].distanceFrom(distArray[distArray.length -1]));
					var thisDist = distArray[distArray.length -2].distanceFrom(distArray[distArray.length -1]);
					distTotal += thisDist;
					var polyline = new GPolyline([distArray[distArray.length -2],distArray[distArray.length -1]], "#ff0000", 5);
					//polyline.F.title = 'Leg '; 
					map.addOverlay(polyline);
					h.innerHTML += "<p>Leg "+(distArray.length -1)+" is "+Math.round(thisDist*distMulti*100)/100+" "+distType+", total distance = "+Math.round(distTotal*distMulti*100)/100+" "+distType+"</p>";
				}
			});
		}
	}//end showDistance
	function ClearDist(){
		dist_mode = false;
		GEvent.removeListener(dbl_event);
		distArray = new Array();
		distTotal = 0;
		if (document.queries.dist){
			document.queries.dist.checked = false;
		}
		toggleLayer('distform');
		ClearMap();	
	}//end ClearDist
	function SetDistType(dtype){
		distType = dtype;
		if (distType == "meters"){
			distMulti = 1;
		} else if (distType == "kilometers"){
			distMulti = (1/1000);
		} else if (distType == "feet"){
			distMulti = 3.2808399;
		} else if (distType == "miles"){
			distMulti = 0.0006213;
		}
		
		if (distArray.length > 1){
			DistHTML( true );	
		}
	}//end SetDistType
	function DistHTML( regen ){
		var fred = "";
		if (regen){
			distTotal = 0;
			 fred = "<p>In distance mode!<br>Double click to set points on map.</p><br>";
			 for (b = 0; b < distArray.length-1; b++){
				 var thisDist = distArray[b].distanceFrom(distArray[b+1]);
				 distTotal += thisDist;
				 fred += "<p>Leg "+(b+1)+" is "+Math.round(thisDist*distMulti*100)/100+" "+distType+", total = "+Math.round(distTotal*distMulti*100)/100+" "+distType+"</p>";
			 }
			h.innerHTML = fred;	
		} else {
			
		}
	}//end DistHTML
//END DISTANCE FUNCTIONS
	
//ZOOMING AND PANOS
	function TreeWalkZoom(){
		var zoom = 18;
		var y = '-82.34583914279938';
		var x = '29.646358110971576';
	
		var center = new GLatLng(x,y);
		map.setCenter(center,zoom);	
	}//end TreeWalkZoom
	function HDZoom(){
		var zoom = 17;
		var y = '-82.34383821487427';
		var x = '29.65039082356072';
	
		var center = new GLatLng(x,y);
		map.setCenter(center,zoom);	
	}//end HDZoom
	function showPano(strParams) {
		//Viewer.setSpeed(0, 0);
		
		var availWidth  = screen.availWidth - 10;
		var availHeight = screen.availHeight - 32;
		var width  = Math.min(600, availWidth);
		var height = Math.min(400, availHeight);
		var left   = (availWidth - width) / 2;
		var top    = (availHeight - height) / 2;
		var strWidthName  = isMSIE() ? "width" : "innerWidth";
		var strHeightName = isMSIE() ? "height" : "innerHeight";
		
		var strResizable = navigatorSupportsAppletScaling() ? "yes" : "no";
		var strWndParams = "left=" + left + ",top=" + top + "," +
						 strWidthName + "=" + width + "," + strHeightName + "=" + height +
						 ",resizable=" + strResizable +
						 ",scrollbars=no,menubar=no,status=no,toolbar=no,directories=no";
		
		wndViewer = self.open("PanoradoAppletSample2.html?" + strParams, "_Viewer", strWndParams);
		if (wndViewer != null) wndViewer.focus();
	}//end showPano
	function navigatorSupportsAppletScaling() { return (isMSIE() || isFirefox()); }
	function isMSIE() { return (navigator.userAgent.indexOf("MSIE") >= 0); }
	function isFirefox() { return (navigator.userAgent.indexOf("Firefox") >= 0); }
//END ZOOMING AND PANOS

//TOGGLE DIV LAYER
	function toggleLayer(whichLayer) {
		//alert(whichLayer);
		if (document.getElementById){
			// this is the way the standards work
			var style2 = document.getElementById(whichLayer).style;
			style2.display = style2.display? "":"block";
		} else if (document.all) {
			// this is the way old msie versions work
			var style2 = document.all[whichLayer].style;
			style2.display = style2.display? "":"block";
		} else if (document.layers)	{
			// this is the way nn4 works
			var style2 = document.layers[whichLayer].style;
			style2.display = style2.display? "":"block";
		}
	}//end toggleLayer	
	function toggleLayerStatus(d, status){
		//alert(d+" "+status);
		if (status=='off'){
			document.getElementById(d).style.display = "none";
			//alert ("I'm off");
		}//end if
		else {
			document.getElementById(d).style.display = "";
			//alert("I'm on");
			//alert(document.getElementById(d).style);
		}//end else
	}//end toggleLayerStatus
//END TOGGLE DIV LAYER

//Old functions still in use and verified
	function JumpURL( URL ){
		window.open(URL,'jumpwindow','scrollbars=yes,width=720,height=620,resizable=yes');
	}//end JupURL
	function panTo( lat, lng ){
		map.setCenter(new GLatLng(parseFloat(lng),parseFloat(lat)));
		map.setZoom(17);
	}//end panTo
