(function(i){function h(a){var b=i('<span class="spinner"><span class="spinner-arrow"><span class="spinner-arrow-up"></span><span class="spinner-arrow-down"></span></span></span>').insertAfter(a);i(a).addClass("spinner-text").prependTo(b);return b}function j(a,b){var c=i.data(a,"spinner").options;var d=i.data(a,"spinner").spinner;if(b){c.width=b}var e=i('<div style="display:none"></div>').insertBefore(d);d.appendTo("body");if(isNaN(c.width)){c.width=i(a).outerWidth()}d._outerWidth(c.width);i(a)._outerWidth(d.width()-d.find(".spinner-arrow").outerWidth());d.insertAfter(e);e.remove()}function f(a){var b=i.data(a,"spinner").options;var c=i.data(a,"spinner").spinner;c.find(".spinner-arrow-up,.spinner-arrow-down").unbind(".spinner");if(!b.disabled){c.find(".spinner-arrow-up").bind("mouseenter.spinner",function(){i(this).addClass("spinner-arrow-hover")}).bind("mouseleave.spinner",function(){i(this).removeClass("spinner-arrow-hover")}).bind("click.spinner",function(){b.spin.call(a,false);b.onSpinUp.call(a);i(a).validatebox("validate")});c.find(".spinner-arrow-down").bind("mouseenter.spinner",function(){i(this).addClass("spinner-arrow-hover")}).bind("mouseleave.spinner",function(){i(this).removeClass("spinner-arrow-hover")}).bind("click.spinner",function(){b.spin.call(a,true);b.onSpinDown.call(a);i(a).validatebox("validate")})}}function g(a,b){var c=i.data(a,"spinner").options;if(b){c.disabled=true;i(a).attr("disabled",true)}else{c.disabled=false;i(a).removeAttr("disabled")}}i.fn.spinner=function(a,b){if(typeof a=="string"){var c=i.fn.spinner.methods[a];if(c){return c(this,b)}else{return this.validatebox(a,b)}}a=a||{};return this.each(function(){var d=i.data(this,"spinner");if(d){i.extend(d.options,a)}else{d=i.data(this,"spinner",{options:i.extend({},i.fn.spinner.defaults,i.fn.spinner.parseOptions(this),a),spinner:h(this)});i(this).removeAttr("disabled")}i(this).val(d.options.value);i(this).attr("readonly",!d.options.editable);g(this,d.options.disabled);j(this);i(this).validatebox(d.options);f(this)})};i.fn._outerWidth=function(a){return this.each(function(){if(!i.boxModel&&i.browser.msie){i(this).width(a)}else{i(this).width(a-(i(this).outerWidth()-i(this).width()))}})};i.fn.spinner.methods={options:function(a){var b=i.data(a[0],"spinner").options;return i.extend(b,{value:a.val()})},destroy:function(a){return a.each(function(){var b=i.data(this,"spinner").spinner;i(this).validatebox("destroy");b.remove()})},resize:function(a,b){return a.each(function(){j(this,b)})},enable:function(a){return a.each(function(){g(this,false);f(this)})},disable:function(a){return a.each(function(){g(this,true);f(this)})},getValue:function(a){return a.val()},setValue:function(a,b){return a.each(function(){var c=i.data(this,"spinner").options;c.value=b;i(this).val(b)})},clear:function(a){return a.each(function(){var b=i.data(this,"spinner").options;b.value="";i(this).val("")})}};i.fn.spinner.parseOptions=function(b){var a=i(b);return i.extend({},i.fn.validatebox.parseOptions(b),{width:(parseInt(b.style.width)||undefined),value:(a.val()||undefined),min:a.attr("min"),max:a.attr("max"),increment:(parseFloat(a.attr("increment"))||undefined),editable:(a.attr("editable")?a.attr("editable")=="true":undefined),disabled:(a.attr("disabled")?true:undefined)})};i.fn.spinner.defaults=i.extend({},i.fn.validatebox.defaults,{width:"auto",value:"",min:null,max:null,increment:1,editable:true,disabled:false,spin:function(a){},onSpinUp:function(){},onSpinDown:function(){}})})(jQuery);