/* 
 THE SIMPLE COMPLEX
 http://www.thesimplecomplex.co.uk
 */
(function($){
	$.fn.fader = function(options){
		var defaults = {
			speed: 200,
			content: '',
			inserted: null,
			callback: function(){
						}
			
		};
		options = $.extend(defaults, options || {});
		
		return this.each(function(){
			var el = $(this), tag = this.tagName.toLowerCase(), floaterTag = 'div', floater;
			if (el.hasClass('nojs')) 
			{
				el.removeClass('nojs');
			}
			
			switch (tag)
			{
				case "span":
				case "a":
					floaterTag = "span";
					break;
					
				case "dl":
					floaterTag = "dt";
					break;
					
				case "ul":
				case "ol":
					floaterTag = "li";
					break;
			}
			floater = $('<' + floaterTag + ' class="fader">' + options.content + '</' + floaterTag + '>');
			el.addClass('hasFader');
			
			floater.appendTo(el);
			if (options.inserted) 
			{
				options.inserted();
			}
			floater.css('visibility', 'visible');
			floater.hide();
			
			el.hover(function(){
				// if the element is currently being animated (to fadeOut)...
				if (floater.is(':animated')) 
				{
					// ...stop the current animation, and fade it to 1 from current position
					floater.stop().fadeTo(options.speed, 1);
				}
				else 
				{
					floater.fadeIn(options.speed);
				}
			}, function(){
				if (floater.is(':animated')) 
				{
					floater.stop().fadeTo(options.speed, 0);
				}
				else 
				{
					floater.fadeOut(options.speed);
				}
			});
			
		});
	};
})(jQuery);

