/*
 * RPS Tooltip
 * @requires jQuery UI (effects)
 */
$(document).ready(function(){

// append the tooltip container to the document body
$('body').append('<div class="rps-tooltip"><div class="rps-tooltip-text"></div><div class="rps-tooltip-arrow">&nbsp;</div></div>');

// mouse over listener for tooltip triggers
$('.rps-tooltip-trigger').mouseover(function(mouseevt){
	$('.rps-tooltip .rps-tooltip-text').html( $(this).attr('title') );
	
	// store the offset for the tooltip
	var rps_tooltip_offset = new Object();
	rps_tooltip_offset.top = $(this).offset().top + $(window).scrollTop();
	rps_tooltip_offset.left = $(this).offset().left + $(window).scrollLeft();
	
	// manipulate it to be centered and padded
	rps_tooltip_offset.top -= $('.rps-tooltip').outerHeight() + 8;
	rps_tooltip_offset.left -= ( $('.rps-tooltip').outerWidth() / 2 ) - ( $(this).outerWidth() / 2 );
	
	// reset the offset, VERY IMPORTANT since the
	// offset method is relative
	$('.rps-tooltip').css({
		'position': 'absolute',
		'left': 0,
		'top': 0
	});
	
	// position the tooltip
	$('.rps-tooltip').offset(rps_tooltip_offset);
	
	$('.rps-tooltip').show();
});

// mouse out listener for tooltip triggers
$('.rps-tooltip-trigger').mouseout(function(mouseevt){
	$('.rps-tooltip').hide();
});

});
