//<![CDATA[
/*
*	Tooltip v1.
*
*	Currently seperate functions. Will be rewritten to object later.
*   
**/
// Define heigth and width of icon used.
var iIconHeight = 11;
var iIconWidth = 3;

// define the x-axis margin
var iTTXMargin = 11;

// Function used by getPosition
function subGPoints(a,b) {
	return new GPoint(a.x-b.x, a.y-b.y);
}   

var Tooltip_image = new Image();
Tooltip_image.src = sBaseUrl  + 'GeoStart/images/bg_tooltip.png';


// Get position for the tooltip. Checks of right side is out of bounds. If so, display left.
// return value: object with x and y ( object.x, object.y )
function getPosition( point ){ 
	var mapOffsetTop = oMapObjects.oMap.getContainer().offsetTop;
	var mapOffsetLeft = oMapObjects.oMap.getContainer().offsetLeft;

	var TlcLatLng = oMapObjects.oMap.fromContainerPixelToLatLng(new GPoint(0,0),true);
	var TlcDivPixel = oMapObjects.oMap.fromLatLngToDivPixel(TlcLatLng);
	var pointDivPixel = oMapObjects.oMap.fromLatLngToDivPixel(point);
	var pointContainerPixel = subGPoints(pointDivPixel, TlcDivPixel); 	

	// Get bounds information for the map
	var bounds = oMapObjects.oMap.getBounds();
	var boundsSpan	= bounds.toSpan();
	var longSpan = boundsSpan.lng();
	var mapWidth = oMapObjects.oMap.getSize().width;
	
	// Convert pixel width to degrees ( map width )
	var tooltipWidthInDeg = ( oMapObjects._oTooltip.offsetWidth + iIconWidth + 6 ) / mapWidth * longSpan;
	
	if ( ( point.lng() + tooltipWidthInDeg ) > bounds.getNorthEast().lng() ) {
		// Display left side of marker.
		pointContainerPixel.x = pointContainerPixel.x - oMapObjects._oTooltip.offsetWidth - iTTXMargin + mapOffsetLeft;
		pointContainerPixel.y = pointContainerPixel.y - iIconHeight + mapOffsetTop;
	} else {
		// display right side of marker
		pointContainerPixel.x = pointContainerPixel.x + iIconWidth + iTTXMargin + mapOffsetLeft;
		pointContainerPixel.y = pointContainerPixel.y - iIconHeight + mapOffsetTop;
	}
	// return object
	return pointContainerPixel;
}


// check if tooltip is onscreen
function markerOnScreen(point) {
	var bounds = oMapObjects.oMap.getBounds();
	// check for onscreen.
	if ( point.lng() < bounds.getNorthEast().lng() && point.lat() < bounds.getNorthEast().lat() && point.lng() > bounds.getSouthWest().lng() && point.lat() > bounds.getSouthWest().lat() ) {
		return true;
	} else {
		return false;	
	}
}


// Show the tooltip div at coordinates with sText inside.
function showTooltip( oCoordinates, sText ) {
		oMapObjects._oTooltip.innerHTML = sText;
		oMapObjects._oTooltip.style.top = oCoordinates.y + 'px';
		oMapObjects._oTooltip.style.left = oCoordinates.x + 'px';													  
}

// Show tooltip by calling this function with eg. an anchor.
function showTooltipExternal ( marker ) {
	if ( markerOnScreen(marker.getPoint()) ) {
		oCoordinates = getPosition(marker.getPoint());		
		showTooltip(oCoordinates, marker.tooltip);
	}
}

// Hides the tooltip div.
function hideTooltip () {
	oMapObjects._oTooltip.style.left = '-500px';
    oMapObjects._oTooltip.style.top = '0px';
}

//]]>// JavaScript Document