var map;
var mapIcons = [];
var markerFlags = [true, true, true, true, true, true, true, true, false, false, false];
var wikiOverlay = null;
var plakLat;
var plakLng;
var currZoom = 5;
var currLat = -28.2399;
var currLng = 24.7288;
var wikiflag = false;
var dirflag = false;
var dirStart = null;
var dirEnd = null;
var dirPoly = null;
var markers = [[], [], [], [], [], [], [], [], [], [], []];
var currentmarkers = [];
var newMarker = null;

var dirIcon = new GIcon();
dirIcon.iconSize = new GSize(24, 24);
dirIcon.iconAnchor = new GPoint(3, 24);
var startIcon = new GIcon(dirIcon);
startIcon.image = "/img/start.png";

var endIcon = new GIcon(dirIcon);
endIcon.image = "/img/end.png";

var xIcon = new GIcon();
xIcon.iconSize = new GSize(24, 24);
xIcon.iconAnchor = new GPoint(12, 12);
var crossIcon = new GIcon(xIcon);
crossIcon.image = "/img/cross.png";

var baseIcon = new GIcon();
baseIcon.iconSize = new GSize(14, 30);
baseIcon.iconAnchor = new GPoint(0, 30);
baseIcon.infoWindowAnchor = new GPoint(9, 2);

var serviceIcon = new GIcon();
serviceIcon.iconSize = new GSize(16, 16);
serviceIcon.iconAnchor = new GPoint(14, 16);
serviceIcon.infoWindowAnchor = new GPoint(9, 2);

