var map = null;
var geocoder = null;
var marker = new Array();
var markerHTML = new Array();
var markerLink = new Array();

// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

$(document).ready(function(){

	// - - - - - - - - - - - - - - - - - - - - - - - - - 
	
	$('.scrollpane').jScrollPane({showArrows:true,scrollbarWidth:23,scrollbarMargin:0});
	
	// - - - - - - - - - - - - - - - - - - - - - - - - - 
	
	$("a#map-view").click(function () { 
	
		// $(".map-view").show();
		$(".list-view").hide();
		$("a#map-view").hide();
		$("a#list-view").show();
		return false;
	});
	
	$("a#list-view").click(function () { 
	
		$(".list-view").show();
		$("a#map-view").show();
		$("a#list-view").hide();
		return false;
	});
	
	// - - - - - - - - - - - - - - - - - - - - - - - - - 
	
	map = new GMap2(document.getElementById("map"));
    geocoder = new GClientGeocoder();
    
    map.addControl(new GSmallMapControl());

});

// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

function showAddress(address,id) {
  geocoder.getLatLng(
    address,
    function(point) {
      if (!point) {
        // alert(address + " not found");
      } else {
        // map.setCenter(point, 14);
     	marker[id] = new GMarker(point);
        map.addOverlay(marker[id]);
        map.setCenter(new GLatLng(40.7615819, -73.9941664), 14);
       
       GEvent.addListener(marker[id], "mouseover", function() {
			marker[id].openInfoWindow(markerHTML[id]);
   		});
   		
   		 GEvent.addListener(marker[id], "mouseout", function() {
			marker[id].closeInfoWindow();
   		});
   		
   		GEvent.addListener(marker[id], "click", function() {
   			document.location = markerLink[id];
   		});
      }
    }
  );
}
