/**---------------------------------------------------------------------------------------------------
 *
 * File:		tooltip.js
 * Date:		25.07.2007
 * Description:	Dynamic ToolTips
 *
 * Usage:
 *
 *--------------------------------------------------------------------------------------------------*/

var	TOOLTIP_TOP		= 1,
	TOOLTIP_BOTTOM	= 2,
	TOOLTIP_LEFT	= 3,
	TOOLTIP_RIGHT	= 4;


/**---------------------------------------------------------------------------------------------------
 *
 * ToolTip Class
 *
 */
function ToolTip( content, body )
{
	this.layer		= new Layer( "layer" + new Date().getTime() );
	this.content	= document.getElementById( content );
	this.body		= document.getElementById( body );
	this.position	= TOOLTIP_TOP;
	
	
	/**
	 * ToolTip Constructor
	 *
	 */
	this.constructor = function()
	{
		this.layer.show( false );
		this.layer.move( -500, -500 );
	}
	
	/**
	 * Sets the position of the tooltip layer
	 *
	 * @param int n
	 */
	this.setPosition = function( n )
	{
		this.position = n;
	}
	
	/**
	 * Displays/hides a tooltip
	 *
	 * @param bool flag
	 * @param object obj
	 * @param string message
	 */
	this.display = function( flag, obj, message )
	{
		var	objWidth	= obj ? obj.offsetWidth : 0,
			objHeight	= obj ? obj.offsetHeight : 0,
			x			= 0,
			y			= 0;
			
		this.body.innerHTML = message
		this.layer.show( flag );
		
		pos = this.layer.getPos( obj );
		
		layerWidth = this.layer.getWidth();
		layerHeight = this.layer.getHeight();
		
		switch( this.position )
		{
			case TOOLTIP_TOP:
				x = (pos[0] + (objWidth / 2)) - (layerWidth / 2);
				y = pos[1] - layerHeight - 1;
				break;
				
			case TOOLTIP_BOTTOM:
				x = (pos[0] + (objWidth / 2)) - (layerWidth / 2);
				y = pos[1] + objHeight;
				break;
				
			case TOOLTIP_LEFT:
				x = pos[0] - layerWidth;
				y = pos[1] - (layerHeight / 2) + (objHeight / 2);
				break;
				
			case TOOLTIP_RIGHT:
				x = pos[0] + objWidth;
				y = pos[1] - (layerHeight / 2) + (objHeight / 2);
				break;
		}
		
		if ( x < 0 )
			x = 0;
			
		if ( y < 0 )
			y = 0;
			
		this.layer.move( x, y );
	}

	
	this.layer.construct( content );
	this.constructor();
}


/*--------------------------------------------------------------------------------------------------*/
