var niceTitle = 
{
	width: 300,
	top: 30,
	left: 35,
	limit: 75,
	tag: new Array('acronym', 'abbr'),
	
	position: function (elem)
	{
		if (elem.offsetParent)
		{
			for (var posX = 0, posY = 0; elem.offsetParent; elem = elem.offsetParent)
			{
				posX += elem.offsetLeft;
				posY += elem.offsetTop;
			}
			return [posX, posY];
		}
		else
		{
			return [elem.x, elem.y];
		}
	},
	
	show: function(jqObject)
	{
		// remove title tag and save
		var title = $(jqObject).attr('title');
		$(jqObject).attr('title','');
		
		if(title != '')
		{
			// create new div
			var thisNiceTitle = document.createElement('div');						
			
			// get mouse position
			mpos = niceTitle.position($(jqObject).get(0));
		    mx = mpos[0];
		    my = mpos[1];
				
			// set default styles
			$(thisNiceTitle).attr('class', 'niceTitle');
			$(thisNiceTitle).css('width', niceTitle.width+'px');
			$(thisNiceTitle).css('top', (my+niceTitle.top)+'px');
			$(thisNiceTitle).css('left', (mx+niceTitle.left)+'px');
			$(thisNiceTitle).css('display', 'none');
			
			// add html to new div
			$(thisNiceTitle).html('<div>'+title.replace(/\r\r|\n\n|\r\n\r\n/g, '</div><div>')+'</div>');		
		
			// make sure not too close to browser edge
			if(((mx+niceTitle.width) > ($(window).width()-niceTitle.limit)))
			{
				$(thisNiceTitle).css('left', ($(window).width() - niceTitle.width - niceTitle.limit)+'px');
			}
		    
			// show nice title
			$(thisNiceTitle).appendTo('body');
			$(thisNiceTitle).show();			
			
			$(jqObject).bind('mouseout', function() { niceTitle.hide(jqObject, title); });			
		}		
	},
	
	hide: function(jqTarget, title)
	{
		// hide nice title and add title back to target element
		$('div.niceTitle').remove();
		$(jqTarget).attr('title', title);			
	},

	init: function()
	{
		for(i=0; i<niceTitle.tag.length; i++)
		{
			$(niceTitle.tag[i]).each( function()
			{
				// add events for item
				$(this).bind('mouseover', function() { niceTitle.show($(this)); });				
			});
		}
							
	}
}

// add to document after dom is loaded
$(document).ready(function() { niceTitle.init(); });
