var map;
var icon0;

function loadMap(lat, lng, zm) {
	map = new GMap2($('map'));
	map.addControl(new GLargeMapControl());
	map.addControl(new GMapTypeControl());
	map.setCenter(new GLatLng(lat, lng), zm, G_SATELLITE_MAP);
	icon0 = new GIcon();
	icon0.image = "http://www.google.com/mapfiles/marker.png";
	icon0.shadow = "http://www.google.com/mapfiles/shadow50.png";
	icon0.iconSize = new GSize(20, 34);
	icon0.shadowSize = new GSize(37, 34);
	icon0.iconAnchor = new GPoint(9, 34);
	icon0.infoWindowAnchor = new GPoint(9, 2);
	icon0.infoShadowAnchor = new GPoint(18, 25);
}

function addPoint(lat, lng, txt) {
	var point = new GPoint(lat, lng);
	var marker = createMarker(point, icon0, txt);
	map.addOverlay(marker);
	console.log(map);
}

function createMarker(point, icon, popuphtml) {
	var popuphtml = '<div id="popup">'+popuphtml+'</div>';
	var marker = new GMarker(point, icon);
	GEvent.addListener(marker, 'click', function() {
		marker.openInfoWindowHtml(popuphtml);
	});
	return marker;
}

function toggleMap(link, lat, lng, zm, show_txt, hide_txt, txt){
	if ($('map').innerHTML.blank()) {
		loadMap(lat, lng, zm);
		addPoint(lat, lng, txt);
	}
	if (link.innerHTML == show_txt) {
		link.update(hide_txt);
		$('map').show();
	} else if (link.innerHTML == hide_txt) {
		link.update(show_txt);
		$('map').hide();
	}
}
