	function addWaypoints(wp)
	{
        function createMarker(point, html) {
          var marker = new GMarker(point);
          GEvent.addListener(marker, "click", function() {
            marker.openInfoWindowHtml(html);
          });
          return marker;
        }
        
        window.overlaysWP = [];
		for (var i=0; i<wp.length; i++) {
			var html = '<div style="width: 195px; text-align: left; font-size: 8pt;">';
			if (wp[i].Image)
				html += '<a href="#" onclick="javascript:openGallery('+wp[i].Image+');return false;">' +
						'<img align="right" width="60" height="60" src="'+pathRoot+'tours/image.php?type=thumbs&amp;image='+wp[i].Image+'" style="border: 1px solid #CE191C; margin:5px;" alt="" /></a>';
			html += '<span style="color:#B40E44"><b>'+wp[i].Name+'</b></span><br /><b>'+wp[i].Comment+'</b>';
			if (wp[i].Url)
				html += '<br /><a href="'+wp[i].Url+'">'+wp[i].Url+'</a>';
			html += '<br/>'+wp[i].Description;

			html += '<br/><br/><span style="color:#B40E44;">m '+wp[i].Elevation;
			html += '<br/>'+wp[i].LatitudeT+' &nbsp; '+wp[i].LongitudeT;
			html += '</span></div>';    	

  			var point = new GLatLng(wp[i].Latitude * 1, wp[i].Longitude * 1);
  			window.overlaysWP[i] = [true,createMarker(point,html)];
      		map.addOverlay(window.overlaysWP[i][1]);
		}
		
		if (!window.tourWaypoints)
			window.tourWaypoints = wp;
	}
	
	function addTracks(tracks)
	{
		var colors = ['#FEA90A','#FF0000','#AE0000','#FF00CC','#00FF00','#00FFFF','#0099FF','#E67300','#FFFF00','#FFFFFF'];
		var j = 0;
		window.overlaysTrack = [];
		for (trackId in tracks) {
			addTrack(trackId,tracks[trackId],colors[j%10]);	j++;
		}

		if (!window.tourTracks)
			window.tourTracks = tracks;

		var elem = document.getElementById('alltracks');
		if (elem) { 
			elem.style.fontWeight = "bold";
			elem.style.color = "#000000";
		}
	}	
	
	function addThumbs(thumbs)
	{
		var photothumbs = document.getElementById('photothumbs');
		
		for (var i=0;i<thumbs.length; i++) {
			var thumb = top.document.createElement('div');
			thumb.style.float = "left";
			thumb.style.position = "relative";
			thumb.style.margin = "3px";
			
			thumb.innerHTML = '<a href="#" onclick="javascript:showPhoto('+thumbs[i]+');return false;"><img id="photo'+thumbs[i]+'" width="60" height="60" src="'+pathRoot+'tours/image.php?type=thumbs&amp;image='+thumbs[i]+'" style="border: 1px solid '+(i == 0?'#CE191C;':'#FFFFFF;')+'" alt="" /></a>';
			
			photothumbs.appendChild(thumb);

	 		addPhoto(thumbs[i]);
		}		
	}
	
	function addTrack(trackId,track,color)
	{
        var points = [];
		for (var i=0;i<track.length; i++) {
			points.push(new GLatLng(track[i][0], track[i][1]));      	
		}
		window.overlaysTrack[trackId] = [true,new GPolyline(points,color,2,1)];
		map.addOverlay(window.overlaysTrack[trackId][1]);
	}
	
	var photos = [];

	function addPhoto( id ) {
		photos.push(id);
	}
	
	function showPhoto( id ) {
		try {
	
		for(var i = 0; i < photos.length; i++ ) {
			var im = document.getElementById('photo' + photos[i]);
			if( im ) {
				im.style['border'] = "1px solid #FFFFFF";
			}
		}
	
		var im = document.getElementById('photo' + id);
		if( im ) {
			im.style['border'] = "1px solid #CE191C";
		}
	
		var im = document.getElementById('photo0');
		if( im ) {
			im.style.display = 'none';
			im.src = pathRoot+'tours/resize.php?id='+id+'&MAX_WIDTH=370';
			im.style.display = 'block';
			im.photo = id;
		}
	
		} catch (e) {
		}
	}	
	
	
	function openGallery(photo)
	{
		var idx = 0;
		if( photo )
			idx = photo;
		else
		{
			var im = document.getElementById('photo');
			idx = im.photo;
		}	 
	
		var i = 0;
		if( idx ) 
		for(i = 0; i < photos.length; i++ ) {
			if( photos[i] == idx )
				break;
		}
	
		window.open(pathRoot+'tours/gallery.php?id='+tour+'&type=map&pageID='+(i+1), '', 'toolbar=0,status=1,resizable=0,scrollbars=1,titlebar=0,width=850,height=750');
	}	
	
	function showAllTracks() {
		try {
		
		if (!window.tourTracks) { return; }
		for (trackId in window.tourTracks) {
			/*
			var s = document.getElementById('track' + trackId);
			if (s) {
				//s.class = "active";
			}
			*/
			var elem = document.getElementById('track' + trackId);
			if (elem) { 
				elem.style.fontWeight = "";
				elem.style.color = "#888888";
			}
			var elem = document.getElementById('alltracks');
			if (elem) { 
				elem.style.fontWeight = "bold";
				elem.style.color = "#000000";
			}
			
			if (!window.tourTracks[trackId][0]) {
				map.addOverlay(window.overlaysTrack[trackId][1]);
				window.tourTracks[trackId][0] = true; 
			}
		}
		
		centerMap();
	
		} catch (e) {
			//alert(e.message);	
		}
	}
	
	function showOneTrack(id) {
		try {
		
		if (!window.tourTracks) { return; }
		for (trackId in window.tourTracks) {

			/*
			var s = document.getElementById('track' + trackId);
			if (s) {
				s.['class'] = 'active';
			}
			*/
			var elem = document.getElementById('track' + trackId);
			if (elem) { 
				elem.style.fontWeight = (trackId == id?"bold":"");
				elem.style.color = (trackId == id?"#000000":"#888888");
			}
			elem = document.getElementById('alltracks');
			if (elem) { 
				elem.style.fontWeight = "";
				elem.style.color = "#888888";
			}
			
			
			if (id == trackId) {
				if (!window.tourTracks[trackId][0]) {
					map.addOverlay(window.overlaysTrack[trackId][1]);
					window.tourTracks[trackId][0] = true; 
				}
				
				var sw = new GLatLng(trackStats[id].MinLat, trackStats[id].MinLon);
				var ne = new GLatLng(trackStats[id].MaxLat, trackStats[id].MaxLon);
				var bounds = new GLatLngBounds(sw,ne);

				var zoom = map.getBoundsZoomLevel(bounds);
	
				map.setCenter(new GLatLng(trackStats[id].CenLat,trackStats[id].CenLon),zoom);
			}
			else {
				if (window.tourTracks[trackId][0]) {
					map.removeOverlay(window.overlaysTrack[trackId][1]); 
					window.tourTracks[trackId][0] = false; 
				}
			}
		}
	
		} catch (e) {
			//alert(e.message);	
		}
	}	
	
