// jsGoogleMapPlace.js

var marker2 = 0;
// Create a base icon for all of our markers that specifies the
// shadow, icon dimensions, etc.

//function CreateMapTiny(mapdiv,lat,long) {
//	var map = new GMap2(document.getElementById(mapdiv));
//	map.setCenter(new GLatLng(lat,long), 13);
//}

function CreateMapPlace(mapdiv,lat,long,zoom,pointer,placename,blurb) {
	var map = new GMap2(document.getElementById(mapdiv));
	map.setCenter(new GLatLng(lat,long), zoom);
	map.addControl(new GSmallMapControl());
	map.addControl(new GMapTypeControl());
//	map.centerAndZoom(new GPoint(lat, long), zoom);
//	if(callout <> '')
//		map.openInfoWindow(map.getCenterLatLng(),	document.createTextNode("<?=$callout?>"));
	
	// add place marker
//	var point = new GPoint(lat, long);
//	var marker = new GMarker(point);
//	map.addOverlay(marker);
	
	var point = new GLatLng(lat, long);
	marker = new GMarker(point)
	map.addOverlay(marker);

	//add text balloon
	var text = '<p style="text-align: left">';
	text += blurb;
	marker.openInfoWindowHtml(text);

	// Add listener that will detect click and display long/lat in the div id=message on the page
//	GEvent.addListener(map, 'moveend', function() {
//		var center = map.getCenterLatLng();
//		var latLngStr = '(' + center.y + ', ' + center.x + ')';
//		document.getElementById("message").innerHTML = latLngStr;
//	});

	/* / Add listener for a click on the map
	GEvent.addListener(map, 'click', function(overlay, point) {
		if(marker2)	map.removeOverlay(marker2); // remove prev marker
		
		var icon = new GIcon(baseIcon);
		icon.image = "http://www.google.com/mapfiles/markerA.png";

		marker2 = new GMarker(point,icon); // set marker to new point
		map.addOverlay(marker2); // add the marker
		
		// get point coords and display on page.
		var latLngStr = '(' + point.y + ', ' + point.x + ')';
		document.getElementById("message").innerHTML = latLngStr;
		/*
		if (overlay) {
		map.removeOverlay(overlay);
		} else if (point) {
		map.addOverlay(new GMarker(point));
		}
	});*/

}

// Create a marker whose info window displays the letter corresponding
// to the given index.
function createMarker(point, index) {
	// Create a lettered icon for this point using our icon class from above
	var letter = String.fromCharCode("A".charCodeAt(0) + index);
	var icon = new GIcon(baseIcon);
	icon.image = "http://www.google.com/mapfiles/marker" + letter + ".png";
	var marker = new GMarker(point, icon);
	
	// Show this marker's index in the info window when it is clicked.
	var html = "Marker <b>" + letter + "</b>";
	GEvent.addListener(marker, 'click', function() {
	marker.openInfoWindowHtml(html);
	});
	
	return marker;
}


// A function to create a marker on the map with the given info
function createMarker2(lng, lat, letter) {
	// Create a point
	var point = new GPoint(lng, lat);
	// Create a new icon
	var icon = new GIcon(baseIcon);
	icon.image = "http://www.google.com/mapfiles/marker.png";
	var marker = new GMarker(point, icon);
	return marker;
}

// A function to create a marker on the map with the given info
function createMarkerWithText(lng, lat, letter, html_text) {
	// Create a point
	var point = new GPoint(lng, lat);
	// Create a new icon
	var icon = new GIcon(baseIcon);
	icon.image = "http://www.google.com/mapfiles/marker.png";
	var marker = new GMarker(point, icon);
	// GEvent.addListener(marker, "click", function () { marker.openInfoWindowHtml(html_text); });
	return marker;
}

/*
var baseIcon = new GIcon();
baseIcon.shadow = "http://www.google.com/mapfiles/shadow50.png";
baseIcon.iconSize = new GSize(20, 34);
baseIcon.shadowSize = new GSize(37, 34);
baseIcon.iconAnchor = new GPoint(9, 34);
baseIcon.infoWindowAnchor = new GPoint(9, 2);
baseIcon.infoShadowAnchor = new GPoint(18, 25);

*/
