
//<![CDATA[

	if (GBrowserIsCompatible()) {
		var gmarkers = [];
		var gicons = [];
		
		var serverpath = 'http://www.riga-sightseeing.lv/';
		var domain = 'http://www.riga-sightseeing.lv/lat/';
		var lang = 'lat';

		gicons["departure1"] = new GIcon();
		gicons["departure1"].image = (serverpath + "images/icons/map/departure1_24.png");
		gicons["departure1"].iconAnchor = new GPoint(12, 12);
		gicons["departure1"].infoWindowAnchor = new GPoint(12, 12);
		gicons["departure1"].iconSize = new GSize(24, 24);
		
		gicons["departure2"] = new GIcon();
		gicons["departure2"].image = (serverpath + "images/icons/map/departure2_24.png");
		gicons["departure2"].iconAnchor = new GPoint(12, 12);
		gicons["departure2"].infoWindowAnchor = new GPoint(12, 12);
		gicons["departure2"].iconSize = new GSize(24, 24);
		
		gicons["departure3"] = new GIcon();
		gicons["departure3"].image = (serverpath + "images/icons/map/departure3_24.png");
		gicons["departure3"].iconAnchor = new GPoint(12, 12);
		gicons["departure3"].infoWindowAnchor = new GPoint(12, 12);
		gicons["departure3"].iconSize = new GSize(24, 24);
		
		gicons["hop"] = new GIcon();
		gicons["hop"].image = (serverpath + "images/icons/map/hop.png");
		gicons["hop"].iconAnchor = new GPoint(6, 6);
		gicons["hop"].infoWindowAnchor = new GPoint(12, 0);
		gicons["hop"].iconSize = new GSize(12, 12);
		
		gicons["sight"] = new GIcon();
		gicons["sight"].image = (serverpath + "images/icons/map/sight.png");
		gicons["sight"].iconAnchor = new GPoint(6, 6);
		gicons["sight"].infoWindowAnchor = new GPoint(12, 0);
		gicons["sight"].iconSize = new GSize(12, 12);
		
		gicons["hotel"] = new GIcon();
		gicons["hotel"].image = (serverpath + "images/icons/map/hotel.png");
		gicons["hotel"].iconAnchor = new GPoint(6, 6);
		gicons["hotel"].infoWindowAnchor = new GPoint(12, 0);
		gicons["hotel"].iconSize = new GSize(12, 12);
		
		// A function to create the marker and set up the event window
		function createMarker(point,name,html,type) {
			var marker = new GMarker(point,gicons[type]);
			// === Store the category and name info as a marker properties ===
			marker.mytype = type;                                 
			marker.myname = name;
			if(type !== 'hop' && type !== 'sight') {
				GEvent.addListener(marker, "click", function() {
					marker.openInfoWindowHtml(html);
				});
			}
			gmarkers.push(marker);
			return marker;
		}

		// == shows all markers of a particular category, and ensures the checkbox is checked ==
		function show(type) {
			for (var i=0; i<gmarkers.length; i++) {
				if (gmarkers[i].mytype == type) {
					gmarkers[i].show();
				}
			}
			// == check the checkbox ==
			document.getElementById(type+"box").checked = true;
		}

		// == hides all markers of a particular category, and ensures the checkbox is cleared ==
		function hide(type) {
			for (var i=0; i<gmarkers.length; i++) {
				if (gmarkers[i].mytype == type) {
					gmarkers[i].hide();
				}
			}
			// == clear the checkbox ==
			document.getElementById(type+"box").checked = false;
			// == close the info window, in case its open on a marker that we just hid
			map.closeInfoWindow();
		}

		// == a checkbox has been clicked ==
		function boxclick(box,type) {
			if (box.checked) {
				show(type);
			}
			else {
				hide(type);
			}
			// == rebuild the side bar
			makeSidebar();
		}

		function myclick(i) {
			GEvent.trigger(gmarkers[i],"click");
		}


		// == rebuilds the sidebar to match the markers currently displayed ==
		function makeSidebar() {
		/*	var html = "";
			for (var i=0; i<gmarkers.length; i++) {
				if (!gmarkers[i].isHidden()) {
					html += '<a href="javascript:myclick(' + i + ')">' + gmarkers[i].myname + '<\/a><br>';
				}
			}
			document.getElementById("side_bar").innerHTML = html;
		*/
		var do_nothing; // side_bar disabled
		}


		// create the map
		var map = new GMap2(document.getElementById("hop_map"));
		map.addControl(new GLargeMapControl());
		map.addControl(new GMapTypeControl());
		map.setCenter(new GLatLng(56.951551,24.105463), 14);
		var encodedPoints ="a~qzIuqdrCTb@|AcCtAsArCgBxEyBjBi@xJ~]BjCc@jCoA|EcG|Mo@oBiBbCz@bCoDfFa@dA?bA|@DvEiJ`Mr[vFjO?jB[lCwDrGcEpFGzA`EjMfHvSyE|KeGvFkT}VqAeC{@jBsA`Bo@sF}AqGyP_zAeAwCdBsB`BgCXaAPmAd@{Hf@eBn@sAhN_V~AwAxBuAwJwVyOxRoOnb@uIlJmInKlB{]nUil@sVsh@jHoQvMo^nR`c@hDhNdChGrIzTlCxHfCJnDyDpC_HFa@`EwIrEfHbC}GwEcIiCfHuC~Gi@dAWNsBjFuAvBiB`B_BCMhAvC|Ji@|@u@d@gB~@uBv@{Az@{ArA}BfD";

		var encodedLevels = "PFDFFDJKFDHHHGGEJFGIDJDGEFJCIGMEIDJEFFKDGCEFDHGDJLHHELIJJDMGFBDKGHDDIILIEBDDHEGIFIDFDDFEP";

		var encodedPolyline = new GPolyline.fromEncoded({
			color: "#990000",
			weight: 5,
			opacity:0.8,
			points: encodedPoints,
			levels: encodedLevels,
			zoomFactor: 15,
			numLevels: 4
		});
		map.addOverlay(encodedPolyline);


		// Read the data
		GDownloadUrl(serverpath + 'inc/markerdata.php?l=' + lang, function(doc) {
			var xmlDoc = GXml.parse(doc);
			var markers = xmlDoc.documentElement.getElementsByTagName("marker");

			for (var i = 0; i < markers.length; i++) {
				// obtain the attribues of each marker
				var id = markers[i].getAttribute("id");
				var lat = parseFloat(markers[i].getAttribute("lat"));
				var lng = parseFloat(markers[i].getAttribute("lng"));
				var point = new GLatLng(lat,lng);
				var type = markers[i].getAttribute("type");
				var address = '<p class="infowin_addr">'+markers[i].getAttribute("address")+'</p>';
				var name = '<p class="infowin_name">'+markers[i].getAttribute("name")+'</p>';
				var stars = markers[i].getAttribute("stars");
				
				if(lang == 'rus') {
					var pointa = '<p>Пункт отправления &laquo;A&raquo;<br />Здесь начинается аудио шоу.</p>';
					var pointb = '<p>Пункт отправления &laquo;B&raquo;<br />Здесь вы можете к нам присоединиться.</p>';
					var pointc = '<p>Пункт отправления &laquo;C&raquo;<br />ВЗдесь вы можете к нам присоединиться.</p>';
					var addit = 'Дополнительная информация';
					var dep_times = 'Время отправления';
				}
				else if(lang == 'lat') {
					var pointa = '<p>Atiešanas punkts &laquo;A&raquo;<br />Audio šovs sakas šeit.</p>';
					var pointb = '<p>Atiešanas punkts &laquo;B&raquo;<br />Šeit jūs varat pie mums pievienoties.</p>';
					var pointc = '<p>Atiešanas punkts &laquo;C&raquo;<br />Šeit jūs varat pie mums pievienoties.</p>';
					var addit = 'Papildus informācija';
					var dep_times = 'Atiešanas laiki';
				}
				else {
					var pointa = '<p>Starting point &quot;A&quot;<br />Audio show starts here.</p>';
					var pointb = '<p>Starting point &quot;B&quot;<br />You can join us here.</p>';
					var pointc = '<p>Starting point &quot;C&quot;<br />You can join us here.</p>';
					var addit = 'Additional information';
					var dep_times = 'Departure times';
				}
				
				if(type=='hotel') {
					var link = '<p class="infowin_link"><a href="'+id+'/">' + dep_times + '</a>';
					if (stars > 0) {
						var starsclass = 'infowin_stars'+stars;
						var html = name+'<div class="'+starsclass+'"></div>'+address+link;
					}
					else var html = name+address+link;
				}
				else if(type=='departure1') {
					var html = name + pointa + '<img src="' + serverpath + 'images/hotels/opera_w120.jpg" width="120" height="95" class="infowin_img" /><p><a href="' + domain + 'departures/opera/">' + addit + '</a></p>';
				}
				else if(type=='departure2') {
					var html = name + pointb + '<img src="' + serverpath + 'images/hotels/townhallsquare_w120.jpg" width="120" height="95" class="infowin_img" /><p><a href="' + domain + 'departures/town-hall-square/">' + addit + '</a></p>';
				}
				else if(type=='departure3') {
					var html = name + pointc + '<img src="' + serverpath + 'images/hotels/latvija_w120.jpg" width="120" height="95" class="infowin_img" /><p><a href="' + domain + 'departures/reval-hotel-latvija/">' + addit + '</a></p>';
				}
				else var html='';
				
				html = '<div class="infowin">'+html+'</div>';
				// create the marker
				var marker = createMarker(point,name,html,type);
				map.addOverlay(marker);
			}
			
			// == show or hide the categories initially ==
			hide("hop");
			hide("hotel");
			hide("sight");
			show("departure1");
			show("departure2");
			show("departure3");
			// == create the initial sidebar ==
			makeSidebar();
		});
	}

	else {
		alert("Sorry, the Google Maps API is not compatible with this browser");
	}
	// This Javascript is based on code provided by the
	// Blackpool Community Church Javascript Team
	// http://www.commchurch.freeserve.co.uk/   
	// http://econym.googlepages.com/index.htm
//]]>
