(function($){
	var to = function(container, fromNr, toNr){
		var $this = container;

		$("#step-"+fromNr, $this).removeClass("current").fadeOut(200, function(){
			$("#step-"+toNr, $this).addClass("current").fadeIn(200);
		});
	};

	var methods = {
		init: function(){
			return this.each(function(){
				var $this = $(this);

				$('.step[data-step-nr="1"]', $this).addClass("current");
				$(".step", $this).not('.current').hide();
			});
		},
		to: function(params){
			return this.each(function(){
				var $this = $(this);
				var fromNr = parseInt($(".current", $this).attr("data-step-nr"));
				var toNr = params.nr;

				to($this, fromNr, toNr);
			});
		},
		next: function(){
			return this.each(function(){
				var $this = $(this);
				var fromNr = parseInt($(".current", $this).attr("data-step-nr"));

				to($this, fromNr, fromNr+1);
			});
		},
		back: function(){
			return this.each(function(){
				var $this = $(this);
				var fromNr = parseInt($(".current", $this).attr("data-step-nr"));

				to($this, fromNr, fromNr-1);
			});
		}
	};

	$.fn.fader = function(method){
		if(methods[method]){
			return methods[method].apply(this, Array.prototype.slice.call(arguments, 1));
		}else if(typeof method === "object" || !method){
			return methods.init.apply(this, arguments);
		}else{
			$.error("Method " +  method + " does not exist on jQuery.fader");
		}    
	};
})(jQuery);
