    var Markers = new Array();
    var currentMap;
    var mapInfo = new Object();
    var currentField;
    var geocoder = new GClientGeocoder();

    function load(lat, lng, name, divname) {
      var div = divname || 'map';
      if (GBrowserIsCompatible()) {
	      var map = new GMap2(document.getElementById(div));
	      currentMap = map;
		var latLong = new GLatLng(lat,lng);
	map.setCenter(latLong, 13);

	var json = new Object();
	json.title = name;
	json.clickable = false;
	json.icon = getPointIcon();
	var marker = new GMarker(latLong, json);

	mapInfo.title = name;	
	mapInfo.marker = marker;	
	mapInfo.latLong = latLong;

	map.addOverlay(marker);
	//map.addControl(new GSmallMapControl());
	map.addControl(new GSmallZoomControl());
	//map.addControl(new GMapTypeControl());
	//map.addControl(new GScaleControl());
      }
    }

    function reset_map() {
	currentMap.clearOverlays();

	var json = new Object();
	json.title = mapInfo.title;
	json.clickable = false;
	json.icon = getPointIcon();
	var marker = new GMarker(mapInfo.latLong, json);
	currentMap.addOverlay(mapInfo.marker);
	currentMap.setCenter(mapInfo.latLong,13);
    }
    function center_map() {
	currentMap.setCenter(mapInfo.latLong,13);
    }


// Get Address that may or may not have lattitude
var tab1Name = null;
var tab2Name = null;
var tab3Name = null;

function setTabNames(tab1,tab2,tab3) {
		tab1Name = tab1;
		tab2Name = tab2;
		tab3Name = tab3;
	}
function showGenericLatAddress(name,lat,lng,address,tab1,tab2,tab3) {
	if (!name) {
		return;
	}
	if ((lat && lng)&&((lat !=0)&&(lng != 0))) {
		var point = new GLatLng(lat,lng);
		setGenericGmapPoint(point,name,tab1,tab2,tab3);
	}
	else {
 	 geocoder.getLatLng(address,
    		function(point) {
      			if (!point) {
        			//alert(address + " not found");
			} else {
				setGenericGmapPoint(point,name,tab1,tab2,tab3);
			}
		});
	}
}


function showLatAddress(name,Reviews,Contact,lat,lng) {
	var address = Contact.address;
	var numReviews = Reviews.numb;
	var ContactTab = address;
	if (Contact.phone != null) {
		ContactTab += "<br/>"+Contact.phone;
	}
	if (Contact.URL != null) {
		ContactTab += '<br/><a href="'+Contact.URL+'" target="_blank">'+Contact.URL+'</a>';
	}
	if (Contact.email != null) {
		ContactTab =+ '<br/>email:<a href="mailto:'+Contact.email+'">'+Contact.email+"</a>";
	}
	var ReviewsTab = "Number of Reviews: "+Reviews.numb;
	if (Reviews.rating != -1) {
		ReviewsTab += '<br/>Average Rating: <img src="'+Reviews.rating+'">';
	}
	ReviewsTab += '<br/><a href="'+Reviews.URL+'">View/Write Reviews</a>';

	if ((lat && lng)&&((lat !=0)&&(lng != 0))) {
		var point = new GLatLng(lat,lng);
		setGmapPoint(point,name,numReviews,ContactTab,ReviewsTab,Reviews.URL);
	}
	else {
 	 geocoder.getLatLng(address,
    		function(point) {
      			if (!point) {
        			//alert(address + " not found");
			} else {
				setGmapPoint(point,name,numReviews,ContactTab,ReviewsTab,Reviews.URL);
			}
		});
	}
}

/* Set the point */
function setGmapPoint(point,name,numReviews,ContactTab,ReviewsTab,zurl) {
	var json = new Object();
	json.title = name;
	json.icon = getIcon(numReviews);
	var marker = new GMarker(point, json);

	var bizName = name+"";
	if ((zurl != null)&&(zurl != ""))  {
		bizName = '<a href="'+zurl+'">'+bizName+'</a>';
	}
	GEvent.addListener(marker, "click", function() {
		var infoTabs = [
  			new GInfoWindowTab("Name", bizName),
      			new GInfoWindowTab("Contact", ContactTab),
      			new GInfoWindowTab("Reviews", ReviewsTab)
		];
		marker.openInfoWindowTabsHtml(infoTabs);
		});

	//marker.id = id;
	currentMap.addOverlay(marker);
	//Markers[id] = marker;
}
function setGenericGmapPoint(point,name,tab1,tab2,tab3) {
	var json = new Object();
	json.title = name;
	//json.icon = getIcon(numReviews);
	var marker = new GMarker(point, json);
	var infoTabs = new Array();
	if (tab1Name && tab1 ) {
		infoTabs[0] = new GInfoWindowTab(tab1Name,tab1);
	}
	if (tab2Name && tab2 && tab2.length >0 ) {
		infoTabs[infoTabs.length] = new GInfoWindowTab(tab2Name,tab2);
	}
	if (tab3Name && tab3 ) {
		infoTabs[infoTabs.length] = new GInfoWindowTab(tab3Name,tab3);
	}
	GEvent.addListener(marker, "click", function() {
		marker.openInfoWindowTabsHtml(infoTabs);
		});

	//marker.id = id;
	currentMap.addOverlay(marker);
	//Markers[id] = marker;
}
	

function displayMarker(mid) {
	var marker = Markers[mid];
	var newCenter = marker.getPoint();
	currentMap.panTo(newCenter);
	GEvent.trigger(marker,"click");
}
function getIcon(number) {
	var icon = new GIcon(G_DEFAULT_ICON);
	icon.image="http://www.zirana.com/ca/cupertino/images/mapicons/marker"+number+".png";
	return icon;
}
function getPointIcon() {
	var icon = new GIcon(G_DEFAULT_ICON);
	icon.iconSize = new GSize(12, 20); 
	icon.shadowSize = new GSize(22, 20); 
	icon.iconAnchor = new GPoint(6, 20); 
	icon.infoWindowAnchor = new GPoint(5, 1); 
	icon.imageMap = [4,0,0,4,0,7,3,11,4,19,7,19,8,11,11,7,11,4,7,0]; 
	//icon.transparent = "mapIcons/mm_20_transparent.png";
	icon.image="http://labs.google.com/ridefinder/images/mm_20_green.png";
	return icon;
}

	
