/* 	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 google_maps_initLoader() {
  var script = document.createElement("script");
  script.src = "http://www.google.com/jsapi?key="+gm_api_key+"&callback=loadMaps";
  script.type = "text/javascript";
  document.getElementsByTagName("head")[0].appendChild(script);
}

function 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(-24.994167,134.866944), 0); 
  //map.setCenter(new google.maps.LatLng(37.4419, -122.1419), 13);
  
  		//document.getElementById("map_display").innerHTML = '';
		//$j("#map_display").html('');
		//$j("#view_map").css({display:"none"});
		//$("view_map").style.display = "none";


  
  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 = '<div style="padding: 20px; ">Map Not Found -Please <a href="/members">Login</a> to update your address</div>';
		//$j("#map_display").html('');
		//$j("#view_map").css({display:"none"});
		//$("view_map").style.display = "none";
		
  		
  	} else {

		//$j("#view_map").css({display:"block"});
	    var map = new google.maps.Map2(document.getElementById("map_display"));
	  map.addControl(new google.maps.SmallMapControl());
	  map.addControl(new google.maps.MapTypeControl());
		// Create a base icon for all of our markers that specifies the
		// shadow, icon dimensions, etc.
		var baseIcon = new GIcon();
		//baseIcon.shadow = "http://www.chironet.com.au/img/chiro_shadow.png";
		baseIcon.shadow = "http://chironet.securelearn.com/img/chiro_shadow.png";
		baseIcon.iconSize = new GSize(49, 42);
		baseIcon.shadowSize = new GSize(49, 42);
		baseIcon.iconAnchor = new GPoint(9, 34);
		baseIcon.infoWindowAnchor = new GPoint(9, 2);
		baseIcon.infoShadowAnchor = new GPoint(18, 25);
			
		var chiroIcon = new GIcon(baseIcon);
		//chiroIcon.image = "http://www.chironet.com.au/img/chiro_marker.png";
		chiroIcon.image = "http://chironet.securelearn.com/img/chiro_marker.png";
		markerOptions = { icon:chiroIcon }


  		map.setCenter(point, 13);
  		var marker = new google.maps.Marker(point, markerOptions);
  		map.addOverlay(marker);
  		//marker.openInfoWindowHtml(address);
  	}
  
  });
}

function loadMaps() {
  google.load("maps", "2", {"callback" : mapsLoaded});
}

google_maps_initLoader();
