	//<![CDATA[

	var map;
    var gmarkers = [];
    var gicons = [];

    gicons["74"] = new GIcon(G_DEFAULT_ICON,"/wp-content/themes/kaw/images/marker_1.png"); //Activities
	gicons["13"] = new GIcon(G_DEFAULT_ICON,"/wp-content/themes/kaw/images/marker_2.png"); //Accommodation
	gicons["7"] = new GIcon(G_DEFAULT_ICON,"/wp-content/themes/kaw/images/marker_3.png"); //Attractions
	gicons["154"] = new GIcon(G_DEFAULT_ICON,"/wp-content/themes/kaw/images/marker_inf.png"); //Visitor Information
		
		function getUrlParam(name) {
			var query = window.location.search.substring(1);
			var vars = query.split("&");

			for (var i = 0; i < vars.length; i++) {
				var pair = vars[i].split("=");
				if(pair[0]==name) {
					return pair[1];
				}
			}
			return "";
		}
	
		if (GBrowserIsCompatible()) {
	
      // A function to create the marker and set up the event window
      function createMarker(point,name,html,category,post_id) {
        var marker = new GMarker(point,{title: name, icon: gicons[category]});
        // === Store the category and name info as a marker properties ===
        marker.mycategory = category;                                 
        marker.myname = name;
		marker.myid = post_id;
		marker.info = html;
        GEvent.addListener(marker, "click", function() {
          marker.openInfoWindowHtml(html);
        });
        gmarkers.push(marker);
        return marker;
      }

	  // create the map
	  var map = new GMap2(document.getElementById("map_canvas"));  
      //directionsPanel = document.getElementById("route");
      directions = new GDirections(map);
      directions.load("from: Canberra ACT, Australia to: Cooma New South Wales Australia to: Thredbo Village New South Wales Australia to: Khancoban New South Wales Australia to: Albury NSW Australia");
      //map.addControl(new GMapTypeControl());
      map.setCenter(new GLatLng(-36.4679751,148.7120818), 8);
      map.setUIToDefault();
	  
      // Read the data
      GDownloadUrl("/wp-content/themes/kaw/mapxml.php", 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("lon"));
          var point = new GLatLng(lat,lng);
          var address = markers[i].getAttribute("address");
          var name = markers[i].getAttribute("post_title");  
          var website = markers[i].getAttribute("website");
          var email = markers[i].getAttribute("email");
          var phone = markers[i].getAttribute("phone");
          //var thumbnail = markers[i].getAttribute("thumbnail");
          var description = markers[i].getAttribute("description");
		  var post_id = markers[i].getAttribute("post_id");   
         
          // create the marker information window
          var html = '<div id="map_popup" style="width: 310px;">';
          //if(thumbnail) {html += '<img src="'+thumbnail+'" class="map_thumb" alt="thumbnail"/>';}
          html += '<div class="map_popup_content">';
		  html += '<h3 style="font-weight:bold;font-style:normal;font-size:16px;margin-bottom:10px;"><a href="/?p='+post_id+'" title="'+name+'" target="_blank">'+name+'</a></h3>';
          if(description) {html += '<p>'+description+' <a href="/?p='+post_id+'">more</a></p>';}
          if(phone) {html += '<p><strong>Phone:</strong> '+phone+'</p>';}
          if(address) {html += '<p><strong>Address:</strong> '+address+'</p>';}
          if(website) {html += '<p><strong>Website:</strong> <a href="'+website+'" target="_blank">'+website+'</a></p>';}
          html += '<p><strong>Get Directions:</strong> <a href="http://maps.google.com/maps?q=to+'+lat+','+lng+'" title="To here" target="_blank">To here</a> | <a href="http://maps.google.com/maps?q=from+'+lat+','+lng+'" title="From here" target="_blank">From here</a></p>';
          html += '</div></div>';
          
          
          var category = markers[i].getAttribute("parent");
		  var post_id = markers[i].getAttribute("post_id");
          // create the marker
          var marker = createMarker(point,name,html,category,post_id);
          map.addOverlay(marker);
        }
        
          // ========= Now process the polylines ===========
          // var lines = xmlDoc.documentElement.getElementsByTagName("line");
          // read each line
          // for (var a = 0; a < lines.length; a++) {
            // get any line attributes
          //  var colour = lines[a].getAttribute("colour");
         //   var width  = parseFloat(lines[a].getAttribute("width"));
            // read each point on that line
         //   var points = lines[a].getElementsByTagName("point");
         //   var pts = [];
         //   for (var i = 0; i < points.length; i++) {
         //      pts[i] = new GLatLng(parseFloat(points[i].getAttribute("lat")),
         //                          parseFloat(points[i].getAttribute("lng")));
         //   }
        //    map.addOverlay(new GPolyline(pts,colour,width));
        //  }
          // ================================================ 
        
        // == show or hide the categories initially ==
		
		showall();  
		
		var markerId = getUrlParam("marker");
		
		if (markerId != '') {
			showmarker(markerId);
		}
		
		document.getElementById("show-way").checked = true;

		
      });
    }
	else {alert("Sorry, the Google Maps API is not compatible with this browser");}
		  
	  // == shows a specific marker
      function showmarker(markerId) {
        for (var i=0; i<gmarkers.length; i++) {
          if (gmarkers[i].myid == markerId) {
            gmarkers[i].show();
			gmarkers[i].openInfoWindowHtml(gmarkers[i].info);
			map.panTo(gmarkers[i].getLatLng());
			document.getElementById(gmarkers[i].myid+"box").checked = true;
          }
        }
      }
      
	  // == hides all markers of a particular category, and ensures the checkbox is cleared ==
      function hidemarker(marker) {	  
        for (var i=0; i<gmarkers.length; i++) {
          if (gmarkers[i].myid == marker) {
            gmarkers[i].hide();
            // == clear the checkbox ==
        	document.getElementById(marker+"box").checked = false; 
 			// == close the info window, in case its open on a marker that we just hid
        	map.closeInfoWindow();
          }
        }
      
       
      }
	  
	  // == hides all markers 
      function hideall() {	  
        for (var i=0; i<gmarkers.length; i++) {
            gmarkers[i].hide();
            document.getElementById(gmarkers[i].myid+"box").checked = false;
        }
      }
 
 	  // == hides all markers 
      function showall() {	  
        for (var i=0; i<gmarkers.length; i++) {
            gmarkers[i].show();
            document.getElementById(gmarkers[i].myid+"box").checked = true;
        }
      }
      
      
	  
	  // == a checkbox has been clicked ==
      function boxclick(box,marker) {
        if (box.checked) {
          showmarker(marker);
        } else {
          hidemarker(marker);
        }
      }

      function myclick(i) {
        GEvent.trigger(gmarkers[i],"click");
      }
      
      
      	  // == a checkbox has been clicked ==
      function directionsclick(box) {
        if (box.checked) {
          directions.load("from: Canberra ACT, Australia to: Khancoban NSW, Australia");
        } else {
          directions.clear();
        }
      }
	  
	//]]>

