/*
GXMaker v.1 alterada
http://code.toeat.com/
*/

function GxMarkerNamespace() {

var n4=(document.layers);
var n6=(document.getElementById&&!document.all);
var likesDXFilters = false;
var ie=(document.all && !window.opera);
if (ie) {
	var ua = navigator.userAgent;
	var re  = new RegExp("MSIE ([0-9]{1,}[\.0-9]{0,})");
	if (re.exec(ua) != null) {
		var rv = parseFloat( RegExp.$1 );
		if (rv >= 7) { 
			likesDXFilters = true;
		} else if ((rv >= 6) && ((new RegExp("SV1")).exec(ua) != null)) { 
			likesDXFilters = true;
		}
	}

}
window.likesDXFilters = likesDXFilters;
window.ie = ie;

var o6=(navigator.appName.indexOf("Opera") != -1);
var safari=(navigator.userAgent.indexOf("Safari") != -1);

function GxMarker( a, b, tooltip, clickURL, target) {
    this.inheritFrom = GMarker;
    this.inheritFrom(a,b);
    if ( typeof tooltip != "undefined" ) {
        this.setTooltip( tooltip );
    }
	if(!target){this.target='_blank';}else{this.target=target}
	this.clickURL = clickURL;
	this.imagesArray = '';
	this.oldImagePath = "";
	this.events = new Array();

}

GxMarker.prototype = new GMarker(new GLatLng(1,1));

GxMarker.prototype.setTooltip = function( string ) {
    this.tooltip = new Object();
    this.tooltip.contents = string;
};

GxMarker.prototype.showHighlight = function() {
}

GxMarker.prototype.removeHighlight = function() {
}

GxMarker.prototype.initialize = function( a ) {
    try {
        GMarker.prototype.initialize.call(this, a);

		this.events.unshift(GEvent.bind(this, "mouseover", this, this.onMouseOver));
		this.events.unshift(GEvent.bind(this, "mouseout",  this, this.onMouseOut));
		this.events.unshift(GEvent.bind(this, "click",  this, this.onClick));
		this.map = a;
    } catch(e) {
    	console.error(e);
    }
}

GxMarker.prototype.remove = function( a ) {
    GMarker.prototype.remove.call(this);
    if ( this.tooltipObject )
        document.body.removeChild(this.tooltipObject);
	this.removeEvents();
   this.map = null;
}

GxMarker.prototype.onInfoWindowOpen = function() {
    this.hideMouseOver();
    GMarker.prototype.onInfoWindowOpen.call(this);
}

GxMarker.prototype.onClick = function() {
	if (this.clickURL)
	{
		window.open(this.clickURL, this.target);
	}
}

GxMarker.prototype.onMouseOver = function() {
    this.showMouseOver();
};

GxMarker.prototype.onMouseOut = function() {
    this.hideMouseOver();
};

GxMarker.prototype.showMouseOver = function() {
	var bb  = this.map.getBounds();
    if ( this.tooltip ) {
        if ( typeof this.tooltipObject == "undefined" ) {
            this.tooltipObject = document.createElement("div");
            this.tooltipObject.style.display    = "none";
            this.tooltipObject.style.position   = "absolute";
            this.tooltipObject.style.padding    = "0";
            this.tooltipObject.style.margin     = "0";
            this.tooltipObject.style.zIndex     = 50000;
           	this.tooltipObject.innerHTML        = "<div>" + this.tooltip.contents + "</div>";

            document.body.appendChild(this.tooltipObject);
        }

		function getElementPosition(elem) {
		    var offsetTrail = elem;
		    var offsetLeft = 0;
		    var offsetTop = 0;
		    while (offsetTrail) {
		        offsetLeft += offsetTrail.offsetLeft;
		        offsetTop += offsetTrail.offsetTop;
		        offsetTrail = offsetTrail.offsetParent;
		    }
		    if (navigator.userAgent.indexOf("Mac") != -1 && 
		        typeof document.body.leftMargin != "undefined") {
		        offsetLeft += document.body.leftMargin;
		        offsetTop += document.body.topMargin;
		    }
		    return {left:offsetLeft, top:offsetTop};
		}

	if(bb.contains(this.getPoint())){
		var tlcLatLng = this.map.fromContainerPixelToLatLng(new GPoint(0,0), true);
		var tlcDivPixel = this.map.fromLatLngToDivPixel(tlcLatLng);
		var pointDivPixel = this.map.fromLatLngToDivPixel(this.getPoint());
		var c = new GPoint(pointDivPixel.x-tlcDivPixel.x, pointDivPixel.y-tlcDivPixel.y);
		var mapPos = getElementPosition(this.map.getContainer());

		this.tooltipObject.style.left = "-1000px";
        this.tooltipObject.style.top = "-1000px";
        this.tooltipObject.style.display = "block";
		
		var pin = (this.tooltip.contents.indexOf('loc_pin_flag')>=0) ? true : false;
		
        var tipLeft = c.x - this.getIcon().iconAnchor.x + mapPos.left;
        if(pin){
			tipLeft -= ((this.getIcon().iconSize.width/2)-6);
		}else if (tipLeft > (document.body.offsetWidth/2)) {
        	tipLeft -= this.tooltipObject.offsetWidth;
        } else {
        	tipLeft += this.getIcon().iconSize.width;
        }
        this.tooltipObject.style.left = tipLeft + "px";

        var tipTop = c.y - this.getIcon().iconAnchor.y + mapPos.top;
        if(pin){
			tipTop -= ((this.getIcon().iconSize.height*2)+1);
		}else if ((c.y + this.map.getContainer().offsetTop) > (this.map.getContainer().offsetHeight/2)) {
        	tipTop -= this.tooltipObject.offsetHeight;
        } else {
        	tipTop += this.getIcon().iconSize.height;
        }
        this.tooltipObject.style.top = tipTop + "px";

		if(pin&&this.locPinTimeout){
			window.clearTimeout(this.locPinTimeout);
		}
    }
	this.showHighlight();
	}
	
}

GxMarker.prototype.hideMouseOver = function() {
    if ( typeof this.tooltipObject != "undefined" ) {		
		if(this.tooltip.contents.indexOf('loc_pin_flag')>=0){
			gmapeasy.tooltipHolder = this.tooltipObject;
			this.locPinTimeout = window.setTimeout('gmapeasy.tooltipHolder.style.display = "none";gmapeasy.tooltipHolder=null;',2000);
		}else{
			this.tooltipObject.style.display = "none";
		}
    }
	this.removeHighlight();
}

GxMarker.prototype.removeEvents = function () { 
	while (this.events.length > 0) { 
		GEvent.removeListener(this.events.shift());
	}
}
GxMarker.prototype.unload = function () {
	this.removeEvents(); 	 
	this.tooltipObject = null;
	this.tooltip = null;
	this.imagesArray = '';
	this.map = null;
	this.hoverIcon = null;
}
function makeInterface(a) {
    var b = a || window;
    b.GxMarker = GxMarker;
}

makeInterface();
}

GxMarkerNamespace();