
	var kmlURL = app_url + "/wp-content/themes/wikimap_highway/kml/journey.kml&nocache=" + new Date().valueOf();
	
	var map = ""; 
	var mgr = ""; 
	var markers = []; 
	var baseIcon = new GIcon(); 
	baseIcon.iconSize = new GSize(21, 25);
	baseIcon.iconAnchor = new GPoint(9, 34);
	baseIcon.infoWindowAnchor = new GPoint(9, 2);
	baseIcon.infoShadowAnchor = new GPoint(18, 25);
	
	// check whether or not the artists are loggedin and determine which layer to post in 
	var overlay = "Suggested%20Locations";
	if(the_artist){
		overlay = "Visited%20Places";	
	}

	function initialize(type) {
		  if (GBrowserIsCompatible()) {
			map = new GMap2(document.getElementById("map"));
			map.setCenter(new GLatLng(54.059387886623576,-1.6259765625),7);
			map.addControl(new GSmallZoomControl());
			createNewPostWindow();
			mgr = new MarkerManager(map); 
			getMapData(type);
			displayRoute();
		  }
		return map;
	}
	
	function createNewPostWindow(){
		postURL = app_url + "/wp-admin/post-new.php?";
		GEvent.addListener(map, "click", function(marker,point) {
		  if (point) {
			if (logged_in) {
					var myHtml = "<div class=\"add-location\"><img src='" + app_url + "/wp-content/themes/wikimap_highway/images/icons/visited_icon.gif' alt='Marker Icon' /><br />When you are sure you want to add this location as a suggestion to the map <a href=\"" + postURL + "Lat=" + point.y +"&Lon=" + point.x + "&Overlay=" + overlay + "\">click here to place the marker</a>. The closer you zoom in, the more accurately you can place your marker.</div>";
			}
			else {
					var myHtml = "<div class=\"add-location\"><img src='" + app_url + "/wp-content/themes/wikimap_highway/images/icons/visited_icon.gif' alt='Marker Icon' /><br />Please login or register to be able to add this location to the map.</div>";
			}
			map.openInfoWindow(point, myHtml);
			
		  } 
		}); 
	}
	
	function getMapData(type){
		var req = new DataRequestor();
		var reqURL = app_url + "/wp-content/plugins/wm-getblogposts.php?type="+type+"&nocache=" + new Date().valueOf();
		req.getURL(reqURL,1, 1);
		req.onLoad = function(data, object){
			mapdata = req._XML_REQ.responseText;
			addPostsToMap(mapdata);
		}
	}
	
	function addPostsToMap(mapdata){
		
		var mapdata = mapdata.replace('</Suggestions>', '');
		var posts = mapdata.split('</Post>');

		var postLat=''; var postLon=''; var postURL=''; var postTitle=''; var authorURL='';
		var author = ''; var summary =''; var iconURL='';

		for (i=0; i<posts.length; i++){
			if(posts[i] != ""){
				post = posts[i];
			}
			
			post = post.substring(post.indexOf('<PostURL>'));
			
			postURL = post.substring(post.indexOf('<PostURL>'),post.indexOf('</PostURL>'));
			postURL = postURL.substring(postURL.indexOf('>')+1,postURL.length);
			
			postLat = post.substring(post.indexOf('<Lat>'),post.indexOf('</Lat>'));
			postLat = postLat.substring(postLat.indexOf('>')+1,postLat.length);
			
			postLon = post.substring(post.indexOf('<Lon>'),post.indexOf('</Lon>'));
			postLon = postLon.substring(postLon.indexOf('>')+1,postLon.length);
			
			postTitle = post.substring(post.indexOf('<Title>'),post.indexOf('</Title>'));
			postTitle = postTitle.substring(postTitle.indexOf('>')+1,postTitle.length);
			
			summary = post.substring(post.indexOf('<Summary>'),post.indexOf('</Summary>'));
			summary = summary.substring(summary.indexOf('>')+1,summary.length);
			
			authorURL = post.substring(post.indexOf('<AuthorURL>'),post.indexOf('</AuthorURL>'));
			authorURL = authorURL.substring(authorURL.indexOf('>')+1,authorURL.length);
			
			author = post.substring(post.indexOf('<Author>'),post.indexOf('</Author>'));
			author = author.substring(author.indexOf('>')+1,author.length);
			
			iconURL = post.substring(post.indexOf('<Icon>'),post.indexOf('</Icon>'));
			iconURL = iconURL.substring(iconURL.indexOf('>')+1,iconURL.length);
			
			var infoWinHTML = "<div class=\"infowindow\">";
	
			infoWinHTML += "<a href=\"" + postURL + "\">" + postTitle + "</a><p id=\"author\"> by <a href=\"" + authorURL + "\">" + author + "</a></p></div><div class=\"infowindow\"><p style=\"margin-top:1em;\">" + summary + "</p></div>";
		
			marker = createMarker(postLat,postLon,infoWinHTML,iconURL);
			markers.push(marker);
			
		}
		mgr.addMarkers(markers,1);
		mgr.refresh(); 
	}
	
	function createMarker(postLat,postLon, infoWinHTML,iconURL){
		var point = new GLatLng(postLat, postLon);
		var custom_icon = new GIcon(baseIcon);
		custom_icon.image = iconURL;
		var marker = new GMarker(point,custom_icon);
		GEvent.addListener(marker, "click", function() {
				marker.openInfoWindowHtml(infoWinHTML);
		});
		return marker;
	}
	
	function displayRoute(){
		var gx = new GGeoXml(kmlURL);
		map.addOverlay(gx);
	}

