// Copyright (c) 2006 by Andrew J. Peterson, NDP Software
// Some Rights Reserved.
// version 1.0, 09-Apr-06


var gMarkers = [];


// Set up the events to show and hide the tooltip
function setTooltipOnMarker(m, tooltip) {
	m.tooltip = '<div class="tooltip">'+tooltip+'</div>';
	
	GEvent.addListener(m,"mouseover", function() {
	  showTooltip(m);
	});        
	GEvent.addListener(m,"mouseout", function() {
		hideTooltip();
	});  
}

/** 
* Hides the tooltip.
* It can be called from an icon mousover or a sidebar mouseover.
*/
function showTooltip(marker) {
	tooltip.innerHTML = marker.tooltip;
	var pt=map.getCurrentMapType().getProjection().fromLatLngToPixel(map.fromDivPixelToLatLng(new GPoint(0,0),true),map.getZoom());
	var offset=map.getCurrentMapType().getProjection().fromLatLngToPixel(marker.getPoint(),map.getZoom());
	var anchor=marker.getIcon().iconAnchor;
	var wd=marker.getIcon().iconSize.width;
	var ht=tooltip.clientHeight;
	var pos = new GControlPosition(G_ANCHOR_TOP_LEFT, new GSize(offset.x - pt.x - anchor.x + wd, offset.y - pt.y -anchor.y -ht)); 
	pos.apply(tooltip);
	tooltip.style.visibility="visible";
}

/** 
* Hides the tooltip.
*/
function hideTooltip() {
	tooltip.style.visibility="hidden";
}

/**
* Makes mouseover of the given element bring up the map tooltips.
*
* @param e Element
* @param mi marker index into gMarkers[] array
*/
function addTooltipOnMouseover(e, mi) {
		e.setAttribute("onmouseover","showTooltip(gMarkers['"+mi+"'])");
		e.setAttribute("onmouseout","hideTooltip()");
}

/**
* Makes mouse over of the map marker change the style of the 
* listing element to contain "mouseOver".
*
* @param e Element
* @param mi marker index into gMarkers[] array
*/
function changeClassOnMarkerMouseover(e, mi) {
	GEvent.addListener(gMarkers[mi],"mouseover", function() {
	  e.className += " mousedOver";
	});        
	GEvent.addListener(gMarkers[mi],"mouseout", function() {
	  e.className = e.className.replace(/ ?mousedOver/," ");
	});        
}

