/*!
 * Simple Caption Overlay v0.1 - A simple caption overlay plugin
 * 
 * NO COPYRIGHTS OR LICENSES. DO WHAT YOU LIKE.
 * 
 * http://www.line22.com/
 * 
 */

(function($){

	//Attatch the new method
	jQuery.fn.extend({

		//Plugin Name
		simpleCaptionOverlay: function(options) {
		
			//Defaults options are set
			var defaults = {
				opacity: '0.5'
			};
			var options = $.extend(defaults, options);  

			return this.each(function() {   
			
				//$(this).find('img').hide();
				
				
				if (!($(this).is('img')))
				{
					var img = $(this).find('img');
			    }
			    else
			    {
			    	var img = $(this);
			    }
			   
			   	//img.hide();
				
				var h = img.height();
				var w = img.width();
				var img_pos = img.position();
				
				$(this).find('.caption').css({
					'width':parseInt(w),
					'height':parseInt(h),
					'position':'absolute',
					'top':0,
					'opacity':0.01,
					'zoom': 1,
					'overflow':'hidden'
				}).find('h2').vAlign();
				
				
				$(this).find('.caption').hover(
					function(){$(this).fadeTo('slow', 0.7);},
					function() {$(this).fadeTo('slow',0.01);}
			//		function() {$(this).siblings("div:first").hide();}	
				);
		

			});

		}

	});
})(jQuery);


(function ($) {
// VERTICALLY ALIGN FUNCTION
$.fn.vAlign = function() {
	return this.each(function(i){
	var ah = $(this).height();
	var ph = $(this).parent().height();
	var mh = Math.ceil((ph-ah) / 2)-7;
	$(this).css('margin-top', mh);
	});
};
})(jQuery);
