(function(){
	$.fn.jfade = function(o){
		var setting = {
			speed : 450,        //渐变时间，默认值为450毫秒，只能用数值来表示
			ease  : 'swing',    //
		  //delay : 900,        //默认为2倍speed
			opacity :  0,
			fn: function(){}
			
		};
		
		o = $.extend(setting, o);
		var o_max = o.opacity==0?1:0;
		return this.each(function(){
			var elem = $(this);
			var links = elem.find('a:not(".always")');
			links = links.not('.active');
			//alert(links.length);	
			var always = elem.find('a.always');
			//alert(always.length);	
			
			if(o.opacity!=0) links.animate({opacity:0}, {duration:1});
			
			if(links.length>0){
				links.hover(function(){
					$(this).stop().animate({opacity:o.opacity, ease:o.ease}, {duration:o.speed});	
				}, function(){
					$(this).stop().animate({opacity:o_max, ease:o.ease}, {duration:o.speed, complete:o.fn})
				});
			}
						
			if(always.length>0){
				var timer = setInterval('autoFade()', 2*o.speed);
				
				always.hover(function(){
					clearInterval(timer);
				}, function(){
					timer = setInterval('autoFade()', 2*o.speed);
				});	
				
				autoFade = function(){
					always.animate({
						opacity:o_max, 
						ease:o.ease
					}, {
						duration: o.speed, complete:function(){
							$(this).animate({
								opacity:o.opacity,
								ease:o.ease
							}, { duration:o.speed}
					);}});
				}
			}						  
		});
	};
		
})(jQuery);
