﻿function initializeGoogleMap(map_id, info_id, address_id)
{
	window.onunload = GUnload;
	
	function echo(s)
	{
		document.body.appendChild(document.createTextNode(s));
		document.body.appendChild(document.createElement('br'));
	}

	if (GBrowserIsCompatible())
	{
		var info_div = document.getElementById(info_id);
		var info = info_div.innerHTML;
		var address_html = document.getElementById(address_id).innerHTML;
		var address = address_html.replace(/<br( \/)?>/gi, ', ').replace(/[\t\r\n]/g, ' ').replace(/(^ +)|( +$)/g, '');
		//info_div.parentNode.removeChild(info_div);

		var map = new GMap2(document.getElementById(map_id));
		var geocoder = new GClientGeocoder();

		geocoder.getLatLng(
			address,
			function(latlng)
			{
				function showBubble()
				{
					var a = escape(address.replace(/(['"])/g, '\\$1'));
					map.openInfoWindowHtml(latlng, '<h2>Smoothie King</h2><p>'+address_html+'<br /><a href="http://maps.google.com/maps?q='+a+'">View Larger Map / Get Directions</a></p>');
				}

				if (latlng)
				{
					map.setCenter(latlng, 14);
					var marker = new GMarker(latlng);  

					GEvent.addListener(
						marker,
						"click",
						showBubble
					);
					
					map.addOverlay(marker);

					//showBubble();
				}
				
			}
		);
	}
	
}