function load() {
	if (GBrowserIsCompatible()) {

		map = new GMap2(document.getElementById("plak_map"));

		var ca = document.cookie.split(';');
		for(var i=0; i < ca.length; i++) {
			var c = ca[i];
			while (c.charAt(0)==' ')
				c = c.substring(1, c.length);
			if (c.indexOf("Plak") == 0) {
				var plakcookie = c.substring(5, c.length);
				var plakarray = plakcookie.split(":");
				var plakZoom = plakarray[0];
				currZoom = parseInt(plakZoom);
				var plakCurrLat = plakarray[1];
				if (plakCurrLat != "NaN")
					currLat = parseFloat(plakCurrLat);
				var plakCurrLng = plakarray[2];
				if (plakCurrLng != "NaN")
					currLng = parseFloat(plakCurrLng);
				if (plakarray[3] == "false")
					markerFlags[1] = false;
				if (plakarray[4] == "false")
					markerFlags[2] = false;
				if (plakarray[5] == "false")
					markerFlags[3] = false;
				if (plakarray[6] == "false")
					markerFlags[4] = false;
				if (plakarray[7] == "false")
					markerFlags[5] = false;
				if (plakarray[8] == "false")
					markerFlags[6] = false;
				if (plakarray[9] == "false")
					markerFlags[7] = false;
				if (plakarray[10] == "true")
					wikiflag = true;
				if (plakarray[11])
					map.setMapType(map.getMapTypes()[parseInt(plakarray[11])]);
				if (plakarray[12]) {
					if (plakarray[12] == "none") {
						document.getElementById("toggle_img").src="/img/rightbutton.gif";
						document.getElementById("sb_info").style.display = "none";
						document.getElementById("plak_map_border").style.width = "752px";
						document.getElementById("plak_map_directions").style.width = "752px";
						map.checkResize();
					}
				}
				if (plakarray[13]) {
					if (plakarray[13] == "true")
						dirflag = true;
				}
				if (plakarray[14]) {
					document.getElementById(plakarray[14]).checked = true;
				} else {
					document.getElementById("r1").checked = true;
				}
				if (plakarray[15] == "true")
					markerFlags[8] = true;
				if (plakarray[16] == "true")
					markerFlags[9] = true;
				if (plakarray[17] == "true")
					markerFlags[10] = true;
			}
		}

		for (var n = 1; n < 11; n++) {
			document.getElementById("check" + n).checked = false;
			document.getElementById("check" + n).disabled = true;
		}

		map.setCenter(new GLatLng(currLat, currLng), currZoom);

		var div = document.createElement("div");
		div.id = "pleasewait";
		div.style.position = "relative";
		div.style.whiteSpace = "nowrap";
		div.style.border = "1px solid silver";
		div.style.backgroundColor = "#F2F8FB";
		div.style.padding = "5px";
		div.innerHTML = "<h1>Loading. Please wait.</h1>";
		div.style.top = (map.fromLatLngToDivPixel(map.getCenter()).y - 50) + 'px';
		div.style.left = (map.fromLatLngToDivPixel(map.getCenter()).x - 142) + 'px';
		map.getPane(G_MAP_FLOAT_PANE).appendChild(div);

		map.addControl(new GLargeMapControl());
		map.addControl(new GMapTypeControl());
		map.enableContinuousZoom();
		map.enableScrollWheelZoom();

		var publisherID = 'ca-pub-4002245024903759';
		var adsManagerOptions = {
			maxAdsOnMap : 1,
			style: 'adunit',
			channel: '5626973176'
		};
		var adsManager = new GAdsManager(map, publisherID, adsManagerOptions);
		adsManager.enable();

		mapIcons.push(null);

		var mapIcon = new GIcon(baseIcon);
		mapIcon.image = "/img/GrayPin.png";
		mapIcons.push(mapIcon);

		mapIcon = new GIcon(baseIcon);
		mapIcon.image = "/img/BluePin.png";
		mapIcons.push(mapIcon);

		mapIcon = new GIcon(baseIcon);
		mapIcon.image = "/img/RedPin.png";
		mapIcons.push(mapIcon);

		mapIcon = new GIcon(baseIcon);
		mapIcon.image = "/img/PinkPin.png";
		mapIcons.push(mapIcon);

		mapIcon = new GIcon(baseIcon);
		mapIcon.image = "/img/PurplePin.png";
		mapIcons.push(mapIcon);

		mapIcon = new GIcon(baseIcon);
		mapIcon.image = "/img/GreenPin.png";
		mapIcons.push(mapIcon);

		mapIcon = new GIcon(baseIcon);
		mapIcon.image = "/img/YellowPin.png";
		mapIcons.push(mapIcon);

		mapIcon = new GIcon(serviceIcon);
		mapIcon.image = "/img/saps.gif";
		mapIcons.push(mapIcon);

		mapIcon = new GIcon(serviceIcon);
		mapIcon.image = "/img/school.gif";
		mapIcons.push(mapIcon);

		mapIcon = new GIcon(serviceIcon);
		mapIcon.image = "/img/hospital.gif";
		mapIcons.push(mapIcon);

		wikiOverlay = new GLayer("org.wikipedia.en");

		GEvent.addListener(map, "moveend", function() {
			if (map.getInfoWindow().isHidden()) {
				displayMarkers();
			}
		});

		GEvent.addListener(map, "singlerightclick", function(point,  src,  overlay) {
			if (document.getElementById("check9").checked) {
				var latlng = map.fromContainerPixelToLatLng(point);
 				plakLat = latlng.lat();
				plakLng = latlng.lng();
				if (plakLat < -22.1111 && plakLat > -34.8422 && plakLng > 16.4516 && plakLng < 32.8966) {
					if (dirStart == null) {
						var markerOptions = { icon:startIcon };
						dirStart = new GMarker(latlng, markerOptions);
						map.addOverlay(dirStart);
						if (dirEnd != null) {
							getDirections();
						}
					} else if (dirEnd == null) {
						var markerOptions = { icon:endIcon };
						dirEnd = new GMarker(latlng, markerOptions);
						map.addOverlay(dirEnd);
						if (dirStart != null) {
							getDirections();
						}
					} else {
						map.removeOverlay(dirStart);
						map.removeOverlay(dirEnd);
						map.removeOverlay(dirPoly);
						dirStart = null;
						dirEnd = null;
						dirPoly = null;
					}
				}
			} else {
				if (!loggedin) {
					alert("You must be logged in before you can add a Plak.");
				} else {
					if (map.getZoom() < 14) {
						alert ("Please zoom in before trying to add a Plak.");
					} else {
						var latlng = map.fromContainerPixelToLatLng(point);
 						plakLat = latlng.lat();
						plakLng = latlng.lng();
						if (plakLat < -22.1111 && plakLat > -34.8422 && plakLng > 16.4516 && plakLng < 32.8966) {
							document.getElementById("plak_lat").value = plakLat;
							document.getElementById("plak_lng").value = plakLng;
							document.getElementById("plak_type").selectedIndex = 0;
							document.getElementById("plak_name").value = "";
							document.getElementById("plak_desc").value = "";
							document.getElementById("plak_address").value = "";
							document.getElementById("plak_phone").value = "";
							document.getElementById("plak_fax").value = "";
							document.getElementById("plak_site").value = "";
							document.getElementById("plak_image").value = "";
							document.getElementById("plak_wifi").checked = false;
							document.getElementById("plak_wifitype").selectedIndex = 0;
							document.getElementById("plak_wifitype").disabled = true;
							document.getElementById("plak_add").style.display = "block";
						}
					}
				}
			}
		});

		AJAXCall("getMarkers", encodeURI("type=1"), "gotMarkers(rep)");

	}
}

