/*
 * initialize Google Map
 */
function load()
{
	if (GBrowserIsCompatible()) 
	{
		map = new GMap2(document.getElementById(MAP_ID));
		map.addControl(new GSmallZoomControl());
		GEvent.addListener(map, "moveend", updateMap);
		initMap();
	}
}
/*
 * performs default initialization of the map
 */
function initMap() {
	var geocoder = new GClientGeocoder();
	geocoder.getLatLng(
   		res_postcode +", " + res_country,
   		function(point) {
   			if (!point) {
				if (res_lat == 0 && res_long == 0) { 
					map.setCenter(new GLatLng(51.500197,-0.126197), 3);
      			} else {
        			map.setCenter(new GLatLng(res_lat, res_long), 13);
        		}
      		} else {
        		map.setCenter(point, 13);
      		}
    	}
  	);	
}
/*
 * callback function to update page
 */
function updateRestaurants(result) {
	eval("var res = " + result.responseText);
	mapRestaraunts(res.results);
}

/*
 * map "moveed" event handler
 */
function updateMap() {
	var bounds = getMapBounds(map);
	AJAXrequest("http://www.booktoeat.com/get_results.php?t_lat=" + res_lat + "&t_lng=" + res_long + "&max_count=5&min_lat=" + bounds.min_lat + "&max_lat=" + bounds.max_lat + "&min_lng=" + bounds.min_lng + "&max_lng=" + bounds.max_lng, updateRestaurants, function(){});
}

window.onload   = load;
window.onunload = GUnload;