

var locations;
var map;
var geocoder;




function showAddress(location) {
  var html = "<b>"+location.name +"</b><br/>";

  var bubbleHtml = html;

  var directionsLink = '<a href="http://maps.google.com/maps?saddr=&daddr=' + encodeURI(location.address) + '" target ="_blank">Click for Driving Directions</a>';

  bubbleHtml += "<p>" + directionsLink + "</p>";

  html += "<p>" + location.full_address + "<br/>" + directionsLink + "</p>";

  if (location.atm) {
	html += "<p><b>ATM LOCATION:</b><br/>" + location.atm + "</p>";
	bubbleHtml += "<p><b>ATM LOCATION:</b><br/>" + location.atm + "</p>";
  }

  if (location.lobby) {
	html += "<p><b>LOBBY HOURS:</b><br/>" + location.lobby + "</p>";
  }

  if (location.drive_up) {
	html += "<p><b>DRIVE UP HOURS:</b><br/>" + location.drive_up + "</p>";
  }

  geocoder.getLatLng(
    location.address,
    function(point) {
      if (!point) {
        alert(location.address + " not found");
      } else {
        var marker = new GMarker(point);
        map.addOverlay(marker);
	 GEvent.addListener(marker, "click", function() {
          $('bankingbarint').innerHTML = html	;
	  marker.openInfoWindowHtml(bubbleHtml);});
      }
    }
  );

}

function processJSON(jsonData){
         locations = eval('('+jsonData.responseText+')');
         for (i=0; i<=locations.length; i++) {
                showAddress(locations[i]);
        }
}



    function doload() {
      if (GBrowserIsCompatible()) {
	$('bankingbarint').innerHTML="<b>To use the map:</b><p>Click on any of the pushpins in the map to view information about that branch.</p> <p>Click and drag in the map window to navigate.</p>";
        map = new GMap2(document.getElementById("gmap"));
        map.addControl(new GLargeMapControl());
        map.addControl(new GScaleControl());

//http://maps.google.com/maps?f=q&hl=en&geocode=&q=ft.+myers,+fl&ie=UTF8&ll=26.643776,-81.852264&spn=0.630914,1.109619&z=10&om=1

        map.setCenter(new GLatLng(26.643776, -81.852264), 10);
        geocoder = new GClientGeocoder();
        var req = new Ajax.Request('locations.pl',{
		method:'get',
                onSuccess:processJSON
        });
      }
}