function getDirections() {
	document.getElementById("directions").src = "img/busy.gif";
	var sp = dirStart.getLatLng().lng() + "," + dirStart.getLatLng().lat();
	var ep = dirEnd.getLatLng().lng() + "," + dirEnd.getLatLng().lat();
	AGCall(sp, ep, "directionloadhandler(rep)", 1);
}

function getTextDirections() {
	document.getElementById("directions").src = "img/busy.gif";
	var sp = dirStart.getLatLng().lat() + "|" + dirStart.getLatLng().lng();
	var ep = dirEnd.getLatLng().lat() + "|" + dirEnd.getLatLng().lng();
	AGCall(sp, ep, "textdirloadhandler(rep)", 2);
}

function textdirloadhandler(obj) {
	document.getElementById("plak_map_border").style.display = "none";
	var doc = document.getElementById("dir_text").contentDocument || document.getElementById("dir_text").contentWindow.document;

	doc.open();
        doc.write("<!DOCTYPE html PUBLIC '-//W3C//DTD XHTML 1.0 Strict//EN' 'http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd'><html xmlns='http://www.w3.org/1999/xhtml'><head><meta http-equiv='content-type' content='text/html; charset=UTF-8'/><link rel='stylesheet' type='text/css' href='Global.css'/></head><body style='background-color: white;'>" + obj + "</body></html>");
        doc.close();    

	document.getElementById("plak_map_directions").style.display = "block";
	document.getElementById("directions").src = "img/car.png";
}

function HideDir() {
	document.getElementById("plak_map_directions").style.display = "none";
	document.getElementById("plak_map_border").style.display = "block";
}

function directionloadhandler(obj) {
	var coords = obj.RoutingPoints.split("|");
	var polyCoords = [];
	for (var n = 0; n < coords.length; n++) {
		var ll = coords[n].split(",");
		polyCoords.push(new GLatLng(parseFloat(ll[1]), parseFloat(ll[0])));
	}
	dirPoly = new GPolyline(polyCoords);
	map.addOverlay(dirPoly);
	document.getElementById("directions").src = "img/car.png";
	var ans = confirm("Would you like text directions for the displayed route?");
	if (ans) {
		getTextDirections();
	}
}

