// see tooltip.tag
// (x,y) is where the pointy end of the tooltip should go
//
// NOTE: this tooltip is used in MyPlan>Tools>MoodTracker 
// i.e. 'How Do I Feel Today' tab
//
function showTooltip(id, x, y, content)
{
	if (content != null)
	{
		$(id + '_Content').innerHTML = content;
	}
	// Hack for Mozilla Bug 187435, scrollbars bleed thru overlay.
	// Not perfect, but close enough
	if (navigator.platform.indexOf("Mac") > -1 && !navigator.vendor) {
		$(id + '_Top').style.overflow = 'auto';
		$(id + '_Content').style.overflow = 'auto';
	}
	
	var div = $(id);
	
	// show the tooltip (force width/height calculation)
	div.style.display = 'block';

	var w = div.offsetWidth;
	
	try {
		// clumsy fix for IE to force the Title to not-wrap in ExerciseFinder
		var title = $(id + '_Title');
		title.style.width = (w - 30) + 'px';
	}
	catch (e) {
		// ignore - tooltip doesn't have a Title
	}

	// center the Nub at the bottom
	var nub = $(id + '_Nub');
	nub.style.left = (Math.round(w / 2) - 25) + 'px';

	var fx = (x - Math.round(w / 2) - 6);
	var fy = (y - div.offsetHeight - 27);
	//alert('x=' + x + ' y=' + y + ' divw=' + div.offsetWidth + ' fx=' + fx + 'fy=' + fy);
	div.style.left = fx + 'px';
	div.style.top = fy + 'px';
	
	var top = $(id + '_Top');
	var bottom = $(id + '_Bottom');
	top.style.width = bottom.style.width = (w - 5) + 'px';
}

// see tooltip.tag
function hideTooltip(id)
{
	var div = $(id);
	div.style.display = 'none';
}

//-------------- class TooltipLeft - used with tooltipLeft.tag

var TooltipLeft = Class.create();

TooltipLeft.prototype = {
	initialize: function(options) {
		this.id = options.id; // id of the outer div (and JS variable name)
		this.contentDivId = options.contentDivId;
		this.shrinkHeight = options.shrinkHeight;
		// set options.shrinkHeight to the number of px
		//  that the content area should be reduced in height
		
		this.hideFlag = false;
	},
	dontHide: function() {
		this.hideFlag = false;
	},
	delayHideTooltip: function() {
		this.hideFlag = true;
		setTimeout(this.id + ".hideTooltip(false)", 1);
	},
	// delayHideTooltip calls this with force=false.
	// Set force=true to force it to hide.
	hideTooltip: function(force) {
		if (!force && !this.hideFlag) return;
	
		$(this.id).style.display = 'none';
	},
	showTooltip: function(x, y) {
		this.hideFlag = false;
	
		var tt = $(this.id);
		tt.style.left = x + 'px';
		tt.style.top = y + 'px';
	
		tt.style.display = 'block';
		
		if (this.shrinkHeight)
		{
			// recalc. the height (with 'auto'), then remove the blank section by reducing the height
			var ttc = $(this.contentDivId);
			ttc.style.height = 'auto';
			ttc.style.height = (ttc.getHeight() - this.shrinkHeight) + 'px';
		}
	}
};

//-------------- end of: class TooltipLeft

