    //<![CDATA[
	var total_markers = 0;
	var default_zoom;

	var map;
	var geocoder;
	var markers = new Array(total_markers);

	var min_num_markers = 5;
	var max_num_markers = 15;
	
	var popWin;
	
	/*
		Description: Loader. Create the map and the geocoder objects. Position at default position.
	*/
    function load(zoom_level) {
      if (GBrowserIsCompatible()) {
		default_zoom = (zoom_level == undefined ? 13 : zoom_level);
		
        map = new GMap2(document.getElementById("map"));
		geocoder = new GClientGeocoder();

		/* Set up starting location, which is googles homebase */
        map.setCenter(new GLatLng(37.4419, -122.1419), default_zoom);
		map.disableDoubleClickZoom();
		
		/* Determing what the max number of markers should be */
		var map_width = parseInt(document.getElementById('map').style.width);
		var map_height = parseInt(document.getElementById('map').style.height);

		//simple test increment the maximum amount by 5 for every 300 pixels to both width and height.
		if (map_width < 500 && map_height < 300) max_num_markers = 5;
		else if (map_width < 800 && map_height < 600) max_num_markers = 15;
		else if (map_width < 1100 && map_height < 900) max_num_markers = 20;
		else if (map_width < 1400 && map_height < 1200) max_num_markers = 25;
		else max_num_markers = 30;

		if (document.getElementById('gmap_custom_popup')) {
			popWin = new popUpWindow(map);      
			map.addOverlay(popWin);
		}
		
      }
    }

	/*
		Description: attempts to convert a given address into a latitude and longtitude, using googles geocode service.
		Notes: the address is gotten from a text field with the id "address".
	*/
	function find_location() {
		var loc_street = document.getElementById('address_street').value;
		var loc_city = document.getElementById('address_city').value;
		var loc_state = document.getElementById('address_state').value;
		
		/* Makesure all parts of the address are entered specifcally street and city*/
		if (loc_street != "" && loc_city != "") {
		
			var loc_str = loc_street + " " + loc_city + " " + loc_state + " USA";
		
			//using the geocoder to get the latitude and longtitude of the address.
			geocoder.getLatLng(loc_str,function(point) {
				if (!point) {
					alert(loc_str + " not found");
				} else {
					map.setCenter(point, default_zoom);
					add_random_markers(point);
				}
			}
			);
		}
		else {
			if (loc_street == "") alert("Please enter in a street address.");
			else if (loc_city == "") alert("Please enter in a city address.");
		}
	}
	
	/*
		Description: Create a new marker and sends it back.
		Parameters: point - a GLatLng object with the latitude and longtidude
			          index - the position of the marker.
	*/
	function create_marker(point, index, marker_details) {

		// if there is an icon image, then we load this image, otherwise use the default icon.
		if (marker_details.getAttribute("icon") != "") {
			var custom_icon = new GIcon(G_DEFAULT_ICON);
			custom_icon.image = marker_details.getAttribute("icon");
			custom_icon.iconSize = new GSize(parseInt(marker_details.getAttribute("i_w")), parseInt(marker_details.getAttribute("i_h")));
			
			// marker shadows if exists.
			if (marker_details.getAttribute("shadow") != "") {
				custom_icon.shadow = marker_details.getAttribute("shadow");
				custom_icon.shadowSize = new GSize(parseInt(marker_details.getAttribute("s_w")), parseInt(marker_details.getAttribute("s_h")));
			}
			else custom_icon.shadow = "";
			
			// Set up our GMarkerOptions object
			markerOptions = { icon:custom_icon };
			var marker = new GMarker(point, markerOptions);
		}
		else var marker = new GMarker(point);
		
		//Adding the mouseover popup listener
		GEvent.addListener(marker, "mouseover", function() {
		  //if the custom pop div exists in the HTML then we will use that otherwise the default popupwindow
		  if (document.getElementById('gmap_custom_popup'))
		    popWin.openCustomInfoWindow(marker,marker_details.getAttribute("text"));
		  else
		    marker.openInfoWindowHtml(marker_details.getAttribute("text"));
		});
		
		return marker;
	}
	

	/*
		Description: Adds 6 random markers around location.
		Parameters: start_point - the starting coordinates, lat/long
	*/
	function add_random_markers(start_point) {
		var i = 0;
		
		//Remove the old overlays
		for (i = 0; i < total_markers; i++) {
			map.removeOverlay(markers[i]);
		}

		//if there is a popwindow open this will hide it.
		if (popWin !== 'undefined') {
			popWin.hide();
		}
		
		//Create a random number of markers to display
		total_markers = Math.floor(Math.random()*(max_num_markers-min_num_markers)+min_num_markers);
		
		/* Get the boundaries of the whole map */
		var bounds = map.getBounds();
		var southWest = bounds.getSouthWest();
		var northEast = bounds.getNorthEast();

		/* calculate the distance we are allowed to travel within the boundaries. */
		var lngSpan = northEast.lng() - southWest.lng();
		var latSpan = northEast.lat() - southWest.lat();
		
		/* Call the php file which will return  the random text and associated marker icon*/
		GDownloadUrl("get_random_text.php?num=" + total_markers, function(data, responseCode) {
			  var xml_data = GXml.parse(data);
			  var rand_text = xml_data.documentElement.getElementsByTagName("marker");
			  
			  /* randomly create 6 new markers locations and put markers there. */
			  for (i = 0; i < total_markers; i++) {
				var point = new GLatLng(southWest.lat() + latSpan * Math.random(),
										southWest.lng() + lngSpan * Math.random());
				/* make the new marker */
				markers[i] = create_marker(point, i, rand_text[i]);
				
				map.addOverlay(markers[i]);
			  }			  
		});
		
	}

	/* For the Custom Overlays */
	  function popUpWindow(map) {
	    this.map = map;
		this.stemImage = "g_map_images/stem.gif";
		this.stemSize = new GSize(24,24);
		this.boxOffset = new GPoint(-10,28);
	
		this.visible = false;
	  }
	  
	  popUpWindow.prototype = new GOverlay();
	  
	  popUpWindow.prototype.initialize = function(map) {
	    //Init the InfoWindow DIV
	    var div1 = document.createElement("div");
		div1.style.position = "absolute";
		map.getPane(G_MAP_FLOAT_SHADOW_PANE).appendChild(div1);
	
		//Init the Stem part of the InfoWindow Div
		var div2 = document.createElement("div");
		div2.style.position = "absolute";
		div2.style.width = this.stemSize.width + "px";
		map.getPane(G_MAP_FLOAT_SHADOW_PANE).appendChild(div2);
		
		this.div1 = div1;
		this.div2 = div2;
	
	  }
	  
	  popUpWindow.prototype.openCustomInfoWindow = function(marker, html) {

		map.panTo(new GLatLng(marker.getPoint().lat(), marker.getPoint().lng()));
		
		var vx = marker.getIcon().iconAnchor.x - marker.getIcon().infoWindowAnchor.x;
		var vy = marker.getIcon().iconAnchor.y - marker.getIcon().infoWindowAnchor.y;
		
		this.offset = new GPoint(vx, vy)||new GPoint(0,0);
		this.point = marker.getPoint();
		//The actual InfoWindow
		this.div1.innerHTML = document.getElementById('gmap_custom_popup').innerHTML;
		this.div1.innerHTML = this.div1.innerHTML.replace('{POP_UP_TEXT}',html);
		
		//The Stem Image part of the infowindow
		this.div2.innerHTML = '<img src="' + this.stemImage+'" width="' + this.stemSize.width + '" height="' + this.stemSize.height + '">';
		
		var z = GOverlay.getZIndex(this.point.lat());
		this.div1.style.zIndex = z;
		this.div2.style.zIndex = z+1;
		
		//show the window and force a redraw
		this.visible = true;
		this.show();
		this.redraw(true);
	  }
	  
	  popUpWindow.prototype.redraw = function(force) {
		if (this.visible) {
			var p = this.map.fromLatLngToDivPixel(this.point);
			this.div2.style.left = (p.x + this.offset.x) + "px";
			this.div2.style.bottom = (-p.y + this.offset.y) + "px";
			this.div1.style.left = (p.x + this.offset.x + this.boxOffset.x) + "px";
			this.div1.style.bottom = (-p.y + this.offset.y + this.boxOffset.y) + "px";
		}
	  }
	  
	  popUpWindow.prototype.remove = function() {
	    this.div1.parentNode.removeChild(this.div1);
		this.div2.parentNode.removeChild(this.div2);
		this.visible = false;
	  }
	  
	  popUpWindow.prototype.copy = function() {
	    return new popUpWindow(this.map, this.style);
	  }
	  
	  popUpWindow.prototype.show = function() {
	    this.div1.style.display = "";
		this.div2.style.display = "";
		this.visible = true;
	  }
	  
	  popUpWindow.prototype.hide = function() {
	    this.div1.style.display = "none";
		this.div2.style.display = "none";
		this.visible = false;
	  }

    //]]>
