function load() {
	//set initial map conditions, including controls, icon etc.
    map = new google.maps.Map2(document.getElementById("etravelmap"));
	map.addControl(new google.maps.LargeMapControl());  
	map.addControl(new google.maps.ScaleControl()); 
   	if (typeof centrex != "number") {var defaultcentre = 1;}
	if (typeof centrey != "number") {var defaultcentre = 1;}
	if (typeof zoom != "number") {var defaultcentre = 1;}
	if (defaultcentre != 1) {map.setCenter(new google.maps.LatLng(centrex, centrey), zoom);}
	else {map.setCenter(new google.maps.LatLng(51, 14.5), 4);}
	geocoder = new google.maps.ClientGeocoder();
	var etravelicon = new GIcon(G_DEFAULT_ICON);
	etravelicon.image = "favicon.ico";
	etravelicon.iconSize = new GSize(16, 16);
	etravelicon.iconAnchor = new GPoint(8,8);
	etravelicon.shadowSize = new GSize(0,0);
	markerOptions = { icon: etravelicon };
	
	function createJSONcity (markers, i) {
		if (typeof directlink == "boolean"){this.directlink = directlink;}
		else {this.directlink == false;}
		this.location = markers.marker[i].Location;
		this.indexurl = markers.marker[i].description; //antiquated term in JSON files
		this.image = markers.marker[i].image;
		this.zoom = parseInt(markers.marker[i].zoom);
	}
	
	function createTXTcity (location, html) {
		//text files only currently support direct links, i.e. no advanced menus, AJAX articles or zooming
		this.directlink = true;
		this.location = location;
		this.indexurl = html;
		this.image = "";
		this.zoom = "";
	}
	
	function geocode(city) {
		geocoder.getLocations(city.location, function(response){
			getcallback(city, response);
		});
	}
	//this function adds city attributess in a snowballing effect. Do not know how to update original city object though	
	function getcallback(city,response) {
		if (response.Status.code == G_GEO_SUCCESS) {
			city.place = response.Placemark[0];
			city.point = new google.maps.LatLng(city.place.Point.coordinates[1],
						city.place.Point.coordinates[0]);
			city.marker = new google.maps.Marker(city.point, markerOptions);
			city.marker.tooltip = "<div class='tooltip'>"+city.location+"</div>";
			map.addOverlay(city.marker);
			GDownloadUrl(city.indexurl, function (data, responsecode){
				city.article = data;
				clicklistener(city);
			});		
			hoverlistener(city);
		}
		if (response.Status.code == G_GEO_TOO_MANY_QUERIES) {
			window.setTimeout(function(){geocode(city);},1000);
		}	
	}
	
	function clicklistener(city){
		google.maps.Event.addListener(city.marker, "click", function (response) {
		if (city.directlink) {
			window.open(city.indexurl);
		}
		else {
			var imghtml = "";
			//adds in autoformatted image from image link
			if (city.image != "") {
				imghtml = "<img src= \""+city.image+" \"width=\"200\" height=\"132\" class=\"thumbnail_right\" />";
			}
		var html = "<p>" + imghtml + city.article + "</p>";
		document.getElementById("mapdesc").innerHTML= html;
		//following functionality added to scan and recognise "center" div from a normal article. If found, it then filters it from the rest of the page for presentation
		var divs = document.getElementsByTagName("div");
		var checkcenter = 0;
		var menus = document.getElementsByTagName("ul");
		var checkmenus = 0;
		var htmlreplace = "";
		html = "<h3>ETravel Map Menu</h3>No menu is available for "+city.location;
		for (i = 0; i < menus.length; i++){
			if (menus[i].getAttribute("id") == "linklist"){
				checkmenus++;
			}
			if (checkmenus == 2){
				htmlreplace = menus[i].innerHTML;
				html = htmlreplace; //.replace(/<li>|<\/li>/gi, "");
				html = "<h3>Browse "+city.location+"</h3><ul id='linklist'>" + html + "</ul>";
			}
			document.getElementById("map_menu").innerHTML = html;
		}
		for (i = 0; i < divs.length; i++) {
			if (divs[i].getAttribute("id") == "center"){checkcenter++;}
			if (checkcenter == 2) {
				var htmlreplace = divs[i].innerHTML;
				htmlreplace = htmlreplace.replace(/h[123]>/gi, "p>");
				document.getElementById("mapdesc").innerHTML = htmlreplace;
			}
		}
		if (zoom != "NaN"){
			map.setCenter(city.point);
			map.setZoom(city.zoom, true);
		}
		}
		//loadmap(hotelfile); This can be enabled in the future when a recursive file can be opened from an item of interest on the map
	});
	}

	function hoverlistener (city) {
	var tooltip = document.createElement("div");
	document.getElementById("etravelmap").appendChild(tooltip);
	tooltip.style.visibility="hidden";
	google.maps.Event.addListener(city.marker, "mouseover", function (response) {
		showTooltip(city.marker);
	});
	function showTooltip(marker) {
		tooltip.innerHTML = marker.tooltip;
		var point=map.getCurrentMapType().getProjection().fromLatLngToPixel(map.getBounds().getSouthWest(),map.getZoom());
		var offset=map.getCurrentMapType().getProjection().fromLatLngToPixel(marker.getPoint(),map.getZoom());
		var anchor=marker.getIcon().iconAnchor;
		var width=marker.getIcon().iconSize.width;
		var pos = new GControlPosition(G_ANCHOR_BOTTOM_LEFT, new GSize(offset.x - point.x - anchor.x + width,- offset.y + point.y +anchor.y)); 
		pos.apply(tooltip);
		tooltip.style.visibility="visible";
	}
	google.maps.Event.addListener(city.marker, "mouseout", function (response) {
		tooltip.style.visibility="hidden"
	});
	//.currentcity++;
	//return cities[i].currentcity;
	}

	//loadmap structured as a function as it will be rerun when a city.marker is clicked to load a new list of points
	function loadmap(url){
		if(url.search("json") != -1){
			GDownloadUrl(url, function getJSON(data, responseCode) {
				var markers = eval("(" + data + ")");
				var cities = new Array(markers.marker.length);
				for(i=0;i<cities.length;i++){
					city = new createJSONcity(markers,i);
					geocode(city);
				}
			});
		}
		//text files only currently support direct links, i.e. no advanced menus. 
		if(url.search(".txt") != -1){
			GDownloadUrl(url, function getTXT(data, responseCode) {
				var rows = data.split('#');
				if (rows.length == 1){
					rows = data.split('\n');
				}
				for (var i = 0; i < rows.length; i++) {
					city = new createTXTcity(rows[i].split(';')[0], rows[i].split(';')[1]);
					geocode(city);
				}
			});
		
		}
				
//listener function controls the chain of events that happen when a city.marker is activated by hover over (tooltip) or click (article rendered).		

	}
	loadmap(hotelfile); //runs loadmap, this could be exported into html itself. Html file references hotelfile
}
