$.fn.tooltip = function(options) {
	var container = this;
	var settings = {
		delay: 200,
		tooltip: '#gd_tooltip'
	};

	var tooltip = $(settings.tooltip);
	
	if(options) {
		$.extend(settings, options);
	}
	
	this.each(function(){
		$(this).attr('tip', $(this).attr('title'));
		$(this).attr('title', '');
	});
	
	var id;

	this.each(function(){
		var div_top = document.getElementById('gd_tooltip').offsetTop;

		$(this).mousemove(function(e){
			var left = e.pageX + 10;
			var topas = e.pageY - div_top + 10;
			bodyScrollTop = document.documentElement && document.documentElement.scrollTop ? document.documentElement.scrollTop : document.body.scrollTop;

			if (tooltip.css('display') != 'block')
			{
				var html = $(this).attr('tip');
				if (html)
				{
					tooltip.html(html);
					if (id != null)
						clearTimeout(id);
					id = setTimeout("$('#gd_tooltip').css('display', 'block')", settings.delay);
				}
			}

			var padding = 30;
			if ($.browser.opera)
			{
				padding = 0;
			}
			if ((left + parseInt($(tooltip).css('width').replace('px', '')) + padding) > document.body.clientWidth)
			{
				left = left - parseInt($(tooltip).css('width').replace('px', '')) - padding;
			}
			tooltip.css('left', left + 'px');
			tooltip.css('top', topas + 'px');
		});

		$(this).mouseout(function(e){
			if (id != null)
				clearTimeout(id);

			$(tooltip).css('display', 'none');
		});
	});
	
	return this;
};