// JavaScript Document

//create the Counter overlay object
function ResultsFlag(marker,html,width) {
	console.log("index: %o -- charcode: %o", html, String.fromCharCode(html+64));
	var count = String.fromCharCode(html+64);
	this.html_ = '<span class="cluster_count">' + count + '</span>';
	this.width_ = (width ? width + 'px' : 'auto');
	this.marker_ = marker;
}

ResultsFlag.prototype = new GOverlay();

cp = ResultsFlag.prototype;

cp.initialize = function(map){
	var div = document.createElement("div");
	div.style.display = 'none';
	map.getPane(G_MAP_MARKER_PANE).appendChild(div);
	this.map_ = map
	this.container_ = div;
}

cp.redraw = function(force) {
	if(!force) return;
	var pixelLocation = this.map_.fromLatLngToDivPixel(this.marker_.getPoint());
	var zIndex = GOverlay.getZIndex(this.marker_.getPoint().y);

	this.container_.innerHTML = this.html_;
	this.container_.style.position = 'absolute';
	this.container_.style.left = pixelLocation.x + 15 + "px";
	this.container_.style.top = pixelLocation.y - 20 + "px";
	this.container_.style.background = "transparent url(/findagent/img/icon_flag.png) no-repeat top right";
	this.container_.style.font = 'bold 12px/12px "Helvetica Neue",Helvetica, arial, sans';
	this.container_.style.color = "#d4021f";
	this.container_.style.textAlign = "center";
	this.container_.style.padding = "0 5px 0 2px";
	this.container_.style.width = "auto";
	this.container_.style.height = "23px";
	this.container_.style.zIndex = zIndex + 1;
	
	this.container_.style.display = 'block';
}

cp.remove = function(){
	this.container_.parentNode.removeChild(this.container_);
}

cp.copy = function(){
	return new Counter(this.html_);
}

GMarker.prototype.ResultsFlagInstance = null;
GMarker.prototype.showResultFlag = function(content){
	if(this.ResultsFlagInstance == null){
		this.ResultsFlagInstance = new ResultsFlag(this, content);
		map.addOverlay(this.ResultsFlagInstance);
	}
}
GMarker.prototype.removeResultFlag = function(){
	if(this.ResultsFlagInstance != null) {
		map.removeOverlay(this.ResultsFlagInstance);
		this.ResultsFlagInstance = null;
	}
}