if (GBrowserIsCompatible()) {
	var map;
	var gicons = [];
	var baseIcon;
	
	function load(mapname, maptype) {
		map = new GMap2(document.getElementById("map"));
		//map.addMapType(G_PHYSICAL_MAP);
		
      	var mt = map.getMapTypes();
      	for (var i=0; i<mt.length; i++) {
        	mt[i].getMinimumResolution = function() {return 0;}
        	mt[i].getMaximumResolution = function() {return 17;}
      	}
		
		if (maptype == 'toplist') {
			map.addControl(new GSmallMapControl());	
			map.setMapType(G_NORMAL_MAP);
		}
		else if (maptype == 'destination') {
			map.addControl(new GLargeMapControl());	
			map.setMapType(G_HYBRID_MAP);		
		}
		else {
			map.addMapType(G_PHYSICAL_MAP);
			map.addControl(new GLargeMapControl());	
			map.setMapType(G_PHYSICAL_MAP);
		}
		map.addControl(new GMapTypeControl());
		
		map.setCenter(new GLatLng(0,0),0);

		baseIcon = new GIcon();
		baseIcon.iconSize   = new GSize(20, 20);
		baseIcon.iconAnchor = new GPoint(10, 10);
		baseIcon.infoWindowAnchor = new GPoint(2, 2);   

		//create an icon for the pins
		var icons = []; 

		for (var i in icons) {
			var iconName = "gfx/icons/" + icons[i] + ".png";
			gicons[icons[i]]  = new GIcon(baseIcon, iconName);
		}		
		
		readMarkers("http://www.touropia.com/feeds/top_markers.php?code=" + mapname + "&type=" + maptype, maptype);		
	}
		
	function createMarker(latlng, point) {
		var marker;
		if (point.dot == 'true') {
			marker = new DotMarker(latlng, "http://www.touropia.com/gfx/markers/" + point.icon + ".gif", [point.title, '']);
			GEvent.addListener(marker, 'click', function() {			
				map.openInfoWindowHtml(latlng, point.desc);		
			});			
		}
		else {
			if (!gicons[point.icon]) {
				var iconName = "http://www.touropia.com/gfx/markers/icon_" + point.icon + ".png";
				gicons[point.icon]  = new GIcon(baseIcon, iconName);			
			}		
			marker = new PdMarker(latlng, gicons[point.icon], point.title);
			marker.setHoverImage("http://www.touropia.com/gfx/markers/hover_" + point.icon + ".png");
			GEvent.addListener(marker, 'click', function() {			
				marker.openInfoWindowHtml(point.desc);		
			});			
		}
	

		return marker;
	}

	function clickMarker(n) {
		GEvent.trigger(gmarkers[n], "click");
	}

	function readMarkers(url, maptype) {
		var bounds = new GLatLngBounds();
		//GLog.writeUrl(url);
		var request = GXmlHttp.create();
		request.open('GET', url, true);
		request.onreadystatechange = function() {
			if (request.readyState == 4) {
				var jscript = request.responseText;
				var points;

				eval(jscript);	
				map.clearOverlays();

				var j = 0;
				var point;
				for (i in points) {
					point = new GLatLng(points[i].lat,points[i].lng);
					var marker = createMarker(point,points[i]);
					map.addOverlay(marker);	
					
					bounds.extend(point);
					j++;

				}
				
				if (j == 1) {	
					if (maptype == 'destination') {
						map.setCenter(point, 15);
					}
					else {
						map.setCenter(point, 8);
					}
				}
				else if (maptype == 'toplist') {
					map.zoomToMarkers(5);
				}
				else {
					map.setZoom(Math.max(map.getBoundsZoomLevel(bounds), 2)); 
					map.setCenter(bounds.getCenter());
          		}
				
			}
		}

		request.send(null);
	}
	
	function DotMarker(point, image, info) {
	  this.point_ = point;
	  this.image_ = image
	  this.info_  = info;
	}

	DotMarker.prototype = new GOverlay();

	DotMarker.prototype.initialize = function(map) {

	  var div = document.createElement("DIV");
	  div.style.position = "absolute";
	  div.style.width = "7px";
	  div.style.height = "7px";
	  div.style.overflow = "hidden";
	  div.style.background = "url(" + this.image_ + ")";
	  if (this.info_ != null){
		  div.title = this.info_[0];
	  }

	  try { div.style.cursor='pointer'; } catch(e) { }

	  GEvent.bindDom(div, 'click', this, function() { GEvent.trigger(this, 'click', this) });

	  map.getPane(G_MAP_MARKER_PANE).appendChild(div);

	  this.map_ = map;
	  this.div_ = div;  
	}

	DotMarker.prototype.remove = function() {
	  this.div_.parentNode.removeChild(this.div_);
	}

	DotMarker.prototype.copy = function() {
	  return new DotMarker(this.point_, this.image_, this.info_);
	}

	DotMarker.prototype.redraw = function(force) {
	  if (!force) return;

	  var p = this.map_.fromLatLngToDivPixel(this.point_);

	  this.div_.style.left = (p.x-3) + "px";
	  this.div_.style.top  = (p.y-3) + "px";
	}
 
	
}
else {
  alert("Sorry, the Google Maps API is not compatible with this browser");
}