var testing_key = 'ABQIAAAABhh_UR6WRzdMjqBQ2z3kmBRP-vWdI0DG5sJZ9j1S0dDOjST5WRQMZQPJl_ku6R7IOtSQwfQafHKpMg';
var prod_key = 'ABQIAAAABhh_UR6WRzdMjqBQ2z3kmBQeyE5IwjT0HGHhtkaWoAumg8N5gBQhohcAjbmeDAGzdqjD2SsW4xEJUg';

//include the script from google
document.write('<script src="http://maps.google.com/maps?file=api&amp;v=2&amp;key='+prod_key+'" type="text/javascript"></script>'); 

var map;
var geocoder;

var lotImg = 'http://maps.google.com/mapfiles/ms/micons/red-dot.png';
var attractionImg = 'http://maps.google.com/mapfiles/ms/micons/yellow-dot.png';

var mouseoverImg = 'http://maps.google.com/mapfiles/ms/micons/yellow-dot.png';

function showMarkerOnMap(lat,lng,placename,address,linkdetails,markerimage,mouseoverimage,setcenter,zoom)
{
//<![CDATA[
	if (setcenter==undefined) setcenter = false;
	if (zoom==undefined) zoom = 13;

//alert(placename);

	// Retrieve location information, pass it to addToMap()
	if (isNaN(parseFloat(lat,10)) || isNaN(parseFloat(lng,10)) || parseFloat(lat,10)==0 || parseFloat(lng,10)==0)
	{
		geocoder.getLocations(address, getLatLng);
//alert('retrieving lat lng');
	}
	else
	{
		// Retrieve the latitude and longitude
		point = new GLatLng(lat,lng);

		addMarkerToMap(point);		
	}

	function getLatLng(response)
	{
		if (response.Placemark)
		{
			// Retrieve the object
			place = response.Placemark[0];

			// Retrieve the latitude and longitude
			point = new GLatLng(place.Point.coordinates[1],place.Point.coordinates[0]);

			addMarkerToMap(point);			
		}
	}

	function addMarkerToMap(point)
	{
//alert(placename+' '+linkdetails);
		if (setcenter)
		{
			map.setCenter(point, zoom);
//alert(placename+' '+'center set '+zoom);
		}
		
	    var icon = new GIcon(G_DEFAULT_ICON);

		icon.image = markerimage;
	    
		// Create a marker
		var marker = new GMarker(point,icon);
	
		var html = '<form action="http://maps.google.com/maps" method="get" target="_blank" style="background: #fff;">';
		html += '<p><strong>Get Driving Directions<\/strong><br \/><i>Your address</i>: <br \/><input type="text" name="saddr" value="" size=20><\/p>';
		html += '<input type="hidden" name="daddr" value="' + address +'" \/>';
		html += '<input type="submit" value="Get Directions &raquo;"\/><\/form>'; 

		GEvent.addListener(marker, "click", function() 
		{
			var link = "";
			if (linkdetails!=undefined) link = '<br />'+linkdetails;
			marker.openInfoWindowHtml("<p><strong>"+placename+"<\/strong><br \/>"+address+link+"<\/p>"+html);
		});	
		// Switch icon on marker mouseover and mouseout
        GEvent.addListener(marker, "mouseover", function() {
         marker.setImage(mouseoverimage);
        });
        GEvent.addListener(marker, "mouseout", function() {
          marker.setImage(markerimage);
        });
		// Add the marker to map
		map.addOverlay(marker);
	}
//]]>
}

function initmap()
{
//<![CDATA[

	if (GBrowserIsCompatible()) 
	{
		// Create new map object
		map = new GMap2(document.getElementById("map"));
		// Create new geocoding object
		geocoder = new GClientGeocoder();
		map.addControl(new GLargeMapControl());
		map.addControl(new GMapTypeControl());	
		
		return true;	
	}
	else
		return false;

//]]>

}