function displayMarkers() {
	var ne = map.getBounds().getNorthEast();
	var sw = map.getBounds().getSouthWest();
	var top = ne.lat();
	var right = ne.lng();
	var bot = sw.lat();
	var left = sw.lng();
	var zoom = map.getZoom();
	var maxmarkers = 100;
	var max = 0;
	
	if (markerFlags[1] && markers[1].length > max) max = markers[1].length;
	if (markerFlags[2] && markers[2].length > max) max = markers[2].length;
	if (markerFlags[3] && markers[3].length > max) max = markers[3].length;
	if (markerFlags[4] && markers[4].length > max) max = markers[4].length;
	if (markerFlags[5] && markers[5].length > max) max = markers[5].length;
	if (markerFlags[6] && markers[6].length > max) max = markers[6].length;
	if (markerFlags[7] && markers[7].length > max) max = markers[7].length;
	if (markerFlags[8] && markers[8].length > max) max = markers[8].length;
	if (markerFlags[9] && markers[9].length > max) max = markers[9].length;
	if (markerFlags[10] && markers[10].length > max) max = markers[10].length;

	clearAll();
	var latlng;
	var breakflag = false;
	for (var n = 0; n < max; n++) {

		for (var x = 1; x < 11; x++) {
			if (markerFlags[x] && n < markers[x].length) {
				latlng = markers[x][n].getLatLng();
				if (latlng.lat() > bot && latlng.lat() < top && latlng.lng() > left && latlng.lng() < right) {
					map.addOverlay(markers[x][n]);
					currentmarkers.push(markers[x][n]);
				}
			}
			if (zoom < 12 && currentmarkers.length == maxmarkers) {
				breakflag = true;
				break;
			}
		}
		if (breakflag) break;
	}
	if (breakflag) {
		document.getElementById("msg").innerHTML = "<strong>Zoom in to see more Plaks.</strong>";
	} else {
		document.getElementById("msg").innerHTML = "<strong>Click map pins to view more information.</strong>";
	}
}

function clearAll() {
	hideName();
	if (newMarker != null) {
		map.removeOverlay(newMarker);
		newMarker = null;
	}
	if (currentmarkers.length > 0) {
		for (var n = 0; n < currentmarkers.length; n++) {
			map.removeOverlay(currentmarkers[n]);
		}
		currentmarkers = [];
	}
}

function GUnload() {
	if (!document.getElementById("check1").disabled) {
		var value = map.getZoom() + ":";
		value += map.getCenter().lat() + ":" + map.getCenter().lng() + ":";
		value += document.getElementById("check1").checked;
		value += ":" + document.getElementById("check2").checked;
		value += ":" + document.getElementById("check3").checked;
		value += ":" + document.getElementById("check4").checked;
		value += ":" + document.getElementById("check5").checked;
		value += ":" + document.getElementById("check6").checked;
		value += ":" + document.getElementById("check7").checked;
		value += ":" + document.getElementById("check8").checked;
		for (var i = 0; i < map.getMapTypes().length; i++) {
			if (map.getCurrentMapType() == map.getMapTypes()[i]) {
				value += ":" + i;
			}
		}
		value += ":" + document.getElementById("sb_info").style.display;
		value += ":" + document.getElementById("check9").checked;
		if (document.getElementById("r1").checked) {
			value += ":r1";
		} else {
			value += ":r2";
		}
		value += ":" + document.getElementById("check10").checked;
		value += ":" + document.getElementById("check11").checked;
		value += ":" + document.getElementById("check12").checked;
		createCookie("Plak", value, 7);
	}
}

function createCookie(name, value, days) {
	if (days) {
		var date = new Date();
		date.setTime(date.getTime()+(days*24*60*60*1000));
		var expires = "; expires="+date.toGMTString();
	}
	else var expires = "";
	document.cookie = name+"="+value+expires+"; path=/";
}

