// GCompoundMarker
function GCompoundMarker( markerWidth, markerHeight, points) {
	this.points_ = points;
	this.markerWidth_ = markerWidth;
	this.markerHeight_ = markerHeight;
	this.NONE = -1;
}
GCompoundMarker.prototype = new GOverlay();

GCompoundMarker.prototype.initialize = function(map) {
	var pane = map.getPane(G_MAP_MARKER_PANE);
	var signals = ["mouseover", "mouseout", "click"];
	this.divs_ = [];
	this.map_ = map;
	this.selected_ = this.NONE;
	this.hovered_ = this.NONE;
	var self = this;
	/*
	var img = new Image();

	img.onload = function() {
		setTimeout(function() {
			for (var i = 0; i < self.divs_.length; i++)
				self.divs_[i].style.backgroundImage = "url(" + self.markerSrc_ + ")";
		}, 50);
	};*/

	//img.src = this.markerSrc_;

	for (var i = 0; i < this.points_.length; i++)
	{		
		var div = document.createElement("div");
		div.id = "float_marker_"+this.points_[i].photo_id;
		var s = div.style;
		s.border = "1px solid white";
		s.width = (this.markerWidth_ - 2) + "px";
		s.height = (this.markerHeight_ - 2) + "px";
		s.backgroundPosition = "-1px " + (-i * this.markerHeight_ - 1) + "px";
		s.position = "absolute";
		s.cursor = "pointer";
		s.zIndex = GOverlay.getZIndex(this.points_[i].pos.lat());
		

		pane.appendChild(div);
		this.divs_.push(div);
		
		this.divs_[i].style.backgroundImage = "url(" + this.points_[i].img + ")";

		for (var j = 0; j < signals.length; j++)
		{
			(function(){
			var i__ = i;
			var signal__ = signals[j];
			GEvent.addDomListener(div, signal__, function() {
				GEvent.trigger(self, signal__, i__);
			});
			})();
		}
	}
};

GCompoundMarker.prototype.remove = function(map) {
	for (var i = 0; i < this.divs_.length; i++)
	{
		this.divs_[i].parentNode.removeChild(this.divs_[i]);
		GEvent.clearInstanceListeners(this.divs_[i]);
	}
};

GCompoundMarker.prototype.removeMarker = function(map,j) {
	for (var i = 0; i < this.divs_.length; i++)
	{
		if(parseInt(i)==parseInt(j)){
			this.divs_[i].parentNode.removeChild(this.divs_[i]);
			GEvent.clearInstanceListeners(this.divs_[i]);
			
		}
	}
};

GCompoundMarker.prototype.copy = function() {
	return new GCompoundMarker(this.markerWidth_, this.markerHeight_, this.points_);
};

GCompoundMarker.prototype.redraw = function(force) {
	if (!force)
		return;

	for (var i = 0; i < this.points_.length; i++)
	{
		var c = this.map_.fromLatLngToDivPixel(this.points_[i].pos);
		var s = this.divs_[i].style;
		s.left = (c.x - this.markerWidth_ / 2 - 1) + "px";
		s.top = (c.y - this.markerHeight_ / 2 - 1) + "px";
	}
};

GCompoundMarker.prototype.select_byid = function(id) {
	for(var i = 0; i < this.divs_.length; i++){
		if(this.divs_[i].id=="float_marker_"+id){
			this.select(i);
			return;
		}
	}
};

GCompoundMarker.prototype.select = function(i) {
	if (this.selected_ != this.NONE)
	{
		var s = this.divs_[this.selected_].style;
		s.border = "1px solid white";
		s.left = (parseInt(s.left) + 1) + "px";
		s.top = (parseInt(s.top) + 1) + "px";
		s.zIndex = GOverlay.getZIndex(this.points_[this.selected_].pos.lat());
	}

	if (i == this.NONE || (i >= 0 && i < this.divs_.length))
	{
		this.selected_ = i;
		if (i != this.NONE)
		{
			var s = this.divs_[i].style;
			s.border = "2px solid red";
			s.left = (parseInt(s.left) - 1) + "px";
			s.top = (parseInt(s.top) - 1) + "px";
			s.zIndex = GOverlay.getZIndex(-90.0);
		}
	}
};

GCompoundMarker.prototype.hover = function(i) {
	if ((this.hovered_ != this.NONE) && (this.hovered_ != this.selected_)){
		var s = this.divs_[this.hovered_].style;
		s.border = "1px solid white";
		s.left = (parseInt(s.left) + 1) + "px";
		s.top = (parseInt(s.top) + 1) + "px";
		s.zIndex = GOverlay.getZIndex(this.points_[this.hovered_].pos.lat());
	}

	if (i == this.NONE || (i >= 0 && i < this.divs_.length))
	{
		this.hovered_ = i;
		if ((i != this.NONE)&& (i != this.selected_))
		{
			var s = this.divs_[i].style;
			s.border = "2px solid #c6701e";
			s.left = (parseInt(s.left) - 1) + "px";
			s.top = (parseInt(s.top) - 1) + "px";
			s.zIndex = GOverlay.getZIndex(-90.0);
		}
	}
};

