var map;
var geocoder;
var current_point; 
function initializeMap() {
	map = new GMap2(document.getElementById("gmap"));
	map.removeMapType(G_HYBRID_MAP);
	map.setCenter(new GLatLng(34,-89), 3);
	var bottomRight = new GControlPosition(G_ANCHOR_BOTTOM_RIGHT, new GSize(10,10));
	map.addControl(new GSmallMapControl(), bottomRight);
	var mapControl = new GMapTypeControl();
	map.addControl(mapControl);
	markLocations(); 
}
function markLocations() {
	locations.each(function(item,index){
		point = new GLatLng(item.lat,item.lng);
		map.addOverlay(createMarker(point,index+1,item.info));
	}); 
}
function createMarker(point,number,str) {
	var marker = new GMarker(point);
		marker.value = number;
	GEvent.addListener(marker, "click", function() {
		infoWindow(point,str); 
	});
	return marker;
}
function infoWindow(point,str) {
	if(current_point==point) return; 
	map.openInfoWindowHtml(point,str);
	current_point = point; 
}
function showLocation(lat,lng,str) {
	point = new GLatLng(lat,lng);
	map.panTo(point);
	infoWindow(point,str); 
}
/****
GMAP GEOCODE EXAMPLE
// addAddressToMap() is called when the geocoder returns an
// answer.  It adds a marker to the map with an open info window
// showing the nicely formatted version of the address and the country code.
// geocoder = new GClientGeocoder();
function addAddressToMap(response) {
	map.clearOverlays();
	if (!response || response.Status.code != 200) {
		alert("Sorry, we were unable to geocode that address");
	} else {
		place = response.Placemark[0];
		point = new GLatLng(place.Point.coordinates[1],place.Point.coordinates[0]);
		marker = new GMarker(point);
		map.addOverlay(marker);
		marker.openInfoWindowHtml(place.address + '<br>' +
		'<b>Country code:</b> ' + place.AddressDetails.Country.CountryNameCode);
		alert(place.Point.coordinates[1]+"\n"+place.Point.coordinates[0]); 
	}
}
// showLocation() is called when you click on the Search button
// in the form.  It geocodes the address entered into the form
// and adds a marker to the map at that location.
function showLocation(address) {
	geocoder.getLocations(address, addAddressToMap);
}
****/