function gotMarkers(object) {
	if (object[0][0] != "none") {

		document.getElementById("check1").checked = markerFlags[1];
		document.getElementById("check2").checked = markerFlags[2];
		document.getElementById("check3").checked = markerFlags[3];
		document.getElementById("check4").checked = markerFlags[4];
		document.getElementById("check5").checked = markerFlags[5];
		document.getElementById("check6").checked = markerFlags[6];
		document.getElementById("check7").checked = markerFlags[7];
		document.getElementById("check10").checked = markerFlags[8];
		document.getElementById("check11").checked = markerFlags[9];
		document.getElementById("check12").checked = markerFlags[10];

		var marker;
		for (var n = 0; n < object.length; n++) {
			var LatLng = new GLatLng(object[n][1], object[n][2]);
			marker = new createMarker(LatLng, mapIcons[object[n][4]], object[n][3], object[n][0], object[n][4]);
			markers[object[n][4]].push(marker);
		}

		document.getElementById("check1").disabled = false;
		document.getElementById("check2").disabled = false;
		document.getElementById("check3").disabled = false;
		document.getElementById("check4").disabled = false;
		document.getElementById("check5").disabled = false;
		document.getElementById("check6").disabled = false;
		document.getElementById("check7").disabled = false;
		document.getElementById("check10").disabled = false;
		document.getElementById("check11").disabled = false;
		document.getElementById("check12").disabled = false;

		document.getElementById("check8").disabled = false;
		document.getElementById("check8").checked = wikiflag;
		document.getElementById("check9").disabled = false;
		document.getElementById("check9").checked = dirflag;
 		toggleWiki(wikiflag);
		displayMarkers();
		var pleasewait = document.getElementById("pleasewait");
		if(pleasewait) {
			map.getPane(G_MAP_FLOAT_PANE).removeChild(pleasewait);
		}
	}
}

function dirFromTo(lat, lng) {
	map.getInfoWindow().hide();
	var latlng = new GLatLng(lat, lng);
	if (dirPoly != null) {
		map.removeOverlay(dirStart);
		map.removeOverlay(dirEnd);
		map.removeOverlay(dirPoly);
		dirStart = null;
		dirEnd = null;
		dirPoly = null;
	}

	if (dirStart == null) {
		var markerOptions = { icon:startIcon };
		dirStart = new GMarker(latlng, markerOptions);
		map.addOverlay(dirStart);
		if (dirEnd != null) {
			getDirections();
		}
	} else {
		var markerOptions = { icon:endIcon };
		dirEnd = new GMarker(latlng, markerOptions);
		map.addOverlay(dirEnd);
		if (dirStart != null) {
			getDirections();
		}
	}
}

function createMarker(point, ico, name, id, type) {
	var alttext = "";
	var markerOptions = { icon:ico };
	var marker = new GMarker(point, markerOptions);

	GEvent.addListener(marker, "click", function() {
		showInfo(this, name, id);
	});

	GEvent.addListener(marker, "mouseover", function(latlng) {
		showName(name, latlng, type);
	});

	GEvent.addListener(marker, "mouseout", function() {
		hideName();
	});

	return marker;
}

function showInfo(marker, name, id) {
	var alttext = "";
	var point = marker.getPoint();
	var ico = marker.getIcon();
	marker.openInfoWindowHtml("<div class='info_div'><img src='" + ico.image + "' class='info_icon' alt='" + alttext + "'/><br/><div class='info_name'>" + name + "</div><div class='info_link'><a href='/moreinfo.php?id=" + id + "'>More info...</a></div><br/></div><input class='plak_button' type='button' value='Directions' onclick=\"dirFromTo(" + point.lat() + ", " + point.lng() + ");\" />");
}

