function init(){
	window.googlemaps()?googlemaps():null;
	}

function googlemaps() {
	if(document.getElementById("map")){
		var mapcenter=document.getElementById('mapcenter').innerHTML;
		var locations=document.getElementById('locations').innerHTML;
		var mapzoom=parseInt(document.getElementById('mapzoom').innerHTML!=undefined?document.getElementById('mapzoom').innerHTML:8);
		if(!(mapzoom>0)){mapzoom=8;}
		 if (GBrowserIsCompatible()) {
			var map = new GMap2(document.getElementById("map"));
			map.addControl(new GSmallZoomControl());
			map.enableDoubleClickZoom();
			var geocoder = new GClientGeocoder();
			function showAddress(address,url) {
				  geocoder.getLatLng(
					address,
					function(point) {
					  if (!point) {
					//  document.getElementById("map").style.display='none'; /* address not found, hide map */
				//	window.alert('no address');
					} else {
				//		map.setCenter(point, 12);
						var marker = new GMarker(point);
						  GEvent.addListener(marker, "click", function() {
						   window.location=(url);
						  });

						map.addOverlay(marker);
					  }
					}
				  );
				}
			function centerMap(address){
				/* the geocoder is (relatively) slow, so we center the map on some arbitrary
				 * spot first because for some reason google maps can't add markers before 
				 * the map is centered someplace.
				 * */
				map.setCenter(new GLatLng(0,0),mapzoom);
				
				geocoder.getLatLng(
					address,function(point){ if (!point) {
					  	//document.getElementById("map").style.display='none'; /* address not found, hide map */
							} else {
								map.setCenter(point, mapzoom);
							  }
						}
					);
				}
			centerMap(mapcenter);
			/* to do: use lat/lon instead of addresses if possible to avoid multiple geocode requests */
			locations=locations.split('|');
			for(var i=0;i<locations.length;i++){
				var locationprops=locations[i].split(';');
				if(document.getElementById('location_'+locationprops[1])){
					var url=document.getElementById('location_'+locationprops[1]).href;
					}else{
					var url=document.location;
					}
				/* check if locationprops[0] looks like coordinates */
				if(locationprops[0].match(/^\([0-9.]+,[0-9.]+\)$/)){
					/* extract the coordinates */
					var latlong=locationprops[0].substring(1,locationprops[0].length-1);
					latlong=latlong.split(',');
					var point = new GLatLng(latlong[0],latlong[1]);
					var marker = new GMarker(point);
					  GEvent.addListener(marker, "click", function() {
						   window.location=(url);
						  });
					map.addOverlay(marker);
					
				}else{
					showAddress(locationprops[0],url);
				}
			}
			//showAddress(address);
		 }
	  }
    }

/*



function addLoadEvent(func)
{	
	var oldonload = window.onload;
	if (typeof window.onload != 'function'){
    	window.onload = func;
	} else {
		window.onload = function(){
		oldonload();
		func();
		}
	}

}
addLoadEvent(init);
*/
