/*
 GxMarker version 1.2

 SYNOPSIS
    This version is compatible with Google Maps API Version 2

    A more full-featured marker that supports tooltips and hover events.  The
    first iteration just supports triggering of mouse over events, and tooltips.
   
    To setup a tooltip, pass in a third parameter (after the icon) to the
    GxMarker class:
        var marker = new GxMarker( new GPoint(lat,lng), icon, "My Tooltip" );
        map.addOverlay(marker);

    Or:
        var marker = new GxMarker( new GPoint(lat,lng) );
        marker.setTooltip("My Tooltip");
        map.addOverlay(marker);

    As of 1.1, changes to setTooltip() should work after the initial invocation

    Please refer to http://code.toeat.com/package/gxmarker for additional
    documentation.
    
    TESTED PLATFORMS:
        Linux: Firefox
        Windows: Firefox, IE6
        Mac OS X (Panther): Safari

    There is no warranty of functionality of this code, if you wish to use it
    and it does not work for you, I recommend you submit a patch.  This software
    is licensed under the GNU Lesser General Public License (LGPL):
    the full text at: http://opensource.org/licenses/lgpl-license.php
	
	Update: 04/07/06 - modified to load with API v2.44+ of the Google Maps API
	Modified by Robert Aspinall - raspinall (AT) gmail (dot) com
*/

