function Markers(color){
 
map.closeInfoWindow();
   if (document.getElementById(color).checked==false) { // hide the marker
      
      for (var i=0;i<gmarkers.length;i++) {
         if (gmarkers[i].type==color)  {
            map.removeOverlay(gmarkers[i]);
             
         }
      }
   } else { // show the marker again
      for (var i=0;i<gmarkers.length;i++) {
         if (gmarkers[i].type==color)  {
            map.addOverlay(gmarkers[i]);
            
         }
      
      }
   }

}

// global variables
var gmarkers=[];
var map;
//var minimap;
var request;
var bounds = new GLatLngBounds(); //www
//var bounds = new GBounds(-Number.MAX_VALUE, -Number.MAX_VALUE, Number.MAX_VALUE, Number.MAX_VALUE); 
// Create our "tiny" marker icon 
var baseIcon = new GIcon();
baseIcon.image = "http://www.goldcoastchat.com.au/images/mm_20_blue.png";
baseIcon.shadow = "http://www.goldcoastchat.com.au/images/mm_20_shadow.png";
baseIcon.iconSize = new GSize(12, 20);
baseIcon.shadowSize = new GSize(22, 20);
baseIcon.shadowSize = new GSize(22, 20);
baseIcon.iconAnchor = new GPoint(6, 20);
baseIcon.infoWindowAnchor = new GPoint(5, 1);
baseIcon.imageMap = [4,0,0,4,0,7,3,11,4,19,7,19,8,11,11,7,11,4,7,0]; 
//baseIcon.transparent = "mapIcons/mm_20_transparent.png";

var icons=[];

// create the crosshair icon, which will indicate where we are on the minimap
      // Lets not bother with a shadow
 // create the crosshair icon, which will indicate where we are on the minimap
      // Lets not bother with a shadow
     // var IconX = new GIcon();
    //  IconX.image = "http://www.goldcoastchat.com.au/images/x.png";
    //  IconX.iconSize = new GSize(21, 21);
    //  IconX.shadowSize = new GSize(0,0);
   //   IconX.iconAnchor = new GPoint(11, 11);
   //   IconX.infoWindowAnchor = new GPoint(11, 11);
   //   IconX.infoShadowAnchor = new GPoint(11, 11);
      
 

   //   var map_moving = 0;
   //   var minimap_moving = 0;
 
 // var xhair;       
      //

function coloredRideshareIcon(iconColor) {
   var color;
   if ((typeof(iconColor)=="undefined") || (iconColor==null)) { 
      color = "red" 
   } else { 
      color = iconColor; 
   }
   if (!icons[iconColor]) {
      var icon = new GIcon(baseIcon);
      icon.image = "http://www.goldcoastchat.com.au/images/"+ color +".png";
      icons[iconColor]=icon;

   } 
   return icons[iconColor];
}
	

function addMarker(lng, lat, title, rating, imgurl, desc, affurl, affurltext, iconStr) {
   var point = new GLatLng(lat,lng);
   bounds.extend(point);
   var icon = coloredRideshareIcon(iconStr);
   var marker = new GMarker(point, icon);
   gmarkers.push(marker);
   marker.type = iconStr; 
   GEvent.addListener(marker, "click", function () {
      // FF 1.5 fix
      var text ="<div style='width:350px;height:150px;font-size:10px;font-family:arial;padding:3px;'><span style='font-weight:bold;color:green;font-size:13px;'>" + title + "</span><br/><img src='http://www.goldcoastchat.com.au/images/" + rating + ".gif'/><br/><img style='border:1px solid #cccccc;padding:3px;margin:3px;height:111px;width:82px;float:left' src='" + imgurl + "' />" + desc + "<br/><a style='float:right;font-size:13px;' href='" + affurl + "' target='_blank' rel='nofollow'>" + affurltext + "</a><br clear='all'/></div>";
      marker.openInfoWindowHtml(text);
   });
   map.addOverlay(marker);
  document.getElementById('msg_div').style.display = 'none';  
}


function processXML() { 
   if (request.readyState == 4) {
      if (request.status != 200) {
         alert("file not found:"+request.status);
         return;
      }
      var xmlDoc = request.responseXML;
      if (!xmlDoc) {
         alert("invalid xml file");
         return;
      }
      markers = xmlDoc.documentElement.getElementsByTagName("marker");
      for (var i=0; i < markers.length; i++) {
         var color= markers[i].getAttribute("icon");
         addMarker(parseFloat(markers[i].getAttribute("lng")),
                   parseFloat(markers[i].getAttribute("lat")),
                   markers[i].getAttribute("title"),
                   markers[i].getAttribute("rating"),
                   markers[i].getAttribute("imgurl"),
                   markers[i].getAttribute("desc"),
                   markers[i].getAttribute("affurl"),
                   markers[i].getAttribute("affurltext"), color);
            
	 // since all the markers are loaded by default, make sure all the boxes are checked
         document.getElementById(color).checked=true;
         //var points = new GLatLng(lat,lng);
         //bounds.extend(points);//
      }
       // ===== determine the zoom level from the bounds =====
          map.setZoom(map.getBoundsZoomLevel(bounds)); 
       // ===== determine the centre from the bounds ======
          var clat = (bounds.getNorthEast().lat() + bounds.getSouthWest().lat()) /2;
          var clng = (bounds.getNorthEast().lng() + bounds.getSouthWest().lng()) /2;
          map.setCenter(new GLatLng(clat,clng));
          //minimap.setCenter(new GLatLng(clat,clng), 8); 
           
   }
} 
				  
function makeMap() {
   map = new GMap(document.getElementById("map"));
   //minimap = new GMap(document.getElementById("minimap"));
   map.addControl(new GLargeMapControl());
   map.addControl(new GMapTypeControl());
   //map.setCenter(new GLatLng(-27.99784970700706, 153.43055248260498), 15);	
   map.setCenter(new GLatLng(0, 0), 0);
   //minimap.setCenter(new GLatLng(0, 0), 0);
   request = GXmlHttp.create(); 
   request.open("GET", "moonPilot.xml", true); 
   request.onreadystatechange = processXML;
   request.send(null);
   //GEvent.addListener(map, 'move', Move);
   //GEvent.addListener(minimap, 'moveend', MMove); 
   //xhair = new GMarker(minimap.getCenter(), IconX);
   //minimap.addOverlay(xhair);       
  
 }	


      // This function handles what happens when the main map moves
      // If we arent moving it (i.e. if the user is moving it) move the minimap to match
      // and reposition the crosshair back to the centre
// function Move(){
//        minimap_moving = true;
//	if (map_moving == false) {
//	  minimap.setCenter(map.getCenter());
//	  xhair.setPoint(map.getCenter());
//	  xhair.redraw(true);
//	  
//	}
//	minimap_moving = false;
//      }
//      // This function handles what happens when the mini map moves
      // If we arent moving it (i.e. if the user is moving it) move the main map to match
      // and reposition the crosshair back to the centre
// function MMove(){
//        map_moving = true;
//	if (minimap_moving == false) {
//	  map.setCenter(minimap.getCenter());
//	  xhair.setPoint(minimap.getCenter());
//	  xhair.redraw(true);
//	}
//	map_moving = false;
//      }
      
      // Listen for when the user moves either map
      
   			
