function ClusterInfo( cluster, regionManager, map ) {
	this.cluster = cluster;
	this.regionManager = regionManager;
	this.map = map;
}

ClusterInfo.prototype.displayClusterInfo = function( ) {
	var p = this.cluster.getControlCenter();
	
	if( this.cluster.getNumberOfMarkers() == 1 ) {
		singleCluster = this.cluster.getClusterData()[0];
		p = new GLatLng( singleCluster.y, singleCluster.x );
	}
	
	var cluData = this.cluster.getClusterData();
	
	var regionHtml = "";
	regionId = cluData[0].regionId;
	for( var i = 0; i < cluData.length; i++ ) {
		if( cluData[i].regionId != regionId ) {	
			regionId = "NOREGION";
			break;
		}
	}
	
	if( regionId == "NOREGION" || 
			this.regionManager.getRegion( regionId ) == null) {
		regionHtml = ""
	} else {
		region = this.regionManager.getRegion( regionId );
		//<img src=\"" + region.logoImage + "\" height=\"50\"><br clear=\"all\">
		regionLink = skiinfoMap.regionDetailURL + "?regionId=" + regionId;
		regionHtml = "<span class=\"gmapCountryTitle\">" + region.countryName + 
					"</span><b class=\"gmapRegionTitle\"><a href=\"" + 
					regionLink + "\">" + region.destname + "</a></b>";
	}
	
	var html = "<h2>Aktivit&auml;ten</h2>" + regionHtml + 
				"<div id=\"gmap_activityList\"><table class=\"gmap_activity_table\">";

	for( var i = 0; i < cluData.length; i++ ) {
		dest = cluData[i];

		destid = "detail_" + dest.destid;
		if( dest.type == "Tour" ) {
			link = skiinfoMap.tourDetailURL + "?tourId=" + dest.destid;
		} else {
			link = skiinfoMap.activityDetailURL + "?destId=" + dest.destid;
		}
		name = "<a href=\"" + link + "\">" + dest.destname + "</a>";
		furtherText = dest.type;
		imgsrc = dest.image;

		imgTag = "";
		if( imgsrc != null && imgsrc != "" ) {
			imgTag = "<img src=\"" + imgsrc + "\" width=\"50\" height=\"50\">";
		}
		
		html += "<tr><td id=\"" + destid + "\" class=\"gmap_thumb\">" + imgTag + "</td>" +
				"<td><span class=\"gmap_activity_title\">" + name + "</span><br><span class=\"gmap_activity_desc\">" + furtherText + "</span></td></tr>";
	}
	
	html += "</table></div>";
	
	this.map.openInfoWindowHtml( p, html );
	
	// Adjust list size to be no more than 250 pixels.
	var dlist = $j("#gmap_activityList");	//document.getElementById("gmap_activityList");
	if( dlist != null ) {
		if( dlist.height() > 200 ) {
			dlist.height( 200 );
			dlist.css( "overflow", "auto" );
		}
		dlist.css( "visibility", "visible");
	}
	
	var infoWindow = this.map.getInfoWindow();
	GEvent.bind( infoWindow, "closeclick", this, this.infoWindowClose );
	
	for( var i = 0; i < cluData.length; i++ ) {
		dest = cluData[i];
		destid = "detail_" + dest.destid;
		detailArea = document.getElementById( destid );
		// Add click + hover events.
	}
};

ClusterInfo.prototype.infoWindowClose = function() {
	this.map.closeInfoWindow();
	return true;
};

ClusterInfo.prototype.followLink = function() {
	if( this.cluster.getNumberOfMarkers() > 1 ) {
		return null;
	}
	singleCluster = this.cluster.getClusterData()[0];
	if( singleCluster.type == "Tour" ) {
		link =  skiinfoMap.tourDetailURL + "?tourId=" + singleCluster.destid;
	} else {
		link =  skiinfoMap.activityDetailURL + "?destId=" + singleCluster.destid;
	}
	location.href = link;
};

