$.imageCaption = function(hotSpot, options) {
	// Create a link to self
	var me = this;

	// Create jQuery object for input element
	var $hotSpot = $(hotSpot).css({display:'block',margin:0,padding:0,position:'relative'});
	$hotSpot.css('height', $hotSpot.height()); //address a positioning/placement bug in versions of IE and Opera

	// Create results and insert into DOM
	var theCaption = document.createElement('p');
	var $theCaption = $(theCaption);
	
	function buildCaption() {
		var captionText = $hotSpot.attr('name');
		$theCaption.html('<span>' + captionText + '</span>').css({
				border:0,
				color:options.textColor,
				display:'block',
				left:0,
				margin:0,
				opacity:0,
				padding:0,
				position:'absolute',
				textAlign:options.align,
				verticalAlign:'baseline',
				width:$hotSpot.width(),
				zIndex:1
			})
			.children().css({
				padding:'2px 6px',
				backgroundColor:options.bgColor
			});
		if (options.valign == 'top') $theCaption.css('top', '2px'); //2px offsets the padding in the span above
		else $theCaption.css('bottom', '6px');
		$hotSpot.append(theCaption);
	}
	
	buildCaption();

	$hotSpot.hover(function() {
		$theCaption.stop().fadeTo(options.speed,0.8);
	}, function() {
		$theCaption.stop().fadeTo(options.speed,0);
	});
};

$.fn.imageCaption = function(options) {
	// Make sure options exists
	options = options || {};

	// Set default values for required options
	options.speed = options.speed || 'normal';
	options.textColor = options.textColor || '#111';
	options.bgColor = options.bgColor || '#fff';
	options.align = options.align || 'left';
	options.valign = options.valign || 'top';

	this.each(function() {
		var hotSpot = this;
		new jQuery.imageCaption(hotSpot, options);
	});

	// Don't break the chain
	return this;
};