function GxMarkerNamespace() {

var n4=(document.layers);
var n6=(document.getElementById&&!document.all);
var ie=(document.all);
var o6=(navigator.appName.indexOf("Opera") != -1);
var safari=(navigator.userAgent.indexOf("Safari") != -1);
var currentSpan = new GBounds();

function setCursor( container, cursor ) {
    try {
        container.style.cursor = cursor;
    }
    catch ( c ) {
        if ( cursor == "pointer" )
            setCursor("hand");
    }
};

function GxMarker( a, b, tooltip1,offset ) {
    this.inheritFrom = GMarker;
		this.offset_=offset||'';
    this.inheritFrom(a,b);
    if ( !currentSpan.minX || a.x < currentSpan.minX ) currentSpan.minX = a.x;
    if ( !currentSpan.maxX || a.x > currentSpan.maxX ) currentSpan.maxX = a.x;
    if ( !currentSpan.minY || a.y < currentSpan.minY ) currentSpan.minY = a.y;
    if ( !currentSpan.maxY || a.y > currentSpan.maxY ) currentSpan.maxY = a.y;
    if ( typeof tooltip1 != "undefined" ) {
        this.setTooltip1( tooltip1 );
    }
}

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

GxMarker.prototype.setTooltip1 = function( string ) {
    //this.removeTooltip1();
    this.tooltip1 = new Object();
    this.tooltip1.opacity  = 78;
    this.tooltip1.contents = string;
};

GxMarker.prototype.initialize = function( a ) {
    try {
        GMarker.prototype.initialize.call(this, a);
        // Setup the mouse over/out events
		GEvent.bind(this, "mouseover", this, this.onMouseOver);
		GEvent.bind(this, "mouseout", this, this.onMouseOut);
    } catch(e) {
		alert(e);
    }
}

GxMarker.prototype.setCursor = function( cursor ) {
    var c = this.iconImage;
    // Use the image map for Firefox/Mozilla browsers
    if ( n6 && this.icon.imageMap && !safari) {
        c = this.imageMap;
    }

    // If we have a transparent icon, use that instead of the main image
    else if ( this.transparentIcon && typeof this.transparentIcon != "undefined" ) {
        c = this.transparentIcon;
    }
}

GxMarker.prototype.remove = function( a ) {
    GMarker.prototype.remove.call(this);
    this.removeTooltip1();
}

GxMarker.prototype.removeTooltip1 = function() {
    if ( this.tooltip1Object ) {
        this.tooltip1Object.parentNode.removeChild(this.tooltip1Object);
        this.tooltip1Object = null;
    }
}

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

GxMarker.prototype.onMouseOver = function() {
    this.showTooltip1();
//    GEvent.trigger(this, "mouseover");
};

GxMarker.prototype.onMouseOut = function() {
    this.hideTooltip1();
//    GEvent.trigger(this, "mouseout");
};

GxMarker.prototype.showTooltip1 = function() {
    if ( this.tooltip1 ) {
        if ( !this.tooltip1Object ) {
            var opacity = this.tooltip1.opacity / 100;
            this.tooltip1Object = document.createElement("div");
						this.tooltip1Object.id= "markerTooltip1";
            this.tooltip1Object.style.display    = "none";
            this.tooltip1Object.style.position   = "absolute";
            this.tooltip1Object.style.background = "none";
            this.tooltip1Object.style.padding    = "0";
            this.tooltip1Object.style.margin     = "0";
            this.tooltip1Object.style.MozOpacity = opacity;
            this.tooltip1Object.style.filter     = "alpha(opacity=" + this.tooltip1.opacity + ")";
            this.tooltip1Object.style.opacity    = opacity;
            this.tooltip1Object.style.zIndex     = 3880000;
            this.tooltip1Object.innerHTML        =  this.tooltip1.contents;

						map1.getPane(G_MAP_MARKER_PANE).appendChild(this.tooltip1Object);
		}

        var c = map1.fromLatLngToDivPixel(new GLatLng(this.getPoint().y, this.getPoint().x));
		try { // this.tooltip1Object.innerHTML=this.tooltip1Object.innerHTML+' !'+this.offset_;
	        if(this.offset_=='camera'){
						if(c.x>420&&c.x<588){
						  this.tooltip1Object.style.left= "420px";
							if(c.y>245&&c.y<384)
							  this.tooltip1Object.style.top  = c.y - ( this.getIcon().iconAnchor.y )-140  + "px";
							else this.tooltip1Object.style.top=c.y+2+"px";	
						}else{
							  this.tooltip1Object.style.left= c.x+9+"px";
							  if(c.y>245&&c.y<384)
							    this.tooltip1Object.style.top  = c.y - ( this.getIcon().iconAnchor.y )- 140  + "px";
								else 	this.tooltip1Object.style.top  = c.y - ( this.getIcon().iconAnchor.y + 3 ) + "px";
							}
					}else{
						if(c.y>331&&c.y<384)
								this.tooltip1Object.style.top  = "311px";
						else {	if(c.y>435&&c.y<500)
						          this.tooltip1Object.style.top  = "400px";
						        else this.tooltip1Object.style.top  = c.y - ( this.getIcon().iconAnchor.y + 3 ) + "px";}
						if(c.x>428&&c.x<588){
							this.tooltip1Object.style.left= "445px";
							if((c.y>310&&c.y<384)||(c.y>435&&c.y<500))
								this.tooltip1Object.style.top=c.y-3+"px";
							else this.tooltip1Object.style.top=c.y+3+"px";
						}else this.tooltip1Object.style.left = c.x + ( this.getIcon().iconSize.width - this.getIcon().iconAnchor.x + 3 ) + "px";
					}
        	this.tooltip1Object.style.display = "block";
		} catch(e) {
			alert(e);
		}
    }
}

GxMarker.prototype.hideTooltip1 = function() {
    if ( this.tooltip1Object ) {
        this.tooltip1Object.style.display = "none";
    }
}

GMap.prototype.flushOverlays = function() {
    currentSpan = new GBounds();
    this.clearOverlays();
}

GMap.prototype.zoomToMarkers = function() {
    var span = new GSize( currentSpan.maxX - currentSpan.minX, currentSpan.maxY - currentSpan.minY );
    for ( var zoom = 0; zoom < this.spec.numZoomLevels; zoom++ ) {
        var ppd = this.spec.getPixelsPerDegree(zoom);
        var pixelSpan = new GSize(
            Math.round(span.width * ppd.x), Math.round(span.height * ppd.y));
        if ( pixelSpan.width  <= this.viewSize.width &&
             pixelSpan.height <= this.viewSize.height )
        { break; }
    }
    this.centerAndZoom( new GPoint( currentSpan.minX + (span.width/2), currentSpan.minY + (span.height/2) ), zoom);
}

function makeInterface(a) {
    var b = a || window;
    b.GxMarker = GxMarker;
}

makeInterface();
}

GxMarkerNamespace();

