(function($) {
	$.fn.caption = function(options) {
		opts: {}
		
		// Extend default options with those provided.
		var opts = $.extend(opts, options);

		return $(this).each(function(i) {
			var inner = $('<span></span>');
			$(this).next("div.caption").appendTo(inner);
			var layer = $('<span class="layer">')
									.append(inner)
									.appendTo($(this));

			_init($(this));
			
			$(this).hover(
				function() {
					layer.stop().animate({top:($(this).height() - layer.height())+"px"},{queue:false,duration:'normal'});
				},
				function() {
					layer.stop().animate({top:$(this).height()+"px"},{queue:false,duration:'normal'});
				}
			);
		});
	}
	
	// private
	function _init(caption) {
		var li = caption.parent();
		var slideshow = li.children(".slideshow");
		var width;
		var height;
		if (slideshow.size()) {
			var img = slideshow.find('img:eq(0)');
		} else {
			var img = li.find('img');
		}
		width = img.attr("width");
		height = img.attr("height");
		
		caption
		.width(width+"px")
		.height(height+"px")
		.css("top", -(height)+"px")
		.children(".layer").css("top", height+"px");
	}

	// public
	$.fn.caption.init = function(elem) {
		elem = $(elem);
		
		elem.each(function() {
			_init($(this));
		});
	}

})(jQuery);

