/* 	Google Maps JS Functions
	Author: Kalianto Wong (Mediasphere Sep 2008)
	Version: 1.0
	Dependencies: GOOGLE MAPS API must be called before calling this file
*/

//Load the Google Maps API

function event_google_maps_initLoader() {
	var script = document.createElement("script");
	//script.src = "http://www.google.com/jsapi?key=ABQIAAAAbkAcIled-tNNPEWEvekkFxT9qxJYSQhYlVyC3rvzA95uRfWoRBQ5ZNkx9EN7jMhN7_INax8Bjy9Mkw&callback=loadMaps";
	script.src = "http://www.google.com/jsapi?key="+gm_api_key+"&callback=event_loadMaps";
	script.type = "text/javascript";
	document.getElementsByTagName("head")[0].appendChild(script);
}

function event_mapsLoaded() {
	var map = new google.maps.Map2(document.getElementById("map_display"));
	map.addControl(new google.maps.SmallMapControl());
	map.addControl(new google.maps.MapTypeControl());
	//map.setCenter(new google.maps.LatLng(37.4419, -122.1419), 13);
	//var geocoder = new google.maps.ClientGeocoder();
	//var address = document.getElementById("map_display_info").innerHTML;
	/*
	geocoder.getLatLng(address, function(point){
	if(!point){
		
		document.getElementById("map_display").innerHTML = '<img src="/img/map.jpg" alt="Map Not Available" />';
		
	} else {
		
		map.setCenter(point, 13);
		var marker = new google.maps.Marker(point);
		map.addOverlay(marker);
		//marker.openInfoWindowHtml(address);
	}
	
	});
	*/
	var cLatLng = new google.maps.LatLng(cLat, cLng);
	if(!cLatLng || (cLat == 0 && cLng == 0) ){
		document.getElementById("map_display").innerHTML = '<span class="notfound">Google Map is not enabled for this page.</span>';
	} else {
	
		map.setCenter(cLatLng, 13);
		var marker = new google.maps.Marker(cLatLng);
		map.addOverlay(marker);
		//marker.openInfoWindowHtml(address);
	}
}

function event_loadMaps() {
	google.load("maps", "2", {"callback" : event_mapsLoaded});
}

jQuery(document).ready(function(){
	event_google_maps_initLoader();
});
