$.fn.edFade = function(options) {  

	var defaults = {  
		pause:5000,
		auto:true,
		nextMessage:"Click for Next"
	};  
 
	var options = $.extend(defaults, options);  
  
	return this.each(function() {  
		
		//vars
		var element = $(this);
		var item = element.find("li");
		var itemNo = item.length;
		var elementCss = {
			"position":"relative"
		};
		var itemCss = {
			"position":"absolute",
			"top":"0px",
			"left":"0px",
			"display":"none",
			"z-index":"2"
		};
		
		//setup
		element.css(elementCss);
		item.css(itemCss);
		
		item.each(function(i){
			i++;		
			$(this).attr("id","item"+i);
		});	
		
		if(options.auto == true){
			element.find("li:last").clone().appendTo(element).addClass("clone").css("z-index","1").show("");
			element.attr("paused",false);
		}else{
			element.find("li:first").show("");
		}
							
		//call functions
		if(options.auto == true){
			auto();
		}else{
			clicker();
		}
				
		element.mouseover(function(){
			$(this).attr("paused",true);
		});
		
		element.mouseout(function(){
			$(this).attr("paused",false);
		});
				
		//functions
		function fade(i){
			var fade = "#item"+i;
			item.fadeOut("slow");
			$(fade).fadeIn("slow");
			$(".clone").fadeOut("slow",function(){
				$(this).remove();
			});
		}
		
		function auto (){							
			item.each(function(i){
				i++;		
				setTimeout(function(){									
					var paused = element.attr("paused");
					if(paused == "false"){
						fade(i);
					}		
					if(i == itemNo){
						auto();
					}
					return false;
				},options.pause * i);
			});
		}
		
		function clicker(){
			var infoCss = {
				"position":"absolute",
				"bottom":"-10px",
				"right":"0px",
				"z-index":"3",
				"font-size":"10px",
				"color":"#000"
			};
			item.append("<span class='info'>"+options.nextMessage+"</span>").css("cursor","pointer");
			element.find(".info").css(infoCss);
			item.click(function(){
				var next = $(this).next(item).attr("id");
				var next = "#"+next;
				item.fadeOut("slow");
				if(next != "#undefined"){
					$(next).fadeIn("slow");
				}else{
					element.find("li:first").fadeIn("slow");
				}
			});
		}
						
	});  
};

