/**
 * Title: SimpleTooltip
 * Version: 0.1
 *
 * Summary:
 * A simple tooltip class working with the prototype library
 *
 * Updated: 2008/11/11
 *
 * Maintainer: Jeroen Pfeil <jeroen@webaholics.eu>
 *
 */
var SimpleTooltip = Class.create({
	tooltipId: '',
	tooltip:'',
	leftOffset:15,
	topOffset:15,
	defaultClass: 'simpletooltip',
	initialize: function(tooltipId) {
		this.tooltipId = tooltipId;
	},
	getTooltip: function() {
		if($(this.tooltipId))return $(this.tooltipId);
		//Tooltip does not exists yet, create it
		var tooltip = document.createElement('div');
		tooltip.setAttribute('id',this.tooltipId);
		tooltip.className = 'simpletooltip'; 
		tooltip.style.position = 'absolute';
		document.getElementsByTagName('body')[0].appendChild(tooltip);
		return tooltip;
	},
	showTooltip: function(eventObj,tooltipContent,heading,tooltipClass) {
		if(!$(this.tooltipId)) {
			this.tooltip = this.getTooltip();
		}
		x = Event.pointerX(eventObj);
		y = Event.pointerY(eventObj);
		
		if(heading){
			head = "<strong class='simpletooltip_heading'>" + heading +  "</strong>";
		} else {
			head = '';
		}
		
	
		if(tooltipClass) {
			this.tooltip.className = 'simpletooltip '+tooltipClass;	
		} else {
			this.tooltip.className = 'simpletooltip';	
		}
		
		this.tooltip.innerHTML = head + tooltipContent;
		this.tooltip.style.display = 'block';
		this.tooltip.style.left = (x + this.leftOffset) + "px";
		this.tooltip.style.top = (y + this.topOffset) + "px";
	},
	hideTooltip: function() {
		if(this.tooltip) {
			this.tooltip.style.display = 'none';
		}
	},
	moveTooltip: function(eventObj) {
		x = Event.pointerX(eventObj);
		y = Event.pointerY(eventObj);
		
		if(!$(this.tooltipId)) {
			this.tooltip = this.getTooltip();
		}
		this.tooltip.style.left = (x + this.leftOffset) + "px";
		this.tooltip.style.top = (y + this.topOffset) + "px";
	}
});