ClusterInfo.prototype.displayClusterQuickTip = function( ) {
	cardinality = this.cluster.getNumberOfMarkers();
	infoHtml = "";
	ci = this.cluster.getClusterData();
	
	if( cardinality != 1 ) {	// Display of tool tips for multiple resorts disabled.
		return null;
	}
	
	if( cardinality > 10 ) {
		regions = {};
		for( var i = 0; i < ci.length; i++ ) {
			if( ci[i].regionId != "NOREGION" ) {
				regions[ci[i].regionId] = true;
			}
		}
		
		for( var regname in regions ) {
			infoHtml += regname + "<br>";
		}
	} else if( cardinality > 1 ) {
		activites = {};
		for( var i = 0; i < ci.length; i++ ) {
			infoHtml += ci[i].destname + "<br>";
		}
	} else {
		infoHtml = 
			"<table><tr><td class=\"gmap_thumb\"><img src=\"" + ci[0].image + "\" width=\"50\" height=\"50\"></td><td width=\"100%\">" + ci[0].destname + "</td></tr></table>";
	}

	ovl = new Tooltip( infoHtml, this.cluster );
	this.map.addOverlay( ovl );
	return ovl;
};

ClusterInfo.prototype.displayPlainClusterList = function() {
	infoHtml = "<div  style=\"width:200px; height:70px; overflow:auto; \">";
	ci = this.cluster.getClusterData();
	for( var i = 0; i < ci.length; i++ ) {
		// TODO: Find link for each activity / tour.
		if( ci[i].type == "Tour" ) {
			link = skiinfoMap.tourDetailURL + "?tourId=" + ci[i].destid;
		} else {
			link = skiinfoMap.activityDetailURL + "?destId=" + ci[i].destid;
		}
		infoHtml += "<a href=\"" + link + "\">" + 
					ci[i].destname + "</a><br>";
	}
	infoHtml += "</div>";
	
	ovl = new Tooltip( infoHtml, this.cluster );
	this.map.addOverlay( ovl );
	return ovl;
}

function Tooltip( innerHtml, cluster ) {
	this.innerHtml = innerHtml;
	this.cluster = cluster;
}

Tooltip.prototype = new GOverlay();
Tooltip.prototype.getCluster = function() { return this.cluster; } 
Tooltip.prototype.initialize = function( map ) { 
	this.map = map;
	
	this.div = document.createElement( "div" );
	this.div.style.border = "1px solid black"; 
	this.div.style.position = "absolute";
	this.div.style.margin = "0px";
	this.div.style.padding = "2px";
	this.div.style.backgroundColor = "white";
	this.div.style.zIndex = "500";
	this.div.innerHTML = this.innerHtml;
	this.alignDiv();
	map.getPane( G_MAP_MAP_PANE ).appendChild( this.div );
}
Tooltip.prototype.remove = function() { 
	if( this.div == null ) { return; }
	this.div.parentNode.removeChild( this.div );
	this.div = null;	
}
Tooltip.prototype.copy = function() { 
	return new ToolTip( this.innerHtml );
}
Tooltip.prototype.redraw = function( force ) {
	if( !force ) { return; } 
	this.alignDiv();
}
Tooltip.prototype.alignDiv = function() {
	if( this.div == null ) { return; }
	
	cp = this.cluster.getControlCenter();
	pixelCenter = this.map.fromLatLngToDivPixel( cp );
	divSize = { x: 200, y: 70 };
	topleft = new GPoint( 	pixelCenter.x - divSize.x / 2, 
							pixelCenter.y - 25 - divSize.y );
	this.div.style.top = topleft.y + "px";
	this.div.style.left = topleft.x + "px";
	this.div.style.width = divSize.x + "px";
	this.div.style.height = divSize.y + "px";
}

Tooltip.prototype.getLatLngBounds = function() {
	if( this.div == null ) { return; }
	
	cp = this.cluster.getControlCenter();
	pixelCenter = this.map.fromLatLngToDivPixel( cp );
	divSize = { x: 200, y: 70 };
	topright = new GPoint( 	pixelCenter.x + divSize.x / 2, 
							pixelCenter.y - 25 - divSize.y );
	ne = this.map.fromDivPixelToLatLng( topright );
	bl = new GPoint( topright.x - divSize.x, topright.y + divSize.y );
	sw = this.map.fromDivPixelToLatLng( bl );
	return new GLatLngBounds( sw, ne );
}




