/*
   Class Tooltip 
 */
(function(){ 

 	function Tooltip() 
	{
		this.e = null;
		this.tooltipStr = '';
		this.bubble = document.getElementById('bubble_tooltip');
		this.bubbleContent = document.getElementById('bubble_tooltip_content');
		this.bubbleTop = document.getElementById('bt_top');
		this.bubleBottom = document.getElementById('bt_bottom');
	}

	Tooltip.prototype.toString = function() { 
		return "[SB.ui.Tooltip]"; 
	};
	
	Tooltip.prototype.show = function(e, elm){

		var mouseCoords = YUIEvent.getXY(e);
		var region = YUIDom.getRegion( elm );
		var posX = region.left;
		var posY = region.top;
		
		
		this.tooltipStr = elm.tooltipText;
		this.bubbleContent.innerHTML = this.tooltipStr;
		this.bubble.style.display = 'block';
	
		//if( posY-(5+this.bubble.offsetHeight) > YUIDom.getViewportHeight() ){
		if( posY-(5+this.bubble.offsetHeight) > 0 ){
			this.bubble.style.top=(posY-(5+ this.bubble.offsetHeight ))+"px";
		} else {
			this.bubble.style.top=(posY-this.bubble.offsetHeight)+"px";
		}

		this.bubble.style.left = posX+5+"px";
/*
		if ( posX-elm.offsetWidth < 0) {
			this.bubble.style.left = 5 + "px"
		} else {
			//Align center points
			var elmWidth = elm.offsetWidth; 
			var toolWidth = this.bubble.offsetWidth;

			var leftOver = Math.abs(toolWidth - elmWidth); 

			this.bubble.style.left=(posX-Math.round(leftOver/2))+"px";
		}
*/

	/*	
		if ( posX-this.bubble.offsetWidth < 0) {
			this.bubble.style.left = 5 + "px"
		} else {
			this.bubble.style.left=(posX-Math.round(this.bubble.offsetWidth/2))+"px";
		}
	*/
	};	

	Tooltip.prototype.hide = function()
	{
		this.e = null;
		this.tooltipStr = '';
		this.bubble.style.display = 'none';
	};
 
	window['SB']['ui']['Tooltip'] = new Tooltip();

})();
 
