var map 		= null;
var geocoder 	= null;

function showMap(point) {
	if (point) {
		$(".mapRelated").each(function(){ this.style.display = ""; });
		var myHtml = '<div class="hint">'+$address+'</div>';

		map 	= new GMap2(document.getElementById("map_canvas"));
		map.addControl(new GSmallMapControl());
		map.openInfoWindowHtml(point, myHtml);
		map.setCenter(point, 15);
	}
}

function locate() {
	showAddress(address, latlon);
}

function arealocate() {
	var $x	= $markers.length;
	var addr= '';
	while ($x--) {
		setMarker((new GLatLng($markers[$x][1], $markers[$x][0])), $x, $bounds);
	}
}


function initialize() {
	if (GBrowserIsCompatible()) {
		geocoder = new GClientGeocoder();
	}
}

function showAddress(address, point) {
	if (geocoder) {
		if (point) {
			point	= point.split(",");
			point	= new GLatLng(point[1], point[0]);
			showMap(point);
		} else {
			geocoder.getLatLng(
				address,
				function(point) {
					if (point) {
						showMap(point);
					}
				}
			);
		}
	}
}

function setMarker(point, num, bounds) {
	var tinyIcon = new GIcon();
	tinyIcon.image = "/images/marker_club.png";
	tinyIcon.shadow = "/images/marker_club_sh.png";

	tinyIcon.iconSize = new GSize(15, 18);
	tinyIcon.shadowSize = new GSize(14, 6);
	tinyIcon.iconAnchor = new GPoint(7, 18);
	tinyIcon.maxHeight = 18;

	var marker = new GMarker(point, {icon:tinyIcon,draggable:false,clickable:true});
	map.addOverlay(marker);
	GEvent.addListener(marker, "click", function(a,b) {
		var $club	= $clubs[num];
//		var $html	= '<div class="hint">'+$club.image+'<h3>'+$club.title+'</h3>'+$club.address+'</div>';
		var $html	= '<div class="hint"><h3>'+$club.title+'</h3>'+$club.image+$club.address+$club.place+''+'</div>';
		map.openInfoWindowHtml(point, $html, {
				onCloseFn: function(){
					map.setCenter(bounds.getCenter(), Math.min(map.getBoundsZoomLevel(bounds), 14));
				},
				maxWidth: 320
		});
	});

}

var map;

function embedMap(id, bounds) {
	map 	= new GMap2(document.getElementById(id));
	map.addControl(new GSmallMapControl());
	map.setCenter(bounds.getCenter(), Math.min(map.getBoundsZoomLevel(bounds), 14));
}

