/*!
* jQuery Info Overlay v1.3.1
* http://www.ferretarmy.com/files/jQuery/InfoOverlay/InfoOverlay.html
*
* Copyright (c) 2009-2010 Jon Neal
* Dual licensed under the MIT and GPL licenses, using the same terms as jQuery.
* Refer to http://docs.jquery.com/License
*
* Date: 2010-05-17 (Mon, 17 May 2010)
* Revision: 1.3.1
* This version fixes Webkit issues with images not showing, introduced in 1.3.0.
*/
(function($) {

	$.fn.InfoOverlay = function(options) {
		
		// Options.
		var opts = $.extend({}, $.fn.InfoOverlay.defaults, options);
		
		return this.each(function() {
		
			// Allows metadata options to be set on the field level that override plugin options
			// if the metadata plugin is installed. http://docs.jquery.com/Plugins/Metadata
			var thisOpts = $.metadata ? $.extend({}, opts, $(this).metadata()) : opts;
			var hrefOpts = $.metadata ? $.extend({}, thisOpts, $(this).metadata()) : thisOpts;
			var useBottomOrigin = (hrefOpts.overlay_origin == 'bottom' || hrefOpts.dual_origin ? true : false);
			var useTopOrigin = (hrefOpts.overlay_origin == 'top' || hrefOpts.dual_origin ? true : false);
			var boxHeight = $(this).height();
			var boxWidth = $(this).width();
			
			if (useBottomOrigin)
			{
				var captionHeight = $('.caption-bot', this).height();

				// Set the CSS properties of the caption.
				$('.caption-bot', this).css({
					left: '0px',
					bottom: (hrefOpts.always_show_overlay ? '0px' : -captionHeight + 'px')
				});
			
				// Build bottom hover functionality.
				if (!hrefOpts.always_show_overlay)
				{
					if (hrefOpts.animate)
					{
						$(this).hover(function() {
							$('.caption-bot', this).stop().animate({bottom: '0px'}, {queue: false, duration: hrefOpts.overlay_speed});
						}, function() {
							if (hrefOpts.overlay_speed_out != null)
								$('.caption-bot', this).stop().animate({bottom: -captionHeight + 'px'}, {queue: false, duration: hrefOpts.overlay_speed_out});
							else
								$('.caption-bot', this).stop().animate({bottom: -captionHeight + 'px'}, {queue: false, duration: hrefOpts.overlay_speed});
						});
					}
					else
					{
						$(this).hover(function() {
							$('.caption-bot', this).css('bottom', '0px');
						}, function() {
							$('.caption-bot', this).css('bottom', -captionHeight + 'px');
						});
					}
				}
			}
			
			if (useTopOrigin)
			{
				var captionHeight = $('.caption-top', this).height();

				// Set the CSS properties of the caption.
				$('.caption-top', this).css({
					left: '0px',
					top: (hrefOpts.always_show_overlay ? '0px' : -captionHeight + 'px')
				});
			
				// Build top hover functionality.
				if (!hrefOpts.always_show_overlay)
				{
					if (hrefOpts.animate)
					{
						$(this).hover(function() {
							$('.caption-top', this).stop().animate({top: '0px'}, {queue: false, duration: hrefOpts.overlay_speed});
						}, function() {
							if (hrefOpts.overlay_speed_out != null)
								$('.caption-top', this).stop().animate({top: -captionHeight + 'px'}, {queue: false, duration: hrefOpts.overlay_speed_out});
							else
								$('.caption-top', this).stop().animate({top: -captionHeight + 'px'}, {queue: false, duration: hrefOpts.overlay_speed});
						});
					}
					else
					{
						$(this).hover(function() {
							$('.caption-top', this).css('top', '0px');
						}, function() {
							$('.caption-top', this).css('top', -captionHeight + 'px');
						});
					}
				}
			}
		});
		//$(this).after('<p style="clear: both; height: 0;">&nbsp;</p>');
	};
	
	$.fn.InfoOverlay.defaults = {
		always_show_overlay : false,
		animate : true,
		border_color : '#666',
		dual_origin : false,
		overlay_color : '#000',
		overlay_origin : 'bottom',
		overlay_speed : 'normal',
		overlay_text_color : '#666'
	};

})(jQuery);
