/*  Mull maps */
// map0: map with  clickable overlays
// map1: map with Mull highlighted,changes centre on zoom
// map2: plain map, no overlays.

	function fileopenedalert() {
		alert ("mullmaps opened");
	}

	var map0, map1, map2;

		function loadmap0(startZoom) {
//			alert ("StartZoom is " + startZoom);
			if (GBrowserIsCompatible()) {
				map0 = new GMap2(document.getElementById("map0"));
				map0.addMapType(G_PHYSICAL_MAP);
				var center = new GLatLng(56.4500, -6.0300);
//			alert ("StartZoom is " + startZoom);
				map0.setCenter(center, startZoom, G_PHYSICAL_MAP);

// Set up map type menu relationships
				var mapControl = new GMenuMapTypeControl(true); // true allows short names for map types
//				mapControl.clearRelationships();
//				mapControl.addRelationship(G_SATELLITE_MAP, G_HYBRID_MAP, "Labels", false);


// Add control after specifying the relationships
				map0.addControl(mapControl);
				map0.addControl(new GSmallMapControl());
				map0.addControl(new GScaleControl());

// Fionnphort marker (fionn)
				var posn = new GLatLng(56.324941, -6.365019);
				var fionn = new GMarker(posn);
				GEvent.addListener(fionn, "click", function() {
				fionn.openInfoWindowHtml(fionnData);
				});
				map0.addOverlay(fionn);

// Create our "tiny" marker icon
				var blueIcon = new GIcon(G_DEFAULT_ICON);
				blueIcon.image = "http://www.google.com/intl/en_us/mapfiles/ms/micons/blue-dot.png";
// Set up our GMarkerOptions object
				markerOptions = { icon:blueIcon };

// Maolbhuidhe marker (maolb)
//				var posn = new GLatLng(56.330173, -6.342797);
//				var maolb = new GMarker(posn, markerOptions);
//				GEvent.addListener(maolb, "mouseover", function() {
//					maolb.openInfoWindowHtml(maolbData);
//				});
//				map0.addOverlay(maolb);

// Druimnacroish marker (druim)
//				var posn = new GLatLng(56.56725, -6.15730);
//				var druim = new GMarker(posn, markerOptions);
//				GEvent.addListener(druim, "click", function() {
//					druim.openInfoWindowHtml(druimData);
//				});
//				map0.addOverlay(druim);

// Regional marker polygons
				polyNW = new GPolygon([
				new GLatLng(56.672, - 6.100),
				new GLatLng(56.561, -5.952),
				new GLatLng(56.496, -6.156),
				new GLatLng(56.529, -6.352),
				new GLatLng(56.607, -6.368),
				new GLatLng(56.672, -6.100)
				], "#000000", 0, 1, "#ff0000", 0.2);
				map0.addOverlay(polyNW);

				polyCT = new GPolygon([
				new GLatLng(56.561, -5.952),
				new GLatLng(56.517, -5.775),
				new GLatLng(56.438, -6.000),
				new GLatLng(56.358, -6.232),
				new GLatLng(56.529, -6.352),
				new GLatLng(56.496, -6.156),
				new GLatLng(56.561, -5.952)
				], "#000000", 0, 1, "#0000ff", 0.2);
				map0.addOverlay(polyCT);

				polySE = new GPolygon([
				new GLatLng(56.517, -5.775),
				new GLatLng(56.462, -5.622),
				new GLatLng(56.370, -5.658),
				new GLatLng(56.295, -5.862),
				new GLatLng(56.438, -6.000),
				new GLatLng(56.517, -5.775)
				], "#000000", 0, 1, "#ffff00", 0.2);
				map0.addOverlay(polySE);

				polySW = new GPolygon([
				new GLatLng(56.438, -6.000),
				new GLatLng(56.295, -5.862),
				new GLatLng(56.246, -6.428),
				new GLatLng(56.359, -6.479),
				new GLatLng(56.358, -6.232),
				new GLatLng(56.438, -6.000)
				], "#000000", 0, 1, "#00ff00", 0.2);
				map0.addOverlay(polySW);


				GEvent.addListener(map0, 'click', function(overlay, latlng, overlaylatlng) {
// GLog.write("map0 click ("+overlay+","+latlng+","+overlaylatlng+")");
					if (overlay) {
						if (overlay instanceof GPolygon) {
							if (overlay.isHidden()) {
								overlay.show();
							} else {
								overlay.hide();
							}
						}
					} else if (latlng) {
						if (polyNW.Contains(latlng)) {polyNW.show();}
						if (polyCT.Contains(latlng)) {polyCT.show();}
						if (polySE.Contains(latlng)) {polySE.show();}
						if (polySW.Contains(latlng)) {polySW.show();}
					}
				});

// Draggable marker with LatLong read-out
var marker = new GMarker(center, {draggable: true});
//var bounds = map0.getBounds();
//var southWest = bounds.getSouthWest();
//var northEast = bounds.getNorthEast();
//var lngSpan = northEast.lng() - southWest.lng();
//var latSpan = northEast.lat() - southWest.lat();
GEvent.addListener(marker, "dragstart", function() {
	map0.closeInfoWindow();
	});
GEvent.addListener(marker, "dragend", function(GLatLng) {
	var lat = GLatLng.lat();
	var lng = GLatLng.lng();
	marker.openInfoWindowHtml("Lat: " + lat+ ",<br />Long: " + lng);
	});
map0.addOverlay(marker);
	}
}
//  END of loadmap0

	function loadmap1() {
		if (GBrowserIsCompatible()) {
			map1 = new GMap2(document.getElementById("map1"),{ size: new GSize(300,300) });
			map1.addMapType(G_PHYSICAL_MAP);
			var startZoom = 6;
			var center = new GLatLng(56.4500, -4.7240);
			var mullCentre = new GLatLng(56.4500, -6.0300);
//			map1.setCenter(center, 6);
			map1.setCenter(center, startZoom, G_PHYSICAL_MAP);

// Set up map type menu relationships
			var mapControl = new GHierarchicalMapTypeControl();
			mapControl.clearRelationships();
			mapControl.addRelationship(G_SATELLITE_MAP, G_HYBRID_MAP, "Labels", false);

// Add control after specifying the relationships
			map1.addControl(mapControl);
			map1.addControl(new GLargeMapControl());
			map1.addControl(new GScaleControl());

			polyMull = new GPolygon([
			new GLatLng(56.672, - 6.100),
			new GLatLng(56.561, -5.952),
			new GLatLng(56.517, -5.775),
			new GLatLng(56.462, -5.622),
			new GLatLng(56.370, -5.658),
			new GLatLng(56.295, -5.862),
			new GLatLng(56.246, -6.428),
			new GLatLng(56.359, -6.479),
			new GLatLng(56.607, -6.368),
			new GLatLng(56.672, -6.100)
			], "#000000", 0, 1, "#ff0000", 0.4);
			map1.addOverlay(polyMull);

//	Re-centres on Mull and hides overlay above startZoom (6). Map can be manually re-centred
			GEvent.addListener(map1, "zoomend", function() {
				var newZoom = map1.getZoom();
				var newCentre = map1.getCenter();
				if (newZoom > startZoom) {
					if (newCentre == center) {
						map1.setCenter(mullCentre);
						polyMull.setFillStyle({opacity:0});
					}
				} else {
//					if (newCentre == mullCentre) {
						map1.setCenter(center)
						polyMull.setFillStyle({opacity:0.4})
//					}
				}
			});

		}
	}
