    //Set the global variables.
    var map;
    var startLat = 40;
    var startLng = -96;
    var startZoom = 3;
    var geocoder;
    var pointData = new Object();
    var deselectCurrent = function(){}; //Empty Function used for the info panel.



    function toggleLayer(whichLayer) //Function is now deprecated, fixed with clearoverlays()
    {
      var elem, vis;
      if( document.getElementById ) // this is the way the standards work
        elem = document.getElementById( whichLayer );
      else if( document.all ) // this is the way old msie versions work
          elem = document.all[whichLayer];
      else if( document.layers ) // this is the way nn4 works
        elem = document.layers[whichLayer];
      vis = elem.style;
      // if the style.display value is blank we try to figure it out here
      if(vis.display==''&&elem.offsetWidth!=undefined&&elem.offsetHeight!=undefined)
        vis.display = (elem.offsetWidth!=0&&elem.offsetHeight!=0)?'block':'none';
      vis.display = (vis.display==''||vis.display=='block')?'none':'block';
    }

    function leftTrim(sString)
    {
        while (sString.substring(0,1) == ' ')
        {
            sString = sString.substring(1, sString.length);
        }
    return sString;
    }


    function clearoverlays()
    {
        //This is cheating, clear the overlays by refreshing the search ;-)
        searchLocations();
    }

    function load() {
      //Called from the onload action of the body element.
      if (GBrowserIsCompatible()) {
        //Instantiate the Geocoder class.
        geocoder = new GClientGeocoder();

        //Create the new map object and give it a home.
        map = new GMap2(document.getElementById('map'));

        //Add the map controls for increased user - interactivity.
        map.addControl(new GSmallMapControl());
        map.addControl(new GMapTypeControl());
        if(document.getElementById('addressInput').value!='')
        {
            //If we are coming from a remote call, then start the map with data.
            map.setCenter(new GLatLng(startLat, startLng), startZoom);
            searchLocations();
        }
        else //Provide an empty map.
        {
            map.setCenter(new GLatLng(startLat, startLng), startZoom);
        }
      }
    }

    function prepareSearch()
    {
        //If the user clicks the search button on the hauntsearch.php page
        //then set the addressInput hidden field.
        var frmStreet = document.getElementById('street').value;
        var frmCity = document.getElementById('city').value;
        var frmState = document.getElementById('state').value;
        var frmZipCode = document.getElementById('zipcode').value;
        var frmRadius = document.getElementById('newradius').value;
        if(frmState=='XX')
            {
                frmState='';
            }

        var searchHold = frmStreet + " " + frmCity + " " + frmState + " " + frmZipCode;

        var searchAddress = leftTrim(searchHold);

        document.getElementById('addressInput').value = searchAddress;

        document.getElementById('radiusSelect').value = frmRadius;

        searchLocations();

    }

   function searchLocations() {
     var address = document.getElementById('addressInput').value;
     //Geocode the supplied address, inform the user of a failure, present map results on success.
     geocoder.getLatLng(address, function(latlng) {
       if (!latlng) {
         alert(address + ' not found');
       } else {
        //alert(address + "\n" + latlng);
         searchLocationsNear(latlng);
       }
     });
   }

   function searchLocationsNear(center) {

     //Clear the existing results.
        document.getElementById('haunt_banner').innerHTML = "<br /><center>Click an attraction on the list to see information here!</center>";
        document.getElementById('haunt_trailer').innerHTML = "";
     var radius = document.getElementById('radiusSelect').value;
     var srchState = document.getElementById('addressInput').value;
     //Get the data from the database and parse into XML for Google to use.
     var haunt_type = document.getElementById('att_type').value
     var searchUrl = 'scripts/phpsqlsearch_genxml.php?lat=' + center.lat() + '&lng=' + center.lng() + '&radius=' + radius;
     searchUrl = searchUrl + '&type=' + haunt_type + '&state=' + srchState;
     //window.open(searchUrl);
     GDownloadUrl(searchUrl, function(data) {
       var xml = GXml.parse(data);
       //Assign the returned values to the markers object.
       var markers = xml.documentElement.getElementsByTagName('marker');
       //Clear the map for redrawing if needed.
       map.clearOverlays();

       //Prepare the side bar for data display.
       var infoPanel = document.getElementById('infoPanel');
       //Make sure that the side bar is clear...
       infoPanel.innerHTML = '';
       //Let the user know that there are no markers resulting from their search.
       if (markers.length == 0) {
         infoPanel.innerHTML = 'No results found.';
         //Show the empty U.S. Map.
         map.setCenter(new GLatLng(startLat, startLng), startZoom);
         return;
       }

       var bounds = new GLatLngBounds();
       for (var i = 0; i < markers.length; i++) {
         //Convert XML to variables. Could have created an object, but this
         //thing grew after starting. Will consider in the rewrite.
         pointData.name = markers[i].getAttribute('name');
         pointData.address = markers[i].getAttribute('address');
         pointData.street = markers[i].getAttribute('street');
         pointData.city = markers[i].getAttribute('city');
         pointData.state = markers[i].getAttribute('state');
         pointData.zipcode = markers[i].getAttribute('zipcode');
         pointData.price = markers[i].getAttribute('price');
         pointData.distance = parseFloat(markers[i].getAttribute('distance'));
         pointData.bnr_url = markers[i].getAttribute('bnr_url');
         pointData.trlr = markers[i].getAttribute('trailer');
         pointData.phone = markers[i].getAttribute('phone');
         pointData.icon_image = markers[i].getAttribute('icon');
         pointData.hnt_url = markers[i].getAttribute('hnt_url');
         pointData.tick_link = markers[i].getAttribute('tick_link');
         pointData.hnt_open = markers[i].getAttribute('hnt_open');
         pointData.hnt_desc = markers[i].getAttribute('hnt_desc');
         pointData.sponsored = markers[i].getAttribute('sponsored');
         pointData.hnt_entered = markers[i].getAttribute('date_entered');
         //Build the haunt information table using the above markers.
         var hnt_info_html = '';
         if (pointData.sponsored==1)
            {
                hnt_info_html = hnt_info_html + '<br/><table class="infotable">';
                hnt_info_html = hnt_info_html + '<tr><td class="haunt_banner_td" colspan="2" align="center"><a href="' + pointData.hnt_url + '" target="_new"><img src="' + pointData.bnr_url + '" border="0" /></a></td></tr>';
                hnt_info_html = hnt_info_html + '<tr><td class="haunt_name_td" colspan="2" align="center">' + pointData.name + '</td></tr>';
            }
         else
            {
                hnt_info_html = '<br /><table class="infotable">';
                hnt_info_html = hnt_info_html + '<tr><td class="haunt_name_td" colspan="2" align="center">' + pointData.name + '</td></tr>';
            }
         //Address of Haunt
         hnt_info_html = hnt_info_html + '<tr><td class="label">Address</td>';
         hnt_info_html = hnt_info_html + '<td class="content">' + pointData.street + '<br />' + pointData.city + ', ' + pointData.state + ', ' + pointData.zipcode + '</td></tr>';


         //Phone Number.
         hnt_info_html = hnt_info_html + '<tr><td class="label">Phone Number</td>';
         if (pointData.phone!="")
            {
                hnt_info_html = hnt_info_html + '<td class="content">' + pointData.phone + '</td></tr>';
            }
            else
            {
                hnt_info_html = hnt_info_html + '<td class="content">No Phone Entered</td></tr>';
            }


         //Description.
         hnt_info_html = hnt_info_html + '<tr><td class="label">Description</td>';
         hnt_info_html = hnt_info_html + '<td class="content">' + pointData.hnt_desc + '</td></tr>';

         //Dates of operation.
         hnt_info_html = hnt_info_html + '<tr><td class="label">Dates / Times Open</td>';
         if(pointData.hnt_open!="")
            {
                hnt_info_html = hnt_info_html + '<td class="content">' + pointData.hnt_open + '</td></tr>';
            }
            else
            {
                hnt_info_html = hnt_info_html + '<td class="content">Contact Attraction for Dates and Times</td></tr>';
            }

         //Haunt URL.
         hnt_info_html = hnt_info_html + '<tr><td class="label">Web Address</td>';
         if(pointData.hnt_url!="")
            {
                //Have to check for complete url.
                var hntUrl = pointData.hnt_url;
                if (hntUrl.match("http://"))
                {
                    hnt_info_html = hnt_info_html + '<td class="content"><a href="' + pointData.hnt_url + '" target="_new">' + pointData.hnt_url + '</a></td></tr>';
                }
                else
                {
                    hnt_info_html = hnt_info_html + '<td class="content"><a href="http://' + pointData.hnt_url + '" target="_new">http://' + pointData.hnt_url + '</a></td></tr>';
                }
            }
            else
            {
                hnt_info_html = hnt_info_html + '<td class="content">Site Link Not Provided</td></tr>';
            }

         //Ticket Price
         if(pointData.price!="")
            {
                hnt_info_html = hnt_info_html + '<tr><td class="label">Ticket Price</td>';
                hnt_info_html = hnt_info_html + '<td class="content">$' + pointData.price + '</td></tr>';
            }
         else
            {
                hnt_info_html = hnt_info_html + '<tr><td class="label">Ticket Price</td>';
                hnt_info_html = hnt_info_html + '<td class="content">Contact Attraction for ticket info.</td></tr>';
            }

         //Haunt Ticket Link.
         if(pointData.tick_link!="")
            {
                hnt_info_html = hnt_info_html + '<tr><td class="label">Buy Tickets</td>';
                hnt_info_html = hnt_info_html + '<td class="content"><a href="' + pointData.tick_link + '">Get Tickets</a></td></tr>';
            }
         else
            {
                hnt_info_html = hnt_info_html + '<tr><td class="label">Buy Tickets</td>';
                hnt_info_html = hnt_info_html + '<td class="content">Contact Attraction for ticket info.</td></tr>';
            }

         //Date Entered.
         hnt_info_html = hnt_info_html + '<tr><td class="label">Submitted</td>';
         hnt_info_html = hnt_info_html + '<td class="content">' + pointData.hnt_entered + '</td></tr>';

         hnt_info_html = hnt_info_html + '</table>';
         //End info HTML builder.

         var point = new GLatLng(parseFloat(markers[i].getAttribute('lat')),
                                 parseFloat(markers[i].getAttribute('lng')));

         //Intialize the point and turn it into a marker.
         initializePoint(point, pointData, hnt_info_html);
         bounds.extend(point);
       }
       map.setCenter(bounds.getCenter(), map.getBoundsZoomLevel(bounds));
       map.setZoom(map.getZoom()-1);
     });
   }


