
//<![CDATA[

	if (GBrowserIsCompatible()) {
		var gmarkers = [];
		var gicons = [];
		
		var serverpath = 'http://www.riga-sightseeing.lv/';
		var domain = 'http://www.riga-sightseeing.lv/rus/';
		var lang = 'rus';

		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);
		
    gicons["departure1"] = new GIcon();
    gicons["departure1"].image = (serverpath + "images/icons/boardplaces/a.png");
    gicons["departure1"].iconAnchor = new GPoint(9, 9);
    gicons["departure1"].infoWindowAnchor = new GPoint(12, 0);
    gicons["departure1"].iconSize = new GSize(18, 18);

		gicons["departure2"] = new GIcon();
		gicons["departure2"].image = (serverpath + "images/icons/boardplaces/b.png");
		gicons["departure2"].iconAnchor = new GPoint(9, 9);
		gicons["departure2"].infoWindowAnchor = new GPoint(12, 0);
		gicons["departure2"].iconSize = new GSize(18, 18);

    gicons["departure3"] = new GIcon();
    gicons["departure3"].image = (serverpath + "images/icons/boardplaces/c.png");
    gicons["departure3"].iconAnchor = new GPoint(9, 9);
    gicons["departure3"].infoWindowAnchor = new GPoint(12, 0);
    gicons["departure3"].iconSize = new GSize(18, 18);

		gicons["departure4"] = new GIcon();
		gicons["departure4"].image = (serverpath + "images/icons/boardplaces/d.png");
		gicons["departure4"].iconAnchor = new GPoint(9, 9);
		gicons["departure4"].infoWindowAnchor = new GPoint(12, 0);
		gicons["departure4"].iconSize = new GSize(18, 18);

    gicons["departure5"] = new GIcon();
    gicons["departure5"].image = (serverpath + "images/icons/boardplaces/e.png");
    gicons["departure5"].iconAnchor = new GPoint(9, 9);
    gicons["departure5"].infoWindowAnchor = new GPoint(12, 0);
    gicons["departure5"].iconSize = new GSize(18, 18);

    gicons["departure6"] = new GIcon();
    gicons["departure6"].image = (serverpath + "images/icons/boardplaces/f.png");
    gicons["departure6"].iconAnchor = new GPoint(9, 9);
    gicons["departure6"].infoWindowAnchor = new GPoint(12, 0);
    gicons["departure6"].iconSize = new GSize(18, 18);

    gicons["departure7"] = new GIcon();
    gicons["departure7"].image = (serverpath + "images/icons/boardplaces/g.png");
    gicons["departure7"].iconAnchor = new GPoint(9, 9);
    gicons["departure7"].infoWindowAnchor = new GPoint(12, 0);
    gicons["departure7"].iconSize = new GSize(18, 18);

    gicons["departure8"] = new GIcon();
    gicons["departure8"].image = (serverpath + "images/icons/boardplaces/h.png");
    gicons["departure8"].iconAnchor = new GPoint(9, 9);
    gicons["departure8"].infoWindowAnchor = new GPoint(12, 0);
    gicons["departure8"].iconSize = new GSize(18, 18);

		// 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;
			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 routeCheck(box, type_id) {
     if ( box.checked ) {
      showRoute(type_id);
     }
     else {
      hideRoute(type_id)
     }
    }

    function showRoute(type_id) {
     switch ( type_id ) {
      case 'lineA' : encodedPolylineA.show(); break;
      case 'lineB' : encodedPolylineB.show(); break;
      case 'lineC' : encodedPolylineC.show(); break;
     }
    }

    function hideRoute(type_id) {
     switch ( type_id ) {
      case 'lineA' : encodedPolylineA.hide(); break;
      case 'lineB' : encodedPolylineB.hide(); break;
      case 'lineC' : encodedPolylineC.hide(); break;
     }
    }

		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 += '<li class="mapside_' + gmarkers[i].mytype + '"><a href="javascript:myclick(' + i + ')">' + gmarkers[i].myname + '<\/a></li>';
				}
			}
			document.getElementById("route_side_bar").innerHTML = '<ul>' + html + '</ul>';
		}


		// create the map
		var map = new GMap2(document.getElementById("route_map"));
		map.addControl(new GLargeMapControl());
		map.addControl(new GMapTypeControl());
		map.setCenter(new GLatLng(56.951551,24.105463), 14);

		var encodedPolylineA = new GPolyline.fromEncoded({
			color: "#FF0000",
			weight: 3,
			opacity:0.8,
			points: "cmqzIqbcrCOTt@vBjA`AdTvj@FzCWfBmB`CoCnE}@r@oAlDrB`HpDlKbE|LcFxLuAbB_DdC}V}YoCxCc@gDyAmHcQmzAcH}SzOkb@fOwRfEjMqD|EyGhJiHrOe@fJwFpJgJ}X{SpWhBo^fHkQkVki@dEeKxEsLzV~h@b@pCnLtSf@uAeCiEgBgZ~\\_VHpR~DlKdCXjCaDpJ}SfLfSiEva@oCfJeAvFU~CqBjDsHtR_AyAcAtA",
			levels: "BBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB",
			zoomFactor: 3,
			numLevels: 0
		});  map.addOverlay(encodedPolylineA);

    var encodedPolylineB = new GPolyline.fromEncoded({
      color: "#008000",
      weight: 3,
      opacity:0.8,
      points: "ulqzIsccrC]pAn@|AmGfM_QbR{J~EgNdG}BFqEoBsAdE}KxHbL{GjA{D|DhBhCTfRqIxNaLhNsOhDiGdh@xpAkS|rA_EhJaJ|JgMq`@}CwSaFah@gGki@aIys@mH_UjOub@jOeRfFtN_ErDiHxJyH`Oy@jMsElGwIaXwS`VtAm]bUwj@zM`Wn@uAaCoGsAoWn\\_WNjS`Wb|@mDdRiGvKu@uA",
      levels: "BBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB",
      zoomFactor: 3,
      numLevels: 0
    });  map.addOverlay(encodedPolylineB);

    var encodedPolylineC = new GPolyline.fromEncoded({
      color: "#800080",
      weight: 3,
      opacity:0.8,
      points: "olqzIubcrC_@`@z@nC|@BzTpl@G|C}@jBsDvFcB`Bm@|BzAeBlDcFy@}DHkCh@aBjDeArFqAV[Ie@eDlAkCv@aT_j@xEuI|B{I|AmDF{DgJc]wIi[aAeCM^pH~W_AdAyF`DsDhCqCtEsEhI_G|Ka@zGeAxEgD~DaJgWgTrWdBa^lHyQjKiXrNrWf@gAsCkGuAuXh]oV@_Jvd@_LH_UvMfFx@rA`@hCPz]XxBp@`@p@GnAsBd@{PE_AzI{l@|G}YvM_v@|BkKdHyPvGuNjFyLfLaXvBiFN_De@s@kFnM_@rBeFpLw@bAiHpOyFpMOjBsFlM_CrJiGn^qDvSaF~VcDnR{C`TqBtM{CvSqFrYiLuRgCxHhEhIwExb@qBdI}@rFsBjFqBxH_F~KmAqA{@xA",
      levels: "BBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB",
      zoomFactor: 3,
      numLevels: 0
    });  map.addOverlay(encodedPolylineC);



		
		// 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 lat = parseFloat(markers[i].getAttribute("lat"));
				var lng = parseFloat(markers[i].getAttribute("lng"));
				var point = new GLatLng(lat,lng);
				var address = markers[i].getAttribute("address");
				var name = markers[i].getAttribute("name");
				var html = "<b>"+name+"<\/b><p>"+address;
				var type = markers[i].getAttribute("type");
				// create the marker
				var marker = createMarker(point,name,html,type);
				map.addOverlay(marker);
			}

			// == show or hide the categories initially ==
			hide("hop");
			hide("hotel");
			show("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

	//]]>
