
function Markers(color){

map.closeInfoWindow();
   if (document.getElementById(color).checked==false) { // hide the marker
	
      for (var i=0;i<gmarkers.length;i++) {
//   alert(color + gmarkers[i].type);
         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]);
         }
      }
   }
}






  //<![CDATA[
// global variables
var gmarkers=[];

var map;
var request;
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(G_DEFAULT_ICON);
//baseIcon.image = "http://labs.google.com/ridefinder/images/mm_20_red.png";
baseIcon.image = "http://www.yelvertonhistory.org.uk/maps/onoff/mm_20_red.png";
baseIcon.shadow = "http://labs.google.com/ridefinder/images/mm_20_shadow.png";
baseIcon.iconSize = new GSize(12, 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";
//baseIcon.transparent = "http://www.wightstay/maps/onoff/mm_20_red.png"
var icons=[];

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://labs.google.com/ridefinder/images/mm_20_"+ color +".png";
	icon.image = "maps/mm_20_"+ color +".png";
      icons[iconColor]=icon;

   } 
   return icons[iconColor];
}
	

function addMarker(lng, lat, road, town, county, tel, desc, link, image, type, place, iconStr) {
   var point = new GPoint(lng, lat);
   bounds.extend(point);
   var icon = coloredRideshareIcon(iconStr);
   var mopts = new Object();
   mopts.icon = icon; 
   mopts.clickable = true;
   
   var marker = new GMarker(point,mopts);
   gmarkers.push(marker);
   marker.type = iconStr;
     GEvent.addListener(marker, "click", function () {

	if(image == "")
	{	
//       var text = '<div><table width="200"><tr><td>' + '<b><a href="http://' + link + '?map=yes" target="_parent">' + place + '</a></b><br><br>' + desc + '<br><b><a href="http://' + link + '?map=yes" target="_parent">More Info</a><br><br></td></tr></table></div>'
      var text = '<div ><table width="200"><tr><td>' + '<b>' + place + '</b><br>' + desc + '<br><b><a href="http://' + link + '?map=yes" target="_blank">More Info</a><br><br></td></tr></table></div>'
	}
	else
	{
		//var text = '<div><table width="200"><tr><td>' + '<b><a href="http://' + link + '?map=yes" target="_parent">' + place + '</a></b><br><br><a href="http://' + link + '" target="_parent"><img border="0" src="http://www.wightfarmholidays.co.uk/pictures/db/' + image + '" ></a><br><br> ' + desc + '<br><b><a href="http://' + link + '?map=yes" target="_parent">More Info</a></td></tr></table></div>'
//		var text = '<div><table width="200"><tr><td>' + '<b><a href="http://' + link + '?map=yes" target="_parent">' + place + '</a></b><br><br><a href="http://' + link + '" target="_parent"><img border="0" src="../pictures/db/' + image + '" width="150" height="100"></a><br><br> ' + desc + '<br><b><a href="http://' + link + '?map=yes" target="_parent">More Info</a></td></tr></table></div>'
		var text = '<div><table width="200"><tr><td>' + '<b>' + place + '</b><br><img border="0" src="../pictures/db/' + image + '" width="150" height="100"><br> ' + desc + '<br><b><a href="http://' + link + '?map=yes" target="_blank">More Info</a></td></tr></table></div>'
	}
 
     marker.openInfoWindowHtml(text);
     });
   map.addOverlay(marker);
     
}

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("row");
      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("road"),
                   markers[i].getAttribute("town"),
                   markers[i].getAttribute("county"),
                   markers[i].getAttribute("tel"),
		   		   markers[i].getAttribute("desc"),
                   markers[i].getAttribute("link"),                   
                   markers[i].getAttribute("image"),
                   markers[i].getAttribute("type"),
                   markers[i].getAttribute("place"), color);

	 // since all the markers are loaded by default, make sure all the boxes are checked
         document.getElementById(color).checked=true;
      }
   }
}
				  
function makeMap() {
   map = new GMap(document.getElementById("map"));
   map.addControl(new GLargeMapControl());
   map.addControl(new GMapTypeControl());
   map.centerAndZoom(new GPoint(-4.086653,50.491869), 5);	
   request = GXmlHttp.create(); 
   request.open("GET", "maps/yelverton.xml", true); 
   request.onreadystatechange = processXML;
   request.send(null);
}	


			
  