// JavaScript Document
			//<![CDATA[

			//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
			// Set global variables that will be used in the map
			//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
			var XML_FILE = "data/fishingmap.xml?" + Math.random(); // xml file used to retrieve data about waters
			var icontypes;   // array that will store the XML objects that represent each icon type
			var markers;     // array that will store the XML objects that represent each water/site
			var htmls = [];  // html for the infoWindow for each water
			var sidebarHtml; // html for sidebar
			var markerLatLngs = []; // array of GLatLng objects
			var markernames = []; // array of Water Names
			var icons = new Array(); // array of icons
			var watercolors = []; // array of colors of pushpins
			var map; // the map object

			var show = []; // array of booleans to determine which types of markers to show/hide
			show["lakes"] = 1;
			show["rivers"] = 1;
			show["ponds"] = 1;
			show["stores"] = 0; // stores are turned 'off' by default

			var starting_map_center = new GLatLng(39.55, -111.538); // Starting GLatLng coordinates of the map center
			var current_map_center = starting_map_center; // Set current center to starting center
			var starting_zoom_level = 7; // Starting zoom level of the map
			var current_zoom_level = starting_zoom_level; // Current zoom level of the map
			var traffic = false; // if true then display traffic status on main roads

			var LakeGMarkers = [];  // array of GMarkers representing lakes and reservoirs
			var RiverGMarkers = []; // array of GMarkers representing rivers and streams
			var PondGMarkers = [];  // array of GMarkers representing community fisheries (ponds)
			var StoreGMarkers = []; // array of GMarkers representing Fishing related stores

			//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
			// toggle on/off showing markers of the type specified as a parameter
			// @param type - type of marker to show/hide
			// @returns ?
			//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
			function toggle_display_status(type)
			{
				try
				{
					switch(type)
					{
						case 'lakes':
							if (document.optionsform.lakes.checked == 0)
							{
								// Turn off lakes
								show["lakes"] = 0;

								//alert("You elected to turn off displaying of lakes");

								// Beginnings of doing it by passing parameters on the address bar and reloading page
								//custom_map_page = window.location + "?" ;
								for (var i = 0; i < LakeGMarkers.length; i++)
								{
									LakeGMarkers[i].hide();
								}
							}
							else
							{
								// lakes were 'turned on'
								show["lakes"] = 1;

								//alert("You elected to 'turn on' displaying of lakes");
								for (var i = 0; i < LakeGMarkers.length; i++)
								{
									LakeGMarkers[i].show();
								}
							}
							break;

						case 'rivers':
							if (document.optionsform.rivers.checked == 0)
							{
								// rivers were 'turned off'
								show["rivers"] = 0;

								//alert("You elected to turn off display of rivers.");
								for (var i = 0; i < RiverGMarkers.length; i++)
								{
									RiverGMarkers[i].hide();
								}
							}
							else
							{
								// rivers were 'turned on'
								show["rivers"] = 1;

								//alert("You elected to 'turn on' display of rivers.");
								for (var i = 0; i < RiverGMarkers.length; i++)
								{
									RiverGMarkers[i].show();
								}
							}

							break;

						case 'ponds':
							if (document.optionsform.ponds.checked == 0)
							{
								// ponds were turned off
								show["ponds"] = 0;
								//alert("You elected to 'turn off' display of urban ponds.");
								for (var i = 0; i < PondGMarkers.length; i++)
								{
									PondGMarkers[i].hide();
								}
							}
							else
							{
								// ponds was 'turned on'
								show["ponds"] = 1;

								//alert("You elected to 'turn on' display of urban ponds.");
								for (var i = 0; i < PondGMarkers.length; i++)
								{
									PondGMarkers[i].show();
								} // end for loop
							}

							break;

						case 'stores':
							if (document.optionsform.stores.checked == 0)
							{
								// stores were turned off
								show["stores"] = 0;
								//alert("You elected to 'turn off' display of fishing related stores.");
								for (var i = 0; i < StoreGMarkers.length; i++)
								{
									StoreGMarkers[i].hide();
								}
							}
							else
							{
								// stores were turned on
								show["stores"] = 1;
								//alert("You elected to 'turn on' display of fishing related stores.");
								for (var i = 0; i < StoreGMarkers.length; i++)
								{
									StoreGMarkers[i].show();
								}
							}

							break;

						default:
							// There was an error of some kind
							alert('We are sorry, there seemed to be some kind of error on ' +
                'this page.  Please contact the site admin about this problem' +
                ' by visiting our Contact Us page.');
							break;
					} // end switch(type)
				}
				catch(e)
				{
					alert("toggle_display_status() error:  " + e);
				}
			} // end toggle_display_status()

			//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
			//create a marker which displays lake/river info in the infowindow
			//@param point - a GLatLng object (coordinate pair)
			//@param html - the html that will go in the InfoWindow for this point
			//@param icon - the icon from which to create the marker icon
			//@returns themarker - a marker object created with the point passed in
			//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
			function createMarker(point,html,icon)
			{
				try
				{
					var themarker = new GMarker(point,icon); // in this case, point is a GLatLng

					GEvent.addListener(themarker, "click", function()
					{
						// Center the map on the marker that was clicked
						map.setCenter(point);
						current_map_center = point; // This might not be needed, because the map object might already store this - CHECK the API

						// Open the InfoWindow with custom html
						themarker.openInfoWindowHtml(html);
					});
					
					GEvent.addListener(themarker, "mouseover", function()
					{
					   themarker.openInfoWindowHtml(html);
          });

					return themarker;
				}
				catch(e)
				{
					alert("createMarker() error:  " + e);
				}
			} // end createMarker()

			//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
			// Refresh the map status - this hides/shows markers based on user selection
			//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
			function refresh_map()
			{
				try
				{
					show["lakes"] = document.optionsform.lakes.checked;
					show["rivers"] = document.optionsform.lakes.checked;
					show["ponds"] = document.optionsform.lakes.checked;
					show["stores"] = document.optionsform.lakes.checked;

					if (show["lakes"])
					{
						for (var i = 0; i < LakeGMarkers.length; i++)
						{
							LakeGMarkers[i].show();
						}
					}
					else
					{
						for (var i = 0; i < LakeGMarkers.length; i++)
						{
							LakeGMarkers[i].hide();
						}
					}

					if (show["rivers"])
					{
						for (var i = 0; i < RiverGMarkers.length; i++)
						{
							RiverGMarkers[i].show();
						}
					}
					else
					{
						for (var i = 0; i < RiverGMarkers.length; i++)
						{
							RiverGMarkers[i].hide();
						}
					}

					if (show["ponds"])
					{
						for (var i = 0; i < PondGMarkers.length; i++)
						{
							PondGMarkers[i].show();
						}
					}
					else
					{
						for (var i = 0; i < PondGMarkers.length; i++)
						{
							PondGMarkers[i].hide();
						}
					}

					if (show["stores"])
					{
						for (var i = 0; i < StoreGMarkers.length; i++)
						{
							StoreGMarkers[i].show();
						}
					}
					else
					{
						for (var i = 0; i < StoreGMarkers.length; i++)
						{
							StoreGMarkers[i].hide();
						}
					}
				}
				catch(e)
				{
					alert("refresh_map error:  " + e);
				}
			} // end refresh_map()


			//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
			// Download the data in the xml file and create the xml objects
			//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
			GDownloadUrl(XML_FILE, function(data, responseCode)
			{
				try
				{
					var xml = GXml.parse(data);
					icontypes = xml.documentElement.getElementsByTagName("icon"); // get array of icon types
					markers = xml.documentElement.getElementsByTagName("water"); // create array of marker tags

					//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
					//parse it & add the html info for each point on the map into an array

					//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
					// Create marker icons
					//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
					for (var i = 0; i < icontypes.length; i++)
					{
						// Create Lakes & Reservoirs icon
						var tempiconcolor = icontypes[i].getAttribute("color");

						icons[tempiconcolor] = new GIcon();
						icons[tempiconcolor].image = icontypes[i].getAttribute("img");
						icons[tempiconcolor].shadow = "images/markers/markershadow.png";
						icons[tempiconcolor].iconSize = new GSize(12, 20);
						icons[tempiconcolor].shadowSize = new GSize(22, 20);
						icons[tempiconcolor].iconAnchor = new GPoint(6, 20);
						icons[tempiconcolor].infoWindowAnchor = new GPoint(5, 1);

						watercolors[icontypes[i].getAttribute("type")] = tempiconcolor;
					} // end for loop

					//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
					// Get list of waters (lakes, rivers, ponds) and sites (stores)
					//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
					for (var i = 0; i < markers.length; i++)
					{
						var tempGMarker;
						var tempwatertype = markers[i].getAttribute("type"); // get the water type (possible values: lake, river, communitypond or store)
						var tempicon = new GIcon(icons[watercolors[tempwatertype]]);

						markernames[i] = markers[i].getAttribute("watername"); // read the water names into an array

						// store the GLatLng object with an index of the water name
						markerLatLngs[markernames[i]] = new GLatLng(parseFloat(markers[i].getAttribute("lat")),parseFloat(markers[i].getAttribute("lng")));

						//store html info for each marker
						var temphtml = "<a href='" + markers[i].getAttribute("url") + "'><img src='" + markers[i].getAttribute("img") +  "' border='0' ";
						temphtml += "alt='" + markernames[i] + "' title='" + markernames[i] + "' width='152' height='115' /></a><br/>";
						temphtml += "<p><a href='" + markers[i].getAttribute("url") + "' target='_blank'>" + markernames[i] + "</a><br/>"; // url of page link
						temphtml += "Location: " + markers[i].getAttribute("location") + "<br/>";
						if (markers[i].getAttribute("location2"))
						{
							temphtml += markers[i].getAttribute("location2"); // if it exists
							temphtml += "<br/>";
						}
						temphtml += "</p>";

						// store icon info for each marker
						tempGMarker = createMarker(markerLatLngs[markernames[i]],temphtml,tempicon);

						switch (tempwatertype)
						{
							case "lake":
								LakeGMarkers.push(tempGMarker);
								break;
							case "river":
								RiverGMarkers.push(tempGMarker);
								break;
							case "communitypond":
								PondGMarkers.push(tempGMarker);
								break;
							case "store":
								StoreGMarkers.push(tempGMarker);
								break;
							default:
								break;
						} // end switch
					} // end for loop

					//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
					// Add sidebar html to the sidebar
					sidebarHtml += "<strong><p>Choose a destination:</strong></p>\n";
					//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
					/*for (var i = 0; i < markers.length; i++)
					{
						sidebarHtml += "<a href='" + markers[i].getAttribute("url") + "'>" + markers[i].getAttribute("watername") + "</a><br>";
					}

					document.getElementById("sidebar").innerHTML = sidebarHtml;*/
					//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
				}
				catch(e)
				{
					alert("GDownloadUrl() error:  " + e);
				}
			}); // end GDownloadUrl()

			function load()
			{
				try
				{
					//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
					// Create the map
					//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
					map = new GMap2(document.getElementById("map"));

          // Set the map underlay (shows while map is loading)
          var uImg = 'http://www.utahfishinginfo.com/images/logos/underlay1.jpg';
          document.getElementById("map").style.backgroundImage = "url(" + uImg + 
            ")";

					// Add optional map controls
					map.addControl(new GLargeMapControl()); // large map control
          map.addMapType(G_PHYSICAL_MAP);
					map.addControl(new GMapTypeControl()); // Map, Satellite, or Hybrid Map options
					map.addControl(new GScaleControl()); // lare zoom control
					map.addControl(new GOverviewMapControl()); // shows 'zoomed out' view

					//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
					// Set the starting map location
					//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
					//map.setCenter(current_map_canter, 7);  // position the starting map position to show all of Utah
          map.setCenter(current_map_center, current_zoom_level);
          document.getElementById("message").innerHTML = "Current Location: " + 
            map.getCenter().toUrlValue();
          //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
          // Add traffic overlay if desired
          //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
          if (traffic)
          {
            var trafficInfo = new GTrafficOverlay();
            map.addOverlay(trafficInfo);
          }

					//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
					// Add an event listener that displays the current coordinates of the map center
					// This is a debug function used while I am creating the map so that I can record the locations
					// of each water accurately for later use.
					//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
					GEvent.addListener(map, "moveend", function()
					{
						var mapcenter = map.getCenter();
						//document.getElementById("message").innerHTML = "Current Location: " + mapcenter.toString();
						document.getElementById("message").innerHTML = "Current Location: " + mapcenter.toUrlValue();
					});
					//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

					//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
					// Add all markers as overlays (hide stores initially)
					//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
					for (var i = 0; i < LakeGMarkers.length; i++)
					{
						map.addOverlay(LakeGMarkers[i]);

						// For some reason, using pop() only displays the LAST HALF of the lake markers
						//map.addOverlay(LakeGMarkers.pop());
						//LakeGMarkers[i].show();
					}
					for (var i = 0; i < RiverGMarkers.length; i++)
					{
						map.addOverlay(RiverGMarkers[i]);
					}
					for (var i = 0; i < PondGMarkers.length; i++)
					{
						map.addOverlay(PondGMarkers[i]);
					}
					for (var i = 0; i < StoreGMarkers.length; i++)
					{
						map.addOverlay(StoreGMarkers[i]);
						StoreGMarkers[i].hide();
					}
					//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
				}
				catch(e)
				{
					alert("Error in load() function:  " + e);
				}
			} // end load()

			//]]>

