/**
 * MPBlockFade.js
 */

(function($){
	
	
	$.fn.blockFade = function(params) {

		// Variables
		var defaultParams = {
			'backgroundClass'  : 'inspiration-block-text-bg',
			'textClass'        : 'inspiration-block-text',
			'backgroundOpacity': '0.8',
			'textOpacity'      : '1.0',
			'speed'            : 500,
			'easing'           : 'linear',
			'isClick'          : false,
			'url'              : ''
		};
		$.extend(defaultParams, params);
		
		// Objects
		var currentObj    = $(this);
		var backgroundObj = currentObj.find('.' + defaultParams.backgroundClass);
		var textObj       = currentObj.find('.' + defaultParams.textClass);
		currentObj.css('cursor', 'pointer');
		backgroundObj.css('opacity', '0.0');
		backgroundObj.css('display', 'block');
		textObj.css('display', 'block');
		textObj.css('opacity', '0.0');
		var top = Math.floor((160 - textObj.height()) / 2);
		textObj.css('top', top + 'px');
		
		// Events
		currentObj.hover(
			function(){
				backgroundObj.css('opacity', '0.0');
				backgroundObj.css('display', 'block');
				textObj.css('display', 'block');
				textObj.css('opacity', '0.0');
				backgroundObj.stop(true, false).animate({opacity: defaultParams.backgroundOpacity}, defaultParams.speed, defaultParams.easing, function(){
					$(this).css('filter', 'none');
				});
				textObj.stop(true, false).animate({opacity: defaultParams.textOpacity}, defaultParams.speed, defaultParams.easing, function(){
					$(this).css('filter', 'none');
				});
			}, 
			function(){
				backgroundObj.stop(true, false).animate({opacity: '0.0'}, defaultParams.speed, defaultParams.easing, function(){
					$(this).css('filter', 'none');
					$(this).css('display', 'none');
				});
				textObj.stop(true, false).animate({opacity: '0.0'}, defaultParams.speed, defaultParams.easing, function(){
					$(this).css('filter', 'none');
					$(this).css('display', 'none');
				});
			}
		);
		if(defaultParams.isClick == true) {
			currentObj.click(function(){
				window.location.href = defaultParams.url;
			});
		}
		
	}
	
	
})(jQuery);
