
  Event.observe(window, 'load', loadGMaps );
  
  var map;
  
  function loadGMaps() {

      qs = window.location.search.toQueryParams();
      map = new Gmaps( "map" );
      if ( qs.width )
        map.width = parseInt( qs.width );
      else
        map.width = 770;
      map.height = 550;
      
      // if a manual zoom level is specified, we use this value for the zoom
      if ( qs.zoom )
        map.zoomLevel = parseInt(qs.zoom);
      else
        map.zoomLevel = 12;      
      
      //map.markerImg = "hotel.png";
      map.showMap();
      
      if ( qs.centreat )
        map.geocode( qs.centreat, function( results, status ) { map.centerMap( results[0].geometry.location ) } );

      if ( properties && properties.property ) {
        var data = properties.property;

        for ( var a=0; a < data.length; a++ ) {
          
            if ( a == 0 && !qs.centreat ) {
                centerIt = true;
            } else {
                centerIt = false;
            }
          
            if( data[a].latitude.length == 0 || data[a].longitude.length == 0  ) {
                map.addGeoMarkerWithStreetView( data[a].address, buildBox( data[a] ), "click", centerIt, data[a].mapHead );
            } else {
                map.addMarkerWithStreetView( data[a].latitude, data[a].longitude, buildBox( data[a] ), "click", centerIt, data[a].mapHead );
                //map.addMarker( data[a].latitude, data[a].longitude, buildBox( data[a] ), "click", centerIt );
            }
  
        }
      }
      
      if ( !qs.centreat )
        setTimeout("map.centerByAveragePoint();", 2000);

  }
  
  
  function buildBox( obj ) {
  
      var sReturn = "";
      // heading
      sReturn += "<h2>";
      sReturn += "<a style=\"text-decoration:none;\" href='http://" + domain + obj.friendlyURL + "' target='_blank'>" + obj.mapHead + "</a>";
      sReturn += "</h2>";
      
      // hotel image
      if ( obj.image.length > 0 ) {
          sReturn += "<img style='border: 1px solid #000; float:left; margin-bottom: 10px;' src='http://" + domain + obj.image + "' width='120' height='76' />";
      }
      
      // paragraph to hold everything else
      sReturn += "<p style='float:left; padding-left:6px; margin-bottom: 10px; margin-top: -4px; width: 114px;'>";
      sReturn += "<span style='font-size:11px; line-height: 15px; display: block; padding-top: 2px;'>" + obj.address.replace("+", "<br />").replace(/\+/g, " ").replace(" AU", "") + "</span>";
      sReturn += "<span style='display: block;font-size:11px;line-height: 15px;'><a href='http://" + domain + obj.friendlyURL + "' target='_blank'>Book Now...</a></span>";
      sReturn += "</p>";
      
      return sReturn;
  }

