/*  JQUERY BUBBLE TOOLTIPS BY MIKE JOLLEY
	These tooltips show titles when hovering elements.
*/
function initTooltips(){
	// Create tooltip element
	$('<span id="btc" style="position:absolute"></span>').appendTo("body");
	// Apply to links
	$('.tips').each(function() {
		prepareTooltip(this);		   
	});
}
function prepareTooltip(el){
	// Get title
	title=$(el).attr("title");
	if(title==null || title.length==0) return false;
	// Remove title, Create and set events
	var newTip = $('<span class="tooltip" style="display:block"><span class="tip"><span>'+title+'</span></span></span>');
	$(el).removeAttr("title").removeAttr("alt").mouseover(function(e) {
		$(newTip).appendTo('#btc');
		positionTooltip(e);
	}).mouseout(function() {
		$('#btc').empty();
	}).mousemove(function(e) {
		positionTooltip(e);
	});
}
function positionTooltip(e){
	var posx=0,posy=0;
	if(e==null) e=window.event;
	// Get mouse position
	if(e.pageX || e.pageY){
		posx=e.pageX; posy=e.pageY;
	}
	// Old IE does not use pageX
	else if(e.clientX || e.clientY){
		if(document.documentElement.scrollTop){
			posx=e.clientX+document.documentElement.scrollLeft;
			posy=e.clientY+document.documentElement.scrollTop;
		}
		else{
			posx=e.clientX+$('body').scrollLeft();
			posy=e.clientY+$('body').scrollTop();
		}
	}
	// Now check if enough room to show tip there...
	if (posx > $(window).width() - 200) {
		// Flip it
		$('#btc').css({"top":(posy+10)+"px","left":(posx-190)+"px"});
		$('#btc .tooltip .tip').css("background-image","url(/img/toptip2.gif)");
	} else	{
		$('#btc').css({"top":(posy+10)+"px","left":(posx-20)+"px"});
		$('#btc .tooltip .tip').css("background-image","url(/img/toptip.gif)");
	}
}
