//		The code contained in this file was cobbled from various sources by www.rvdude.com
//		Use freely, but please do give credit.
//		Generous credit goes to the Blackpool Community Church Javascript Team 
//		who have created one of the finest Google MAP API tutorials anywhere
//		http://www.econym.demon.co.uk/googlemaps/
//		http://www.commchurch.freeserve.co.uk/   

// Get the xml name if passed in the URL and set a text title to display
	// Get the parm string in the format ?filename and w/o the file extension or file directory info
	var myxmlfilename = window.location.search.substring(1);
	switch (myxmlfilename)
		{
		//Make sure to make any changes done here also in the htm file pull down menu form
		case "": var myxmlfilename = "markers_CUR"; myxmlfilenametitle = "Most Recent 50"; break  // "Default" values if not passed via URL
case "markers_FUTURE": var myxmlfilenametitle = "Future Travels"; break
case "markers_CUR": var myxmlfilenametitle = "Most Recent 50"; break
case "markers_ALLNA": var myxmlfilenametitle = "N. America All"; break
case "markersWORLD" : var myxmlfilenametitle = "World Travels"; break
case "markers_ALL": var myxmlfilenametitle = "All Travels"; break
case "markersAZ" : var myxmlfilenametitle = "Arizona"; break
case "markersAK" : var myxmlfilenametitle = "Alaska"; break
case "markersCA" : var myxmlfilenametitle = "California"; break
case "markersCO" : var myxmlfilenametitle = "Colorado"; break
case "markersDE" : var myxmlfilenametitle = "Delaware"; break
case "markersFL" : var myxmlfilenametitle = "Florida"; break
case "markersGA" : var myxmlfilenametitle = "Georgia"; break
case "markersIA" : var myxmlfilenametitle = "Iowa"; break
case "markersID" : var myxmlfilenametitle = "Idaho"; break
case "markersIL" : var myxmlfilenametitle = "Illinois"; break
case "markersIN" : var myxmlfilenametitle = "Indiana"; break
case "markersKS" : var myxmlfilenametitle = "Kansas"; break
case "markersKY" : var myxmlfilenametitle = "Kentucky"; break
case "markersMD" : var myxmlfilenametitle = "Maryland"; break
case "markersMI" : var myxmlfilenametitle = "Michigan"; break
case "markersMN" : var myxmlfilenametitle = "Minnesota"; break
case "markersMO" : var myxmlfilenametitle = "Missouri"; break
case "markersMS" : var myxmlfilenametitle = "Mississippi"; break
case "markersMT" : var myxmlfilenametitle = "Montana"; break
case "markersNC" : var myxmlfilenametitle = "North Carolina"; break
case "markersND" : var myxmlfilenametitle = "North Dakota"; break
case "markersNE" : var myxmlfilenametitle = "Nebraska"; break
case "markersNM" : var myxmlfilenametitle = "New Mexico"; break
case "markersNV" : var myxmlfilenametitle = "Nevada"; break
case "markersNY" : var myxmlfilenametitle = "New York"; break
case "markersOH" : var myxmlfilenametitle = "Ohio"; break
case "markersOK" : var myxmlfilenametitle = "Oklahoma"; break
case "markersPA" : var myxmlfilenametitle = "Pennsylvania"; break
case "markersSC" : var myxmlfilenametitle = "South Carolina"; break
case "markersSD" : var myxmlfilenametitle = "South Dakota"; break
case "markersTN" : var myxmlfilenametitle = "Tennessee"; break
case "markersTX" : var myxmlfilenametitle = "Texas"; break
case "markersUT" : var myxmlfilenametitle = "Utah"; break
case "markersVA" : var myxmlfilenametitle = "Virginia"; break
case "markersWA" : var myxmlfilenametitle = "Washington"; break
case "markersWI" : var myxmlfilenametitle = "Wisconsin"; break
case "markersWV" : var myxmlfilenametitle = "West Virginia"; break
case "markersWY" : var myxmlfilenametitle = "Wyoming"; break
case "markersAB" : var myxmlfilenametitle = "Alberta"; break
case "markersBC" : var myxmlfilenametitle = "British Columbia"; break
case "markersSK" : var myxmlfilenametitle = "Saskatchewan"; break
case "markersYT" : var myxmlfilenametitle = "Yukon"; break
case "markers_z_AK2009" : var myxmlfilenametitle = "Alaska 2009"; break
case "markers_z_SKI2009" : var myxmlfilenametitle = "Ski Colorado 2009"; break
case "markers_z_SKI2008" : var myxmlfilenametitle = "Ski Colorado 2008"; break
case "markers_z_SUM2008" : var myxmlfilenametitle = "Summer 2008"; break
case "markers_z_SUM2007" : var myxmlfilenametitle = "Summer 2007"; break
case "markers_z_MINNIE" : var myxmlfilenametitle = "Minnie Winnie All"; break
		default: var myxmlfilenametitle = myxmlfilename;    // This is the header value if xml data file not recognized
		}
	// Fix up myxmlfilename to be a filename. For now I want to keep all xml files together in this one directory 
	var myxmlfilename = "datamarkers/" + myxmlfilename + ".xml";