function showName(name, latlng, type) {
	var div = document.createElement("div");
	div.id = "infopop";
	div.style.position = "relative";
	div.style.whiteSpace = "nowrap";
	div.innerHTML = name;
	if (type > 7) {
		div.style.top = (map.fromLatLngToDivPixel(latlng).y - 41) + 'px';
		div.style.left = (map.fromLatLngToDivPixel(latlng).x - 13) + 'px';
	} else if (type == 0) {
		div.style.top = (map.fromLatLngToDivPixel(latlng).y - 34) + 'px';
		div.style.left = (map.fromLatLngToDivPixel(latlng).x - 8) + 'px';
	} else {
		div.style.top = (map.fromLatLngToDivPixel(latlng).y - 54) + 'px';
		div.style.left = (map.fromLatLngToDivPixel(latlng).x + 8) + 'px';
	}
	map.getPane(G_MAP_FLOAT_PANE).appendChild(div);
}

function hideName() {
	var infopop = document.getElementById("infopop");
	if(infopop) {
		map.getPane(G_MAP_FLOAT_PANE).removeChild(infopop);
	}
}

function cityChanged(LatLng) {
	var values = LatLng.split(",");
	map.setCenter(new GLatLng(values[0], values[1]), parseInt(values[2]));
}

function plak_add_close() {
	document.getElementById("plak_add").style.display = "none";
}

