(function($) {
	$.fn.tooltip = function(options) {
		/*
		** Default settings
		*/
		var settings = {
			'location'	:	'float',	//float, top, bottom
			'skin'		:	'yellow',	//yellow, black, white, blue, red, green
			'element'	:	'*',		//'*' for all elements with alt, or use selector
			'width'		:	'250px',	//tooltip's width
			'height'	:	'20px'		//tooltip's height
		};

		return this.each(function() {
			if (options)
			{
				$.extend(settings, options);
			}

			var self = $(this);

			$(settings.element).live('mouseenter', function(e) {
				//Mouse over event handler on targeted element(s)
				var element = $(this);
				var altText = element.attr('alt');

				e.stopImmediatePropagation();
				e.stopPropagation();

				if (altText != undefined)
				{
					//Add skin, set dimension, set text
					self.addClass(settings.skin).css({width:settings.width, height:settings.height}).html(altText);

					if (settings.location == 'float')
					{
						//Floating tooltips
						var leftPos = element.offset().left + 'px';
						var topPos = (element.offset().top - (parseInt(settings.height) + 20)) + 'px';
						self.removeClass('top bottom').css({left:leftPos, top:topPos}).hide().show('fast');
					}
					else if (settings.location == 'top')
					{
						//Add class top and remove class bottom if location=top						
						var screenTop = $(window).scrollTop();
						self.removeClass('bottom').addClass('top').css({top: screenTop+'px'}).hide().show('fast');
					}
					else if (settings.location == 'bottom')
					{
						//Add class bottom and remove class top if location=bottom
						var screenTop = $(window).scrollTop();
						self.removeClass('top').addClass('bottom').css({bottom: -screenTop+'px'}).hide().show('fast');
					}
				}
				else {
					//No alt text found, hide tooltips
					self.hide('fast', function(){
						self.removeClass('top bottom').css({left:'-9999px', top:'-9999px'});
					})
				}
			}).live('mouseout', function(e) {
				//Mouse out event handler on targeted element(s)
				e.stopImmediatePropagation();
				e.stopPropagation();
				self.hide('fast', function(){
					self.removeClass('top bottom').css({left:'-9999px', top:'-9999px'});
				})
			});
		});
	};
})(jQuery);
