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

function addUnloadEvent(func) {
	// Allow multiple unloaders
	var oldonunload = window.onunload;
	if (typeof window.onunload != 'function') {
		window.onunload = func;
	} else {
			window.onunload = function() {
				oldonunload();
				func();
			}
	}
}

var map = null;
var points = [
			{ posn : [50.222733,-5.386348], shortname: "churchTown", title: "Church Town Farm Campsite", html : "<h1>Church Town Farm Campsite</h1><p>situated close to the church in Gwithian, over looking St Ives Bay. A quiet, family-run site set in 5.5 acres, with spacious pitches.</p>", center : false },
			{ posn : [50.20469,-5.40405], shortname: "stIvesBay", title: "St Ives Bay Holiday Park", html : "<h1>St Ives Bay Holiday Park</h1><p>Mid way along St Ives bay, with facilities inculding houses, chalets, caravans and camping.</p>", center : false },
			{ posn : [50.201916,-5.415294], shortname: "beachside", title: "Beachside Holiday Park", html : "<h1>Beachside Holiday Park</h1><p>Overlooking St Ives bay, catering for chalets, caravans and tents.</p>", center : false },
			{ posn : [50.219081,-5.382442], shortname: "carlize", title: "Carlize Country House", html : "<h1>Carlize Country House</h1><p>Set back from the bay, they offer B&B and a self catered cottage.</p>", center : false },
			{ posn : [50.229377, -5.386863], shortname: "sandsifter", title: "sandsifter", html : '<img name="sandsifterlogox94" src="images/logos/sandsifter-logox94.gif" width="94" height="17" border="0" alt="sandsifter logo" /><p>good food & drink in a relaxed contemporary atmosphere, live music on Friday and Saturday evenings, plus Surf shop and Surf lessons by the beach.</p>', center : true },
			{ posn : [50.211707, -5.389588], shortname: "atlantic", title: "Atlantic Coast Caravan Park", html : "<h1>Atlantic Coast Caravan Park</h1<p>caravan and camping site, situated behind the sand dunes bordering Gwithian Beach.</p>", center : false }
			];
function loadMap() {
  var zoom = 13;
  if (GBrowserIsCompatible()) {
	map = new GMap2(document.getElementById("map"));
	map.addControl(new GLargeMapControl());
	map.addControl(new GMapTypeControl());
	map.setCenter(new GLatLng(50.229377,-5.386863), zoom,G_HYBRID_MAP);
	for(var i=0;i<points.length;i++) {	
		var place = points[i];
		var point = new GLatLng(place["posn"][0], place["posn"][1]);
		points[i]["marker"] = createMarker(point,place["title"],'<div class="mapBubble">'+place["html"]+'</div>');
		map.addOverlay(points[i]["marker"]);
		if (place.center) map.setCenter(point, zoom,G_HYBRID_MAP);
	}
 }
}

function moveToMarker(name) {
	for(var i=0;i<points.length;i++) {
		if (points[i]["shortname"] == name) {
			//map.panTo(points[i].marker.getPoint());
			points[i].marker.openInfoWindowHtml('<div class="mapBubble">'+points[i]["html"]+'</div>');
			//points[i].marker.showMapBlowup({zoomLevel:17});
			return false;			
		}
	}
}

// Creates a marker at the given point with the given number label
function createMarker(point, name, html) {
  var marker = new GMarker(point, {title: name});
  GEvent.addListener(marker, "click", function() {
    marker.openInfoWindowHtml(html);
  });
  return marker;
}

addLoadEvent(loadMap);
addUnloadEvent(GUnload);