// Choose random map
var mapType = Math.round(Math.random() * 1);

switch(mapType) {
	
	case 0:
		// Map zoom level
		var mapZoom = 2;
		// Map centre point
		var mapCentre = new Array(-74.0, -122.0); 
		// Default hero shot, taken from mapPhotos array
		var defaultImage = 1;
		// 	Define map points - (lat, long, title, text, image - relative to BASEURL/resources/images/)
		var mapPhotos = new Array();	
			mapPhotos[0] = new Array(-72.235514, -84.111328, "Antarctica #1", "Lines in the snow", "home_ant_01.jpg");
			mapPhotos[1] = new Array(-78.446627,-82.63916, "Antarctica #25", "Camp three", "home_ant_25.jpg");
			mapPhotos[2] = new Array(-79.171335,-81.958008, "Antarctica #31", "Naked Skiing", "home_ant_31.jpg");			
			mapPhotos[3] = new Array(-79.367701, -86.660156, "Antarctica #33", "Minaret Peak", "home_ant_33.jpg");
			mapPhotos[4] = new Array(-79.827836, -81.650391, "Antarctica #12", "Blue Ice Runway", "home_ant_12.jpg");
			mapPhotos[5] = new Array(-79.981891, -80.332031, "Antarctica #26", "Patriot Hills", "home_ant_26.jpg");
			break;

	case 1:
		// Map zoom level
		var mapZoom = 5;
		// Map centre point
		var mapCentre = new Array(-29.897806, 116.081543);
		// Default hero shot, taken from mapPhotos array
		var defaultImage = 0;
		// 	Define map points - (lat, long, title, text, image - relative to BASEURL/resources/images/)
		var mapPhotos = new Array();
			mapPhotos[0] = new Array(-30.115285,114.993725, "National Park WA", "Sandstone figures", "home_aus_10.jpg");
			mapPhotos[1] = new Array(-30.524413, 121.135254, "Coolgardie, WA", "Grave with flowers", "home_aus_18.jpg");
			mapPhotos[2] = new Array(-33.28462, 137.06543, "Lucky Bay, SA", "View for two", "home_aus_04.jpg");
			mapPhotos[3] = new Array(-28.555576, 140.998535, "Cameron Corner, NSW", "Tree in red sand", "home_aus_02.jpg");
			mapPhotos[4] = new Array(-25.878994, 136.889648, "Dalhousie, SA", "", "home_aus_14.jpg");
			break;
}

// Load the default image
switchPhoto(defaultImage);


function loadMap() {
	if (GBrowserIsCompatible()) {
		var map = new GMap2(document.getElementById("map"));
		
		// Add zoom control
		var pos = new GControlPosition(G_ANCHOR_TOP_RIGHT, new GSize(5, 5));
		map.addControl(new GSmallZoomControl(), pos);
				
		map.addMapType(G_SATELLITE_MAP);
		map.removeMapType(G_NORMAL_MAP);
		
		// Set the icon
		var icon = new GIcon();
		icon.image = BASEURL+"/resources/images/photo_marker.png";
		icon.iconSize = new GSize(15, 15);
		icon.shadowSize = new GSize(15, 15);
		icon.iconAnchor = new GPoint(7, 7);
		icon.infoWindowAnchor = new GPoint(7, 7);

		// set the centre point for the map
		var point = new GLatLng(mapCentre[0], mapCentre[1]);
		map.setCenter(point, mapZoom);
		
		/*
		GEvent.addListener(map, "click", function(marker, point) {
			// get lat/long of click
			alert(point);
		});
		*/
		
		var linePoints = new Array();
		for(var i=0; i<mapPhotos.length; i++) {
			
			// Add each point to linePoints array
			linePoints[i] = "new GLatLng("+mapPhotos[i][0]+", "+mapPhotos[i][1]+")";
			
			var photo = new GLatLng(mapPhotos[i][0],mapPhotos[i][1]);		
			var marker = new GMarker(photo,icon);
			marker.title = i;
			
			GEvent.addListener(marker, "mouseover", function() {
				// show the rollover marker
				showPhotoInfo(this.title);
			});
			
			GEvent.addListener(marker, "mouseout", function() {
				// hide the rollover marker
				hidePhotoInfo();
			});
			
			GEvent.addListener(marker, "click", function() {
				// go to the photo
				switchPhoto(this.title);
			});
			
			map.addOverlay(marker);
		}
		
		// Draw the polyline between points
		eval("var polyline = new GPolyline([" + linePoints.join(",") + "], '#FF0000', 1);");
		map.addOverlay(polyline);
	}
}

function showPhotoInfo(intPoint) {
	document.getElementById("tip_title").innerHTML = mapPhotos[intPoint][2];
	document.getElementById("tip_text").innerHTML = mapPhotos[intPoint][3];
	
	var tipDiv = document.getElementById("photo_tip");
	tipDiv.style.visibility = 'visible';
	tipDiv.style.left = (mouseX+15)+"px";
	tipDiv.style.top = (mouseY-15)+"px";
}

function hidePhotoInfo() {
	document.getElementById("photo_tip").style.visibility = 'hidden';
}

function switchPhoto(intPoint) {
	document.getElementById("home_hero").src = BASEURL + "/resources/images/pix.gif";
	document.getElementById("home_hero").src = BASEURL + "/resources/images/" + mapPhotos[intPoint][4];
}

var IE = document.all?true:false;
if (!IE) document.captureEvents(Event.MOUSEMOVE)
document.onmousemove = getMouseXY;
var mouseX = 0;
var mouseY = 0;

function getMouseXY(e) {
	if (IE) { 
		mouseX = event.clientX + document.body.scrollLeft;
		mouseY = event.clientY + document.body.scrollTop;
	}
	else {
		mouseX = e.pageX;
		mouseY = e.pageY;
	}  
	if (mouseX < 0){mouseX = 0;}
	if (mouseY < 0){mouseY = 0;} 
	return true;
}