var allMMMmarkers=[];
var allMMMmarkers2=[];

function MMMarker(latlng, opts/*, dbID,markerWidth,markerHeight,tag, apppath*/) 
{
    this.latlng = latlng;
    this.labelText = opts.labelText || "";
    this.labelClass = opts.labelClass || "markerLabel";
    this.labelOffset = opts.labelOffset || new GSize(0, 0);
	this.intID = opts.dbID;
	this.dot = opts.dot;
    GMarker.apply(this, arguments);

	allMMMmarkers[this.intID] = this;
	allMMMmarkers2.push(this.intID);
}

MMMarker.prototype = new GMarker(new GLatLng(0,0));

// Creates the DIV representing this rectangle.
MMMarker.prototype.initialize = function(map) 
{
	GMarker.prototype.initialize.apply(this, arguments);
		
	// Create the DIV representing our rectangle
	var div = document.createElement("div");
	div.className = this.labelClass;
	div.innerHTML = this.labelText;
	div.style.position = "absolute";
	div.style.textAlign = "center";
	//div.style.border = "solid 1px blue";
	div.style.width = "17px";
	//div.style.background = "red";
	map.getPane(G_MAP_MARKER_PANE).appendChild(div);
	
	// Pass through events fired on the text div to the marker.
	var eventPassthrus = ['click', 'dblclick', 'mousedown', 'mouseup', 'mouseover', 'mouseout'];
	for(var i = 0; i < eventPassthrus.length; i++) 
	{                        
		var name = eventPassthrus[i];                       
		GEvent.addDomListener(div, name, newEventPassthru(this, name));
	}                
	// Mouseover behaviour for the cursor.               
	div.style.cursor = "pointer";

	this.map = map;
	this.div = div;
}

function newEventPassthru(obj, event) 
{        
	return function() 
	{                 
		GEvent.trigger(obj, event);       
	};
}

// Remove the main DIV from the map pane
MMMarker.prototype.remove = function() 
{
	this.div.parentNode.removeChild(this.div);
	this.div = null;
	GMarker.prototype.remove.apply(this, arguments);
}

// Redraw the rectangle based on the current projection and zoom level
MMMarker.prototype.redraw = function(force) 
{
    // We only need to do anything if the coordinate system has changed
    if (!force) return;

	GMarker.prototype.redraw.apply(this, arguments);
    
    // Calculate the DIV coordinates of two opposite corners of our bounds to
    // get the size and position of our rectangle
    var p = this.map.fromLatLngToDivPixel(this.latlng);
    var z = GOverlay.getZIndex(this.latlng.lat());
    
    // Now position our DIV based on the DIV coordinates of our bounds
    this.div.style.left = (p.x + this.labelOffset.width) + "px";
    this.div.style.top = (p.y + this.labelOffset.height) + "px";
    this.div.style.zIndex = z + 1; // in front of the marker
}
