//<![CDATA[

  var map = null;
  var geocoder = null;
  var icon = null;
  var page = 1;
 
  var tooltip = document.createElement("div");
  tooltip.setAttribute("id","div_marker_tooltip");
  tooltip.setAttribute("class","tooltip");
  tooltip.style.border="1px #666 solid";
  tooltip.style.backgroundColor="#ffffff";
  tooltip.style.fontWeight="bold";
  //tooltip.style.overflow="hidden";
  tooltip.style.position="absolute";
  //tooltip.style.top="-0.25em";
  tooltip.style.left="-0.25em";
  tooltip.style.zIndex="0";
  
  function load() {
      if (GBrowserIsCompatible()) {
          map = new GMap2(document.getElementById("googleMap"));
          map.enableDoubleClickZoom();
          map.addControl(new GLargeMapControl());
          map.addControl(new GMapTypeControl());
          map.setCenter(new GLatLng('28.53854', '-81.378983'), 10);	
          
          document.getElementById("googleMap").appendChild(tooltip);
          tooltip.style.visibility="hidden"; 
          
          //map.setMapType(G_HYBRID_MAP);
          geocoder = new GClientGeocoder();
          //geocoder.setCache(null);
          icon = new GIcon();
          icon.image = "/idx/images/arrow.png";
          icon.iconSize = new GSize(20, 23);
          icon.iconAnchor = new GPoint(6, 6);
          icon.infoWindowAnchor = new GPoint(9, 2);
          //searchListings();
      }
  }
    
  function searchListings(resultsContainer) {
      loadingImage();
            
	  // get search parameters
	  areaSearch = $('map_area').options[$('map_area').selectedIndex].value;
	  typeSearch = $('map_proptype').options[$('map_proptype').selectedIndex].value;
	  bathSearch = $('map_bathrooms').options[$('map_bathrooms').selectedIndex].value;
	  bedrSearch = $('map_bedrooms').options[$('map_bedrooms').selectedIndex].value;
	  minpSearch = $('map_price_min').options[$('map_price_min').selectedIndex].value;
	  maxpSearch = $('map_price_max').options[$('map_price_max').selectedIndex].value;
	  /*
	  if ($('map_pool_yn').checked) {
    	  poolSearch = $('map_pool_yn').value;
	  } else {
	      poolSearch = '';
	  }
	  */
	  poolSearch = '';
	  // build query string
	  
	  // showArea(citySearch);
	  queryString = '?city=' + escape(areaSearch) +
	                '&type=' + typeSearch +
	                '&bathrooms=' + bathSearch +
	                '&bedrooms=' + bedrSearch +
	                '&min_price=' + minpSearch +
	                '&max_price=' + maxpSearch +
	                '&pool_yn=' + poolSearch +
	                '&callback=1';
	  new Ajax.Updater('searchResults', '/idx/map/search.php' + queryString, {
   	                  onComplete:function(request) { },
					  evalScripts:true, asynchronous:true });
  }
  
  function searchResultsMsg (message) {
      $('searchResults').innerHTML = message;
  }
  
  function loadingImage() {
      map.clearOverlays();
      addCustomControl();
      searchResultsMsg("");
      $('updateMap').disabled = true;
      $('updateMap').value = 'Loading...';
      $('searchResults').style.visibility="hidden";
  }
  
  function searchImage() {
      removeCustomControl();
      $('updateMap').disabled = false;
      $('updateMap').value = 'Update Map';
      $('searchResults').style.visibility="visible";
  }
  
  function showTooltip(marker) {
      tooltip.innerHTML = marker.tooltip;
      var point = map.getCurrentMapType().getProjection().fromLatLngToPixel(map.getBounds().getSouthWest(), map.getZoom());
      var offset = map.getCurrentMapType().getProjection().fromLatLngToPixel(marker.getPoint(), map.getZoom());
      var anchor = marker.getIcon().iconAnchor;
      var width = marker.getIcon().iconSize.width;
      var height = marker.getIcon().iconSize.height;
      var pos = new GControlPosition(G_ANCHOR_BOTTOM_LEFT, new GSize(offset.x - point.x - anchor.x + width,- offset.y + point.y +anchor.y)); 
      pos.apply(tooltip);
      tooltip.style.visibility="visible";
  } 
  
  
var customControl;

function addCustomControl () {
    
    //var innerHTML = innerHTML;
    
    removeCustomControl();
    
    function CustomControl() {
    }

    CustomControl.prototype = new GControl();

    CustomControl.prototype.initialize = function (map) {
      var container = document.createElement("div");
      this.setButtonStyle_(container);
      container.appendChild(document.createTextNode(''));
      map.getContainer().appendChild(container);
      return container;
    }

    CustomControl.prototype.getDefaultPosition = function() {
      return new GControlPosition(G_ANCHOR_TOP_LEFT, new GSize(175, 125));
    }

    CustomControl.prototype.setButtonStyle_ = function(button) {
      //button.innerHTML  = innerHTML;
      button.innerHTML  = '<img src="/idx/images/loading.gif" align="center"><br /><img src="/idx/images/loading_bar.gif" align="center">';
      button.style.textDecoration = "underline";
      button.style.color = "#0000cc";
      button.style.backgroundColor = "white";
      button.style.font = "small Arial";
      button.style.border = "1px solid black";
      button.style.padding = "20px";
      button.style.marginBottom = "3px";
      button.style.textAlign = "center";
      button.style.width = "100px";
      button.style.cursor = "pointer";
    }
    
    customControl = new CustomControl();
    
    map.addControl(customControl);
    map.disableDragging();
   
}

function removeCustomControl() {
    map.removeControl(customControl);
    map.enableDragging();
}
  
  

//]]>