function DiscoverMap(map,clusterer) {
	this.map = map;
	this.clusterer = clusterer;
	
	this.markerTitleId = "markerTitle_";
	this.menuId = "markerMenu";
	
	this.styles = new Object();
	this.styles.active = "markerActive";
	this.styles.hover = "markerHover";

	/* closure variables */
	var markerTitleId = this.markerTitleId;
	var menuId = this.menuId;
	var styles = this.styles;

	GEvent.addListener(clusterer, 'refreshed', function(status){
		for (var i=status.length-1; i>=0; i--){
			var $markerMenu = $("#" + markerTitleId + i);
			$markerMenu.get(0).className = "";
			
			if(map._activeMarkerIndex === i){
				$markerMenu.addClass(styles.active)
			}

			$markerMenu.addClass(status[i]);
		}
	});

	GEvent.addListener(clusterer, 'clustermouseover', function(markers) {
		for(var i=markers.length-1; i>=0; i--){
			$("#" + markerTitleId + i).addClass(styles.active);
		}
	});
	
	GEvent.addListener(clusterer, 'clustermouseout', function(markers) {
		for(var i=markers.length-1; i>=0; i--){
			$("#" + markerTitleId + i).removeClass(styles.active);
		}
	});

	/*GEvent.addListener(this.map, 'infowindowopen', function(){
		var $li = document.getElementById('anchor'+$map._activeMarkerIndex);
		$li.className=$li.className+' active';
	});

	GEvent.addListener(this.map, 'infowindowclose', function(){
		var $li=document.getElementById('anchor'+$map._activeMarkerIndex);
		$class=$li.className;
		$class=$class.replace(/\sactive/,'');
		$li.className=$class;
		$map._activeMarkerIndex=false;
	});*/

	GEvent.addListener(this.map, 'moveend', function() { map._lastCenter=map.getCenter(); });
	GEvent.addListener(this.map, 'resize', function() { map.setCenter(map._lastCenter); });
}

DiscoverMap.prototype.displayMarkers=function(){
	var markers = this.clusterer.getMarkers();
	var linksHtml = "<ul>";
	for (var i=0;i<markers.length;i++) {
		var marker = markers[i];
		var data = marker._customData;

		var cls = "markerRemoved";
		if(marker._isVisible){
			cls = 'markerVisible';
		}
		else if(marker._isActive){
			cls = "markerClustered";
		}
		
		linksHtml += "<li class='" + cls + "' id='" + this.markerTitleId + i + "' onclick='discover.menuSelect(" + i + ")'>" 
			+ "<div class='previewDate'>" + data.startDate.replace(" 00:00","") + "</div>"
			+ "<div class='previewCategory' style='color: " + data.color + "'>" + data.title + "</div>"
			+ "<div style='clear:both'></div>" 
			+ "<div class='previewText'>" + data.text + "</div>"
			
		 "</li>";
	}
	linksHtml += "</ul>";
	//alert(linksHtml);
	$("#" + this.menuId).html(linksHtml);
	return;
};

DiscoverMap.prototype.menuSelect=function($id){
	if(this.map._activeMarkerIndex!==$id){
		this.clusterer.triggerClick($id);
	} else {
		this.map.closeInfoWindow();
	}
};