//####################### DEPRECATED <remains for reference> ##################
    function createMarker(point, name, address, map, icon_image) {
          icon = new GIcon();
          icon.image = icon_image;
          icon.iconSize = new GSize(42, 45);
          icon.iconAnchor = new GPoint(14 >> 1, 45 >> 1);
          icon.infoWindowAnchor = new GPoint(15, 1);
      var marker = new GMarker(point,{icon: icon});
      var html = '<b>' + name + '</b> <br/>' + address;
      GEvent.addListener(marker, 'click', function() {
        marker.openInfoWindowHtml(html);
      });
      return marker;
    }
//##################### END DEPRECATED createMarker function ##################

//The following function is a bit of a hodge podge, will clean and optimize
//after roll out.
    function initializePoint(point, pointData, hnt_info_html) {

        //Create the marker.
        icon = new GIcon();
        icon.image = pointData.icon_image;
        icon.iconSize = new GSize(42, 45);
        icon.iconAnchor = new GPoint(14 >> 1, 45 >> 1);
        icon.infoWindowAnchor = new GPoint(15, 1);
        var marker = new GMarker(point,{icon: icon});
        var marker_html = '<b>' + pointData.name + '</b> <br/>' + pointData.address;

      //Create the div for the side panel.
      var div = document.createElement('div');
      //Build the infoPanel div elements.
      //For sponsored listings...
      if(pointData.sponsored==1)
        {
            var panel_html = '<div class="infoPanelHeader_div">';
            panel_html = panel_html + '<span class="infoPanelHeader_span">' + pointData.name;
            panel_html = panel_html + '&nbsp;-&nbsp;(' + pointData.distance.toFixed(1) + ' mi.)</span></div>';
            panel_html = panel_html + '<div class="infoPanelHeaderBanner_div">';
            panel_html = panel_html + '<center><img src="' + pointData.bnr_url + '" /></center>';
            panel_html = panel_html + '</div>';
            panel_html = panel_html + '<div class="infoPanelClickForInfo_div"><span class="infoPanelClickForInfo_span">Click for Info</span></div>';
        }
      else
        {
            var panel_html = '<div class="infoPanelHeader_div">';
            panel_html = panel_html + '<span class="infoPanelHeader_span">' + pointData.name;
            panel_html = panel_html + '&nbsp;-&nbsp;(' + pointData.distance.toFixed(1) + ' mi.)</span></div>';
            panel_html = panel_html + '<div class="infoPanelAddress_div">';
            panel_html = panel_html + '<span class="infoPanelAddress_span">';
            panel_html = panel_html + pointData.street + '<br />';
            panel_html = panel_html + pointData.city + ', ' + pointData.state;
            panel_html = panel_html + ' ' + pointData.zipcode + '</span></div>';
            panel_html = panel_html + '<div class="infoPanelClickForInfo_div">';
            panel_html = panel_html + '<span class="infoPanelClickForInfo_span">';
            panel_html = panel_html + 'Click for Info</span></div>';
        }
      //Write the infoPanel div.
      div.innerHTML = panel_html;
      div.style.cursor = 'pointer';
      div.style.marginBottom = '5px';
      div.className = 'norm';
      var trlr = pointData.trlr;
      var paid = pointData.sponsored;
      var address = pointData.address;
      var focusPoint = function() {
        deselectCurrent();
        div.className = 'current';
        deselectCurrent = function(){div.className='norm';}
        document.getElementById('directions').innerHTML = "";
        document.getElementById('haunt_banner').innerHTML = hnt_info_html;
        document.getElementById('haunt_trailer').innerHTML = "";
        //alert(pointData.trlr);

        if(trlr=="")
            {
                var noVideoHTML = '<div>No Video Provided</div>';
                document.getElementById('haunt_trailer').innerHTML = noVideoHTML;
                document.getElementById('haunt_trailer').className = 'hauntTrailer_div_novid';
            }
        else
            {
                if(paid==1)
                    {
                        //alert("Inside Trailer Maker");
                        document.getElementById('haunt_trailer').innerHTML = trlr;
                        document.getElementById('haunt_trailer').className = 'hauntTrailer_div';
                    }
            }

        var directpanel = document.getElementById('directions');
        var fromaddress = document.getElementById('addressInput').value;
        var printUrl = "http://maps.google.com/maps?f=d&hl=en&geocode=&saddr=";
        printUrl = printUrl + fromaddress + "&daddr=";
        printUrl = printUrl + address + "&pw=2";
        document.getElementById('printReference').href = printUrl;
        var direct = new GDirections(map,directpanel);
        map.clearOverlays()
        direct.clear();
        direct.load("from: " + fromaddress + " to: " + address);
        var boundsdd = direct.getBounds();
        map.setCenter(boundsdd.getCenter(), map.getBoundsZoomLevel(boundsdd,1000));
        tabinit();
        marker.openInfoWindowHtml(marker_html);
        return false;
      }
      GEvent.addListener(marker, 'click', focusPoint);
      div.onclick = focusPoint;
      /* Removed due to customization ability
      GEvent.addDomListener(div, 'mouseover', function() {
        div.style.backgroundColor = '#eee';
      });
      GEvent.addDomListener(div, 'mouseout', function() {
        div.style.backgroundColor = '#fff';
      });
      ************/
      document.getElementById('infoPanel').appendChild(div);
      map.addOverlay(marker);
      tabinit();

    }

//For the tabbed div.
    function tabinit()
    {
        var myfinder=new ddtabcontent("hauntfinder")
        myfinder.setpersist(false)
        myfinder.setselectedClassTarget("link")
        myfinder.init()
    }
