(function(e){
	var f={init:function(b){
		return this.each(function(){
			var d=e.extend({},e.fn.stepy.defaults,b),a=e(this).data("options",d),c=a.attr("id");
			if(void 0===c||""==c)c="stepy-"+e("."+a.attr("class")).index(this),a.attr("id",c);
			var h=e("<ul/>",{id:c+"-titles","class":"stepy-titles clearfix"});
			d.titleTarget?e(d.titleTarget).html(h):h.insertBefore(a);
			d.validate&&(jQuery.validator.setDefaults({ignore:d.ignore}),a.append('<div class="stepy-error"/>'));
			var g=a.children("fieldset"),l=void 0,n=void 0,
	r="",m="";g.each(function(k){
		l=e(this);l.addClass("step").attr("id",c+"-step-"+k).append('<p id="'+c+"-buttons-"+k+'" class="'+c+'-buttons"/>');
		n=l.children("legend");d.legend||n.hide();r="";
		d.description&&(n.length?r="<span>"+n.html()+"</span>":e.error(c+": the legend element of the step "+(k+1)+" is required to set the description!"));
		m=l.attr("title");m=""!=m?"<div>"+m+"</div>":"--";h.append('<li id="'+c+"-title-"+k+'">'+m+r+"</li>");
		l.attr("title","");0==k?1<g.length&&f.createNextButton.call(a,
k):(f.createBackButton.call(a,k),l.hide(),k<g.length-1&&f.createNextButton.call(a,k))});var p=h.children();p.first().addClass("current-step");var q=a.children(".finish");if(d.finishButton)if(q.length){var t=a.is("form"),s=void 0;d.finish&&t&&(s=a.attr("onsubmit"),a.attr("onsubmit","return false;"));q.click(function(c){d.finish&&!f.execute.call(a,d.finish,g.length-1)?c.preventDefault():t&&(s?a.attr("onsubmit",s):a.removeAttr("onsubmit"),"submit"==q.attr("type")||d.validate&&!f.validate.call(a,g.length-
1)||a.submit())});q.appendTo(a.find("p:last"))}else e.error(c+': element with class name "finish" missing!');d.titleClick?p.click(function(){var c=p.filter(".current-step").attr("id").split("-"),c=parseInt(c[c.length-1],10),b=e(this).index();if(b>c){if(d.next&&!f.execute.call(a,d.next,b))return!1}else if(b<c&&d.back&&!f.execute.call(a,d.back,b))return!1;b!=c&&f.step.call(a,b+1)}):p.css("cursor","default");g.delegate('input[type="text"], input[type="password"]',"keypress",function(a){if(13==(a.keyCode?
a.keyCode:a.which)&&(a.preventDefault(),a=e(this).parent().children("."+c+"-buttons"),a.length)){var b=a.children(".button-next");b.length?b.click():(a=a.children(".finish"),a.length&&a.click())}});g.first().find(":input:visible:enabled").first().select().focus()})},createBackButton:function(b){var d=this,a=this.attr("id"),c=this.data("options");e("<a/>",{id:a+"-back-"+b,href:"javascript:void(0);","class":"btn btn-link button-back",html:c.backLabel}).click(function(){c.back&&!f.execute.call(d,c.back,
b-1)||f.step.call(d,b-1+1)}).appendTo(e("#"+a+"-buttons-"+b))},createNextButton:function(b){var d=this,a=this.attr("id"),c=this.data("options");e("<a/>",{id:a+"-next-"+b,href:"javascript:void(0);","class":"btn btn-primary right",html:c.nextLabel}).click(function(){c.next&&!f.execute.call(d,c.next,b+1)||f.step.call(d,b+1+1)}).appendTo(e("#"+a+"-buttons-"+b))},execute:function(b,d){var a=b.call(this,d+1);return a||void 0===a},step:function(b){b--;var d=this.children("fieldset");b>d.length-1&&
(b=d.length-1);var a=this.data("options");max=b;if(a.validate)for(var c=!0,h=0;h<b;h++)if(c&=f.validate.call(this,h),a.block&&!c){max=h;break}d.hide().eq(max).show();e("#"+this.attr("id")+"-titles").children().removeClass("current-step").eq(max).addClass("current-step");this.is("form")&&(c=void 0,c=max==b?d.eq(max).find(":input:enabled:visible"):d.eq(max).find(".error").select().focus(),c.first().select().focus());a.select&&a.select.call(this,max+1);return this},validate:function(b){if(!this.is("form"))return!0;
var d=this.children("fieldset").eq(b),a=!0,c=e("#"+this.attr("id")+"-titles").children().eq(b),f=this.data("options"),g=this.validate();e(d.find(":input:enabled").get().reverse()).each(function(){var b=g.element(e(this));void 0===b&&(b=!0);(a&=b)?f.errorImage&&c.removeClass("error-image"):(f.errorImage&&c.addClass("error-image"),g.focusInvalid())});return a}};e.fn.stepy=function(b){if(f[b])return f[b].apply(this,Array.prototype.slice.call(arguments,1));if("object"!==typeof b&&b)e.error("Method "+
b+" does not exist!");else return f.init.apply(this,arguments)};e.fn.stepy.defaults={back:void 0,backLabel:"&lt; Back",block:!1,description:!0,errorImage:!1,finish:void 0,finishButton:!0,legend:!0,ignore:"",next:void 0,nextLabel:"Next &gt;",titleClick:!1,titleTarget:void 0,validate:!1,select:void 0}})(jQuery);