//<![CDATA[;
function load() { if (GBrowserIsCompatible()) {
	map = new GMap2(document.getElementById("map"));
	var maptypes = new Array(G_NORMAL_MAP,G_SATELLITE_MAP,G_HYBRID_MAP,G_PHYSICAL_MAP);
	var circuits = new Array(); var icons = new Array(); icons[1] = new GIcon(); icons[1].image = "http://bleau.info/images/topos/maps/massif.png"; icons[1].iconSize = new GSize(40, 40); icons[1].iconAnchor = new GPoint(20, 20); icons[1].infoWindowAnchor = new GPoint(18, 13); icons[2] = new GIcon(icons[1],"http://bleau.info/images/topos/maps/massif2.png"); icons[3] = new GIcon(icons[1],"http://bleau.info/images/topos/maps/massif3.png"); icons[4] = new GIcon(icons[1],"http://bleau.info/images/topos/maps/massif4.png"); icons[5] = new GIcon(icons[1],"http://bleau.info/images/topos/maps/massif5.png"); icons[6] = new GIcon(icons[1],"http://bleau.info/images/topos/maps/massif6.png"); icons[7] = new GIcon(icons[1],"http://bleau.info/images/topos/maps/massif7.png"); icons[8] = new GIcon(icons[1],"http://bleau.info/images/topos/maps/massif8.png"); icons[9]=  new GIcon(icons[1],"http://bleau.info/images/topos/maps/massif9.png"); icons[10] = new GIcon(icons[1],"http://bleau.info/images/topos/maps/massif10.png"); icons[11] = new GIcon(icons[1],"http://bleau.info/images/topos/maps/massif11.png"); icons[12] = new GIcon(icons[1],"http://bleau.info/images/topos/maps/massif12.png"); icons[13] = new GIcon(icons[1],"http://bleau.info/images/topos/maps/massif13.png"); icons[14] = new GIcon(icons[1],"http://bleau.info/images/topos/maps/massif14.png"); icons[15] = new GIcon(icons[1],"http://bleau.info/images/topos/maps/massif15.png"); icons[16] = new GIcon(icons[1],"http://bleau.info/images/topos/maps/massif16.png"); icons[17] = new GIcon(icons[1],"http://bleau.info/images/topos/maps/massif17.png"); icons[18] = new GIcon(icons[1],"http://bleau.info/images/topos/maps/massif18.png"); icons[19] = new GIcon(icons[1],"http://bleau.info/images/topos/maps/massif19.png"); icons[20] = new GIcon(icons[1],"http://bleau.info/images/topos/maps/massif20.png"); icons[42] = new GIcon(icons[1],"http://bleau.info/images/topos/maps/massif42.png"); icons[56] = new GIcon(icons[1],"http://bleau.info/images/topos/maps/massif56.png"); icons[60] = new GIcon(icons[1],"http://bleau.info/images/topos/maps/massif60.png"); icons[100] = new GIcon(icons[1],"http://bleau.info/images/topos/maps/massifb.png");
	icons[101] = new GIcon(); icons[101].image = "http://bleau.info/images/topos/maps/parking.png"; icons[101].iconSize = new GSize(30, 30); icons[101].iconAnchor = new GPoint(15, 15); icons[101].infoWindowAnchor = new GPoint(10, 0); icons[102] = new GIcon(); icons[102].image = "http://bleau.info/images/topos/maps/camping.png"; icons[102].iconSize = new GSize(40, 40); icons[102].iconAnchor = new GPoint(20, 20); icons[102].infoWindowAnchor = new GPoint(16, 9); icons[103] = new GIcon(); icons[103].image = "http://bleau.info/images/topos/maps/rer.png"; icons[103].iconSize = new GSize(21, 21); icons[103].iconAnchor = new GPoint(10, 10); icons[103].infoWindowAnchor = new GPoint(6, 1); icons[104] = new GIcon(); icons[104].image = "http://bleau.info/images/topos/maps/sncf.png"; icons[104].iconSize = new GSize(21, 21); icons[104].iconAnchor = new GPoint(10, 10); icons[104].infoWindowAnchor = new GPoint(6, 1); icons[105] = new GIcon(); icons[105].image = "http://bleau.info/images/topos/maps/blocage.png"; icons[105].iconSize = new GSize(40, 21); icons[105].iconAnchor = new GPoint(20, 10); icons[105].infoWindowAnchor = new GPoint(20, 10); icons[106] = new GIcon(); icons[106].image = "http://bleau.info/images/topos/maps/f1.png"; icons[106].iconSize = new GSize(24, 24); icons[106].iconAnchor = new GPoint(12, 12); icons[106].infoWindowAnchor = new GPoint(8, 0); icons[107] = new GIcon(); icons[107].image = "http://bleau.info/images/topos/maps/etap.png"; icons[107].iconSize = new GSize(24, 20); icons[107].iconAnchor = new GPoint(12, 10); icons[107].infoWindowAnchor = new GPoint(8, 0); icons[108] = new GIcon(); icons[108].image = "http://bleau.info/images/topos/maps/webcam2.png"; icons[108].iconSize = new GSize(30, 30); icons[108].iconAnchor = new GPoint(15, 15); icons[108].infoWindowAnchor = new GPoint(10, 0); icons[109] = new GIcon(); icons[109].image = "http://bleau.info/images/topos/maps/maisonbleau.png"; icons[109].iconSize = new GSize(40, 40); icons[109].iconAnchor = new GPoint(20, 20); icons[109].infoWindowAnchor = new GPoint(18, 13); icons[110] = new GIcon(); icons[110].image = "http://bleau.info/images/topos/maps/sportoutdoor.png"; icons[110].iconSize = new GSize(95, 14); icons[110].iconAnchor = new GPoint(47, 7); icons[110].infoWindowAnchor = new GPoint(45, 4);
	var iconboulder = new GIcon(); iconboulder.image = "http://bleau.info/images/topos/maps/bicon.png"; iconboulder.iconSize = new GSize(16, 16); iconboulder.iconAnchor = new GPoint(8, 8); iconboulder.infoWindowAnchor = new GPoint(8, 4);
	loadMapProperties(map);
	mgr = new GMarkerManager(map);

	function createAreaMarker(point, icon, url, tooltip, wdwstyle, area_lat, area_long, area_level, area_maptype) {
		var marker = new GMarker(point, {icon:icon, title:tooltip});
		if (area_lat > 0 && area_long > 0 && area_level > 0) { GEvent.addListener(marker, "dblclick", function() { map.closeExtInfoWindow(); map.setMapType(area_maptype); map.setCenter((map.getZoom() < area_level) ? new GLatLng(area_lat,area_long) : marker.getPoint()); map.setZoom((map.getZoom() < area_level) ? area_level : map.getZoom()+1); }); } else { GEvent.addListener(marker, "dblclick", function() { map.setCenter(marker.getPoint()); map.setZoom(map.getZoom()+1); map.closeExtInfoWindow(); }); }
		if (wdwstyle == 1) { GEvent.addListener(marker, "click", function() { marker.openExtInfoWindow(map, "custom_info_window_wide","<div align=center><img src=\"http:images.climbing.nl/lightbox/loading.gif\" width=32 height=32 style=\"margin:20px\" alt=\"\"></div>", {ajaxUrl: url, beakOffset: 4}) });
		} else if (wdwstyle == 2) { GEvent.addListener(marker, "click", function() { marker.openExtInfoWindow(map, "custom_info_window_blue","<div align=center><img src=\"http://images.climbing.nl/lightbox/loading.gif\" width=32 height=32 style=\"margin:20px\" alt=\"\"></div>", {ajaxUrl: url, beakOffset: 4}) });
		} else if (wdwstyle == 3) { GEvent.addListener(marker, "click", function() { marker.openExtInfoWindow(map, "custom_info_window_bluewide","<div align=center><img src=\"http://images.climbing.nl/lightbox/loading.gif\" width=32 height=32 style=\"margin:20px\" alt=\"\"></div>", {ajaxUrl: url, beakOffset: 4}) });
		} else if (wdwstyle == 4) { GEvent.addListener(marker, "click", function() { marker.openExtInfoWindow(map, "custom_info_window_bluemedium","<div align=center><img src=\"http://images.climbing.nl/lightbox/loading.gif\" width=32 height=32 style=\"margin:20px\" alt=\"\"></div>", {ajaxUrl: url, beakOffset: 4}) });
		} else { GEvent.addListener(marker, "click", function() { marker.openExtInfoWindow(map, "custom_info_window_red","<div align=center><img src=\"http://images.climbing.nl/lightbox/loading.gif\" width=32 height=32 style=\"margin:20px\" alt=\"\"></div>", {ajaxUrl: url, beakOffset: 4}) }); }
		return marker;
	}

	function createCircuitMarker(point, icon, tooltip, label, anchor) {
		icon.infoWindowAnchor = new GPoint(12, 4);
		if ((icon.image == "http://bleau.info/images/topos/maps/depart1.png")  || (icon.image == "http://bleau.info/images/topos/maps/depart2.png")  || (icon.image == "http://bleau.info/images/topos/maps/depart6.png")  || (icon.image == "http://bleau.info/images/topos/maps/depart10.png") || (icon.image == "http://bleau.info/images/topos/maps/depart13.png") || (icon.image == "http://bleau.info/images/topos/maps/depart14.png")) { var labelstring = "<div style=\"color:black; white-space:nowrap;\">n&deg;" + label + "</div>"; }
		else { var labelstring = "<div style=\"color:white;white-space:nowrap;\">n&deg;" + label + "</div>"; 	}
		if (label < 10) {
			icon.iconSize = new GSize(25, 15);
			if (anchor == 'center') { icon.iconAnchor = new GPoint(13, 8); var ofsetter = new GSize(-10, -7); }
			else if (anchor == 'top') { icon.iconAnchor = new GPoint(13, 16); var ofsetter = new GSize(-10, -15); }
			else if (anchor == 'bottom') { icon.iconAnchor = new GPoint(13, 0); var ofsetter = new GSize(-10, 1); }
			else if (anchor == 'left') { icon.iconAnchor = new GPoint(26, 8); var ofsetter = new GSize(-23, -7); }
			else if (anchor == 'right') { icon.iconAnchor = new GPoint(0, 8); var ofsetter = new GSize(3, -7); }
			else if (anchor == 'topleft') { icon.iconAnchor = new GPoint(26, 16); var ofsetter = new GSize(-23, -15); }
			else if (anchor == 'topright') { icon.iconAnchor = new GPoint(0, 16); var ofsetter = new GSize(3, -15); }
			else if (anchor == 'bottomleft') { icon.iconAnchor = new GPoint(26, 0); var ofsetter = new GSize(-23, 1); }
			else if (anchor == 'bottomright') { icon.iconAnchor = new GPoint(0, 0); var ofsetter = new GSize(3, 1); }
			else { icon.iconAnchor = new GPoint(13, 8); var ofsetter = new GSize(-10, -7); }
		} else {
			icon.iconSize = new GSize(32, 15);
			if (anchor == 'center') { icon.iconAnchor = new GPoint(13, 8); var ofsetter = new GSize(-10, -7); }
			else if (anchor == 'top') { icon.iconAnchor = new GPoint(13, 16); var ofsetter = new GSize(-10, -15); }
			else if (anchor == 'bottom') { icon.iconAnchor = new GPoint(13, 0); var ofsetter = new GSize(-10, 1); }
			else if (anchor == 'left') { icon.iconAnchor = new GPoint(33, 8); var ofsetter = new GSize(-30, -7); }
			else if (anchor == 'right') { icon.iconAnchor = new GPoint(0, 8); var ofsetter = new GSize(3, -7); }
			else if (anchor == 'topleft') { icon.iconAnchor = new GPoint(33, 16); var ofsetter = new GSize(-30, -15); }
			else if (anchor == 'topright') { icon.iconAnchor = new GPoint(0, 16); var ofsetter = new GSize(3, -15); }
			else if (anchor == 'bottomleft') { icon.iconAnchor = new GPoint(33, 0); var ofsetter = new GSize(-30, 1); }
			else if (anchor == 'bottomright') { icon.iconAnchor = new GPoint(0, 0); var ofsetter = new GSize(3, 1); }
			else { icon.iconAnchor = new GPoint(13, 8); var ofsetter = new GSize(-10, -7); }
		}
		var marker = new LabeledMarker(point, {icon:icon, clickable:false, labelText:labelstring, labelOffset:ofsetter, title:tooltip});
		return marker;
	}

	function createBoulderMarker(point, icon, text, tooltip) {
		var marker = new GMarker(point, {icon:icon, title:tooltip});
		GEvent.addListener(marker, "click", function() { marker.openInfoWindowHtml(text); });
		return marker;
	}

	var request = GXmlHttp.create();
	request.open("GET", "/areas/markers.xml", true);
	request.onreadystatechange = function() {
		if (request.readyState == 4) {
			var xmlDoc = GXml.parse(request.responseText);
			var markers = xmlDoc.documentElement.getElementsByTagName("marker");
			for (var i = 0; i < markers.length; i++) {
				var mlat = (markers[i].getAttribute("lat")) ? parseFloat(markers[i].getAttribute("lat")) : 0;
				var mlng = (markers[i].getAttribute("lng")) ? parseFloat(markers[i].getAttribute("lng")) : 0;
				var micon = (markers[i].getAttribute("icn")) ? parseInt(markers[i].getAttribute("icn")) : 0;
				var murl = (markers[i].getAttribute("url")) ? markers[i].getAttribute("url") : "";
				var mtooltip = (markers[i].getAttribute("tip")) ? markers[i].getAttribute("tip") : "";
				var mstyle = (markers[i].getAttribute("stl")) ? parseInt(markers[i].getAttribute("stl")) : 0;
				var mminlevel = (markers[i].getAttribute("min")) ? parseInt(markers[i].getAttribute("min")) : 0;
				var mmaxlevel = (markers[i].getAttribute("max")) ? parseInt(markers[i].getAttribute("max")) : 0;
				var marea_lat = (markers[i].getAttribute("alat")) ? parseFloat(markers[i].getAttribute("alat")) : 0;
				var marea_lng = (markers[i].getAttribute("alng")) ? parseFloat(markers[i].getAttribute("alng")) : 0;
				var marea_level = (markers[i].getAttribute("alvl")) ? parseInt(markers[i].getAttribute("alvl")) : 0;
				var marea_map = (markers[i].getAttribute("map")) ? parseInt(markers[i].getAttribute("map")) : 0;
				mgr.addMarker(createAreaMarker(new GLatLng(mlat,mlng),icons[micon],murl,mtooltip,mstyle,marea_lat,marea_lng,marea_level,maptypes[marea_map]),mminlevel,mmaxlevel);
			}
		}
	}
	request.send(null);

	var request2 = GXmlHttp.create();
	request2.open("GET", "/circuits/markers.xml", true);
	request2.onreadystatechange = function() {
		if (request2.readyState == 4) {
			var xmlDoc = GXml.parse(request2.responseText);
			var markers = xmlDoc.documentElement.getElementsByTagName("marker");
			for (var i = 0; i < markers.length; i++) {
				var mlat = (markers[i].getAttribute("lat")) ? parseFloat(markers[i].getAttribute("lat")) : 0;
				var mlng = (markers[i].getAttribute("lng")) ? parseFloat(markers[i].getAttribute("lng")) : 0;
				var micon = (markers[i].getAttribute("icn")) ? parseInt(markers[i].getAttribute("icn")) : 0;
				var mtooltip = (markers[i].getAttribute("tip")) ? markers[i].getAttribute("tip") : "";
				var mcolor = (markers[i].getAttribute("clr")) ? parseInt(markers[i].getAttribute("clr")) : 0;
				var mnumber = (markers[i].getAttribute("num")) ? parseInt(markers[i].getAttribute("num")) : 0;
				var manchor = (markers[i].getAttribute("anc")) ? markers[i].getAttribute("anc") : "center";
				var mminlevel = (markers[i].getAttribute("min")) ? parseInt(markers[i].getAttribute("min")) : 0;
				var mmaxlevel = (markers[i].getAttribute("max")) ? parseInt(markers[i].getAttribute("max")) : 0;
				circuits[micon] = new GIcon(); circuits[micon].image="http://bleau.info/images/topos/maps/depart"+mcolor+".png";
				mgr.addMarker(createCircuitMarker(new GLatLng(mlat,mlng),circuits[micon],mtooltip,mnumber,manchor),mminlevel,mmaxlevel);
			}
		}
	}
	request2.send(null);

	var request3 = GXmlHttp.create();
	request3.open("GET", "/boulders.xml", true);
	request3.onreadystatechange = function() {
		if (request3.readyState == 4) {
			var xmlDoc = GXml.parse(request3.responseText);
			var markers = xmlDoc.documentElement.getElementsByTagName("marker");
			for (var i = 0; i < markers.length; i++) {
				var mlat = (markers[i].getAttribute("lat")) ? parseFloat(markers[i].getAttribute("lat")) : 0;
				var mlng = (markers[i].getAttribute("lng")) ? parseFloat(markers[i].getAttribute("lng")) : 0;
				var mhtml = (markers[i].getAttribute("html")) ? markers[i].getAttribute("html") : "";
				var mtooltip = (markers[i].getAttribute("tip")) ? markers[i].getAttribute("tip") : "";
				var mminlevel = (markers[i].getAttribute("min")) ? parseInt(markers[i].getAttribute("min")) : 0;
				var mmaxlevel = (markers[i].getAttribute("max")) ? parseInt(markers[i].getAttribute("max")) : 0;
				mgr.addMarker(createBoulderMarker(new GLatLng(mlat,mlng),iconboulder,mhtml,mtooltip),mminlevel,mmaxlevel);
			}
		}
	}
	request3.send(null);

	GEvent.addDomListener(map, 'extinfowindowupdate',function(){
		var windowContent = (document.getElementById("custom_info_window_red_contents")) ? document.getElementById("custom_info_window_red_contents") : (document.getElementById("custom_info_window_blue_contents")) ? document.getElementById("custom_info_window_blue_contents") : (document.getElementById("custom_info_window_bluewide_contents")) ? document.getElementById("custom_info_window_bluewide_contents") : document.getElementById("custom_info_window_wide_contents");
		if (document.getElementById("tab1")) {
			var tabs = new Array(document.getElementById("tab0"),document.getElementById("tab1"));
			if (tabs.length > 0) {
				var tabContentsArray = new Array(tabs.length);
				for(i = 0; i < tabs.length; i++) {
					tabContentsArray[i] = document.getElementById("tab"+i+"_content"); 
					if (i > 0) { hide(tabContentsArray[i]); }
					tabs[i].setAttribute("name", i.toString());
					GEvent.addDomListener(tabs[i],"click",function() {
						var tabIndex = this.getAttribute("name");
			 			for(tabContentIndex=0; tabContentIndex < tabs.length; tabContentIndex++) {
							if( tabContentIndex == tabIndex ) {
								show(tabContentsArray[tabContentIndex]);
							} else {
								hide(tabContentsArray[tabContentIndex]);
							}
						}
						map.getExtInfoWindow().resize();
					});
				}
			}
		}
	});

	mgr.refresh();

	var gpsmarker = new GMarker(new GLatLng(48.490216,2.351074));
	GEvent.addListener(gpsmarker, "click", function() { map.removeOverlay(gpsmarker) });	
	GEvent.addListener(map, "click", function(overlay, point) {
		if (point) {
			gpsmarker.setPoint(point);
			map.addOverlay(gpsmarker);
			var matchll = /\(([-.\d]*), ([-.\d]*)/.exec( point );
			if (matchll) { 
				var lat = parseFloat( matchll[1] );
				var lon = parseFloat( matchll[2] );
				lat = lat.toFixed(6);
				lon = lon.toFixed(6);

				var gpslat = parseInt(lat);
				var remainder = lat - (gpslat * 1.0);
				var latmin = remainder * 60.0;
				var gpslatmin = parseInt(latmin);
				var remainder2 = latmin - (gpslatmin * 1.0);
				var latsec = remainder2 * 60.0;

				var gpslon = parseInt(lon);
				remainder = lon - (gpslon * 1.0);
				var lonmin = remainder * 60.0;
				var gpslonmin = parseInt(lonmin);
				remainder2 = lonmin - (gpslonmin * 1.0);
				var lonsec = remainder2 * 60.0;

			}
			var message = "<B>Latitude, longitude:</B><BR />N " + lat + ", E " + lon + " (Dec)<BR />N " + gpslat + "&deg; " + gpslatmin + "\' " + latsec.toFixed(2) + "\", E " + gpslon + "&deg; " + gpslonmin + "\' " + lonsec.toFixed(2) + "\" (DMS)<BR />N " + gpslat + "&deg; " + latmin.toFixed(4) + "\', E " + gpslon + "&deg; " + lonmin.toFixed(4) + "\' (GPS)";
			gpsmarker.openInfoWindowHtml(message);
	 }});

}};

/**
 * Helper function to hide the given DOM element
 * @param {Object} element The DOM element that should be hidden
 */
function hide(element){
	element.style.display = "none";
	element.style.position = "absolute";
}
/**
 * Helper function to show the given DOM element
 * @param {Object} element The DOM element that should be displayed
 */
function show(element){
	element.style.display = "block";
	element.style.position = "relative";
}

//]]>;

