//**********************************************************************************************************************
/**
* DOCUMENT: dd-caption.js
* DEVELOPED BY: Dustin Dikes
* EMAIL: dustindikes@gmail.com
* PHONE: 509-279-4968
* DATE: 12/11/2010
* DESCRIPTION: This document contains all the javascript for the caption plugin
*/
//***********************************************************************************************************************

(function($){  
	$.fn.caption = function(options) {
		
		var defaults = {
			types		: 'img,div',
			wrapper		: 'cap_wrap',
			caption		: 'caption'
		};
		
		var options = $.extend(defaults,options);
		
		this.each(function() {  
				
			var obj = $(this);
		
			// Create an object with the items
			var items = obj.children(options.types);
			
			// Loop through each item. For each one we create
			// a wrapper div (if the item isn't already a div and
			// we add a caption div with the rel of the item
			items.each(function(){
				
				var item = $(this);
				
				var height 	= item.height();
				var width	= item.width();
				var quarter	= height/4;
				var type	= this.tagName;
				var caption	= item.attr('rel');
				
				// If the item is already a div, it can be our wrapper
				if(type == 'DIV') {
					item.addClass(options.wrapper);
					var wrap = item;
				}
				// If it isn't a div, we need to wrap it in one
				else {
					item.wrap('<div class="'+options.wrapper+'" />');
					var wrap = item.parent();
				}
				
				// Apply some css to the wrapper div
				wrap.css({
					'height':	height,
					'width':	width,
					'overflow':	'hidden',
					'position': 'relative'
				});	
				
				// Add the caption and apply css
				wrap.append('<div class="'+options.caption+'"><p>'+caption+'</p></div>');
				
				wrap.children('.'+options.caption).css({
					'height': 	quarter,
					'width':	width,
					'position':	'absolute',
					'bottom':	quarter*-1+'px'
				});
				
				$('.'+options.wrapper).hover(function(){
					$(this).children('.'+options.caption).animate({'bottom':0},200);
				},function(){
					$(this).children('.'+options.caption).animate({'bottom':quarter*-1+'px'},100);
				});
				
			});			
			
		});
				
	};
})(jQuery);  

$(function() {
	
	$('.dd-caption').caption();

});


