/*
	hoverFade jQuery plugin version 1.0
	
	Copyright (c) 2010 Dan Wellman
  
	Dual licensed under the MIT and GPL licenses:
	http://www.opensource.org/licenses/mit-license.php
	http://www.gnu.org/licenses/gpl.html
	
*/

;(function($) {
	$.hoverFade = {
		defaults: {
			newClass: "hover-anims",
			classToRemove: "hover-css",
			onClass: "on",
			trigger: "a",
			faderTemplate: "<span />"
		}
	};
	
	$.fn.extend({
		hoverFade:function(userConfig) {
																
			//use defaults or properties supplied by user
			var config = $.extend({}, $.hoverFade.defaults, userConfig),
				el = $(this),
				fader = config.faderTemplate.replace("<", "").replace(">", "").replace(" /", "");
			
			//add fader to target el(s)
			el.removeClass(config.classToRemove).addClass(config.newClass).children().each(function() {
				$(this).find(config.trigger).append(config.faderTemplate).find(fader).css("opacity", 0);												
			});
			
			//show element with on class
			$("." + config.onClass, el).find(fader).css("opacity", 1);
						
			//fade in on hover, fade out on off
			$(el).find(config.trigger).not("." + config.onClass).hover(function(){
				$(this).find(fader).stop().animate({
					opacity: 1
				});
			}, function(){
				$(this).find(fader).stop().animate({
					opacity: 0
				});
			});
			
			//return the jquery object for chaining
			return this;
		}
	});
})(jQuery);