
//<![CDATA[
var vgooglemap;
var eventClick=0;
function load() {
  if (GBrowserIsCompatible()) {
	vgooglemap = new GMap2(document.getElementById("googlemap"));
	vgooglemap.addControl(new GSmallMapControl());
	vgooglemap.setCenter(new GLatLng(0,0),2);
	vgooglemap.setMapType(G_PHYSICAL_MAP);
	updatemap("top");
	}
}		 

// Creates a marker at the given point with the given number label
function createMarker(point,index, itemtype,itemtname,subtype,htmldata,id  ) {
  var theicon = new GIcon();
 
  theicon.infoWindowAnchor = new GPoint(9, 12);
  theicon.infoShadowAnchor = new GPoint(18, 12);				  			  
  
  if (itemtype == "R") {
	if (subtype == "1") {
		theicon.image =  "/images/mapicons/resortartificial.png"; 
	} else if (subtype == "2") {	
		theicon.image =  "/images/mapicons/resortindoor.png"; 
	} else {
		theicon.image =  "/images/mapicons/resortmtn.png"; 
	}					
	theicon.shadow = "/images/mapicons/shadow.png"
	theicon.iconSize = new GSize(25, 25);	
	theicon.shadowSize = new GSize(37, 25);
	theicon.iconAnchor = new GPoint(9, 25);						  
  } else if (itemtype == "A") {
	theicon.image =  "/images/mapicons/smallairport.png"; 	
	theicon.shadow = "/images/mapicons/smallshadow.png"
	theicon.iconSize = new GSize(22, 22);	
	theicon.shadowSize = new GSize(37, 22);
	theicon.iconAnchor = new GPoint(9, 22);						  	
  }			  

  var marker = new GMarker(point,{icon: theicon,title:itemtname}); 
  GEvent.addListener(marker, "click", function() {
	marker.openInfoWindowHtml(htmldata);
	if (eventClick == 0) {					
		}
	});
  return marker;
}  


function updatemap(what) {

	vgooglemap.clearOverlays();
	var bounds = new GLatLngBounds();
	  GDownloadUrl("/cfpages/xml/homepage_data.cfm?show=" + what, function(data, responseCode) {
	  var xml = GXml.parse(data);
	  var markers = xml.documentElement.getElementsByTagName("marker");
	  totalMarkers=markers.length;
	  for (var i = 0; i < markers.length; i++) {			  	
		var point = new GLatLng(parseFloat(markers[i].getAttribute("lat")),
								parseFloat(markers[i].getAttribute("lng")));

		vgooglemap.addOverlay( createMarker( point, i + 1, markers[i].getAttribute("itemtype"),markers[i].getAttribute("itemname"),markers[i].getAttribute("subtype"),markers[i].getElementsByTagName("htmldata")[0].firstChild.nodeValue,markers[i].getAttribute("id") ) );
		bounds.extend(point);
		}
		var clat = (bounds.getNorthEast().lat() + bounds.getSouthWest().lat()) /2;
		var clng = (bounds.getNorthEast().lng() + bounds.getSouthWest().lng()) /2;
		if (markers.length > 1) {
			vgooglemap.setZoom(vgooglemap.getBoundsZoomLevel(bounds));
		} else {
			vgooglemap.setZoom(10);
		}
		vgooglemap.setCenter(new GLatLng(clat,clng));						
	});	
}		
//]]>