//  END of loadmap1

//   overlay.setFillStyle({opacity:0});
//   overlay.setStrokeStyle({opacity:0});
// and instead of .show() restore the opacity to what it was originally.

	function loadmap2() {
		if (GBrowserIsCompatible()) {
			map2 = new GMap2(document.getElementById("map2"));
			map2.addMapType(G_PHYSICAL_MAP);
			var center = new GLatLng(56.4500, -6.0300);
			map2.setCenter(center, 9);

// Set up map type menu relationships
			var mapControl = new GHierarchicalMapTypeControl();
			mapControl.clearRelationships();
			mapControl.addRelationship(G_SATELLITE_MAP, G_HYBRID_MAP, "Labels", false);

// Add control after specifying the relationships
			map2.addControl(mapControl);
			map2.addControl(new GSmallMapControl());
			map2.addControl(new GScaleControl());
		}
	}
//  END of loadmap2


var maolbData = "<p><a href='http://www.mull-bed-and-breakfast.co.uk/' target='_blank'>Maolbhuidhe B&B</a></p><p><b>Tel:</b> 01681 700786</p>"
var druimData = "<p><a href='http://www.druimnacroish.co.uk/' target='_blank'>Druimnacroish</a></p><p><b>Tel:</b> 01688 400274</p>"
var fionnData = "Fionnphort<br />Pub: The Keel Row<br />B&Bs:<br />Maolbhuidhe,<br />Seaview,<br />Staffa House,<br />Caol-Ithe,<br />Abbey View"