function isUrl(s) {
	var regexp = /(http|https):\/\/(\w+:{0,1}\w*@)?(\S+)(:[0-9]+)?(\/|\/([\w#!:.?+=&%@!\-\/]))?/;
	return regexp.test(s);
}

function isImage(s) {
	var regexp = /(.jpg|.jpeg|.png|.gif)/i;
	return regexp.test(s);
}

function addPlak() {
	if (document.getElementById("plak_type").value == -1) {
		alert("Please select a type.");
	} else if (document.getElementById("plak_name").value.length == 0) {
		alert("Please supply a name.");
	} else if (document.getElementById("plak_name").value.length > 40) {
		alert("Sorry, but the Plak name is limited to 40 characters.");
	} else if (document.getElementById("plak_desc").value.indexOf("!!") > -1) {
		alert("Please use only single exclamation marks!!!!!!!");
	} else if (document.getElementById("plak_address").value.length > 300) {
		alert("Sorry, but the address is limited to 300 characters.");
	} else if (document.getElementById("plak_phone").value.length > 20) {
		alert("Sorry, but the phone number is limited to 20 characters.");
	} else if (document.getElementById("plak_phone").value.length > 0 && document.getElementById("plak_phone").value.substring(0,1) != "0") {
		alert("Please read the help for the correct phone number format.");
	} else if (document.getElementById("plak_fax").value.length > 20) {
		alert("Sorry, but the fax number is limited to 20 characters.");
	} else if (document.getElementById("plak_fax").value.length > 0 && document.getElementById("plak_fax").value.substring(0,1) != "0") {
		alert("Please read the help for the correct phone number format.");
	} else if (document.getElementById("plak_site").value.length > 0 && !isUrl(document.getElementById("plak_site").value)) {
		alert("Sorry, but the link to the web site seems to be invalid. It must start with http:// or https://");
	} else if (document.getElementById("plak_image").value.length > 0 && !isUrl(document.getElementById("plak_image").value)) {
		alert("Sorry, but the image URL seems to be invalid. It must start with http:// or https://");
	} else if (document.getElementById("plak_image").value.length > 0 && !isImage(document.getElementById("plak_image").value)) {
		alert("Sorry, but the image URL seems to be invalid. It must point at either a jpeg, a gif or a png image.");
	} else {
		var icon = mapIcons[document.getElementById("plak_type").value];
		plak_add_close();
		var LatLng = new GLatLng(document.getElementById("plak_lat").value, document.getElementById("plak_lng").value);
		var markerOptions = { icon:icon };
		if (newMarker != null) {
			map.removeOverlay(newMarker);
		}
		newMarker = new GMarker(LatLng, markerOptions);
		map.addOverlay(newMarker);
		newMarker.openInfoWindowHtml("<br/><div class='info_name'>Are you sure that want to add that Plak there?</div><br/><input class='plak_button' type='button' value='Yes' onclick=\"addNewPlak();\" /> <input class='plak_button' type='button' value='No' onclick=\"removeNewPlak();\" />");
	}
}

function addNewPlak() {
	var hasWiFi;
	if (document.getElementById("plak_wifi").checked) {
		hasWiFi = 1;
	} else {
		hasWiFi = 0;
	}
	var plak_name = document.getElementById("plak_name").value;
	plak_name = plak_name.replace(/&/g, "%26");
	var plak_desc = document.getElementById("plak_desc").value;
	plak_desc = plak_desc.replace(/&/g, "%26");
	var plak_address = document.getElementById("plak_address").value;
	plak_address = plak_address.replace(/&/g, "%26");
	var plak_site = document.getElementById("plak_site").value;
	plak_site = plak_site.replace(/&/g, "%26");
	var plak_image = document.getElementById("plak_image").value;
	plak_image = plak_image.replace(/&/g, "%26");
	AJAXCall("add", encodeURI("name=" + plak_name + "&lat=" + document.getElementById("plak_lat").value + "&lng=" + document.getElementById("plak_lng").value + "&type=" + document.getElementById("plak_type").value + "&desc=" + plak_desc + "&address=" + plak_address + "&phone=" + document.getElementById("plak_phone").value + "&fax=" + document.getElementById("plak_fax").value + "&wifi=" + hasWiFi + "&wtype=" + document.getElementById("plak_wifitype").value + "&site=" + plak_site + "&image=" + plak_image), "plakAdded(rep)");
	map.removeOverlay(newMarker);
	newMarker = null;
}

function removeNewPlak() {
	map.removeOverlay(newMarker);
	newMarker = null;
}

function wifiClicked(value) {
	if (value) {
		document.getElementById("plak_wifitype").disabled = false;
	} else {
		document.getElementById("plak_wifitype").disabled = true;
	}
}

function plakTypeChange(value) {
	if (value == 1) {
		document.getElementById("plak_wifi").checked = true;
		document.getElementById("plak_wifi").disabled = true;
		document.getElementById("plak_wifitype").disabled = false;
	} else {
		document.getElementById("plak_wifi").disabled = false;
	}
}

function plakAdded(object) {
	var LatLng = new GLatLng(object[2], object[3]);
	var marker = new createMarker(LatLng, mapIcons[object[1]], object[4], object[0], object[1]);
	markers[object[1]].push(marker);
	map.addOverlay(marker);
}

function toggleOverlay(flag, index) {
	markerFlags[index] = flag;
	displayMarkers();
}

function toggleWiki(show) {
	if (show) {
		map.addOverlay(wikiOverlay);
	} else {
		map.removeOverlay(wikiOverlay);
	}
}

function toggleDirections(show) {
	if (!show) {
		if (dirStart != null) {
			map.removeOverlay(dirStart);
			dirStart = null;
		}
		if (dirEnd != null) {
			map.removeOverlay(dirEnd);
			dirEnd = null;
		}
		if (dirPoly != null) {
			map.removeOverlay(dirPoly);
			dirPoly = null;
		}
	}
}

function togglesidebar(image) {
	if (document.getElementById("sb_info").style.display == "block") {
		image.src="/img/rightbutton.gif";
		document.getElementById("sb_info").style.display = "none";
		document.getElementById("plak_map_border").style.width = "752px";
		document.getElementById("plak_map_directions").style.width = "752px";
	} else {
		image.src="/img/leftbutton.gif";
		document.getElementById("sb_info").style.display = "block";
		document.getElementById("plak_map_border").style.width = "608px";
		document.getElementById("plak_map_directions").style.width = "608px";
	}
	map.checkResize();
	displayMarkers();
}

function printDirections(){
	dir_text.focus();
	dir_text.print(); 
}