// ------------- BEGIN FUNCTIONS -------------------------

// A function to make the pull down menu url redirector work
function myMapZoom() { 
	// Get the position number of the list item selected (0 to length of list)
	var selecteditemindex = document.myMapZoomForm.myMapZoomList.selectedIndex; 

	// Set up the redirector information appending the new xml filename to use  
	var selectedxmlfile = "index.htm?" + document.myMapZoomForm.myMapZoomList.options[selecteditemindex].value;

	// Redirect browser to open this new xml file in same window
	top.location.href = selectedxmlfile; 
return;
} //end function myMapZoom


// A function to create the Google Map markers and set up the marker click window
function createMarker(point,mylabel,myurl,icon,mydesc,i,lat,lng) {

	// Create a marker with the requested icon
	var marker = new GMarker(point, newmapicons[icon]);
	
//HELP Question - How to add marker tooltip flyover????
	// test lines to add a mouseover tooltip on the marker. seems you cant have both an icon and a tooltip
	//       var marker = new GMarker(point, title:mylabel); work but default icon
	//       var marker = new GMarker(point, {title:mylabel}, {newmapicons[icon]}); no work
	// end test lines

//NOTE
// to load the popup window labels so they pass the xml linenum and filename for the xml record use all this can be 
// moved into the else clause for efficiency
// testurl = myurl + "?linenum=" + i + "&xmlfile=" + myxmlfilename;		
// and change the myurl variable a few lines down to testurl
	
	// Map marker pop up window with formated description text and corresponding url link
	if (myurl == "") // See if the label needs to be a link. The div tag sets the size of the pop up window
		{var jlplabel = '<div align="left" style="overflow:auto; width:350px"><font color="#000000">' + mylabel + '</font>' + 
		'<font color="#000000" size="2"><br><br>' + mydesc + '</font>'} 
		else {var jlplabel = '<div align="left" style="overflow:auto; width:350px"><a target=_blank href=' + myurl + '>' + mylabel + '</a>' + 
		'<font color="#000000" size="2"><br><br>' + mydesc + '</font>'}
		
// http://mapki.com/wiki/Google_Map_Parameters has the params for the google map call
// Add in the links for google map and earth on the map window bubble pop up
// Note that we open a div above and must close it below
	jlplabel = jlplabel + 
		'<p align="center">' +
		'<a href="http://maps.google.com/maps?q=' + lat + ',' + lng + '%28RVDude%20-%20' + unescape(mylabel) + '%29&output=kml">' +
		'<img border="0" src="../images/googleearth_text.gif" width="67" height="27"></a>' +
		'<a target="_blank" href="http://maps.google.com/maps?q=' + lat + ',' + lng + '%28RVDude%20-%20' + unescape(mylabel) + '%29&t=h&z=14">' +
		'<img border="0" src="../images/google_maps.gif" width="67" height="27"></a></p></div>';

	GEvent.addListener(marker, "click", function() {marker.openInfoWindowHtml(unescape(jlplabel));});
//	GEvent.addListener(marker, "mouseover", function() {marker.openInfoWindowHtml(unescape(jlplabel));});

		
	// Save the info we need to use later for the sidebar
	gmarkers[i] = marker;
	htmls[i] = jlplabel;

	// Set the color for the sidebar text to match the icon color
	switch (icon){
		case "camp": var iconColor = "#00CC00"; break   //green
		case "poi": var iconColor = "#FFFF99"; break    //yellow
		case "info": var iconColor = "#FF0000"; break  //red
		case "future": var iconColor = "#FFFFFF"; break   //white
		case "plane": var iconColor = "#00FFFF"; break   //light blueish
		case "bike": var iconColor = "#3399FF"; break   //blue 0066FF
		case "boat": var iconColor = "#3399FF"; break   //blue 0066FF
		case "carbus": var iconColor = "#3399FF"; break   //blue 0066FF
		case "fish": var iconColor = "#3399FF"; break   //blue 0066FF
		case "golf": var iconColor = "#3399FF"; break   //blue 0066FF
		case "hike": var iconColor = "#3399FF"; break   //blue 0066FF
		case "domisc": var iconColor = "#3399FF"; break   //blue 0066FF
		case "show": var iconColor = "#3399FF"; break   //blue 0066FF
		case "ski": var iconColor = "#3399FF"; break   //blue 0066FF
		case "tour": var iconColor = "#3399FF"; break   //blue 0066FF
		default: var iconColor = "#CCCCCC";             //Greyish
	}		

	// Add a line to the sidebar html note a = a + b is the same as a += b
	sidebar_html += '<a href="javascript:myclick(' + i + ')"><font size="2" color="' + iconColor + '">' + mylabel + '</font></a><br>';
	i++;
	map.addOverlay(marker);
return marker;
} //end function createMarker


// A function to pick up the click on a marker or sidebar item and open the corresponding info window
function myclick(i) {
	gmarkers[i].openInfoWindowHtml(unescape(htmls[i]));
return;
} //end function myclick


