(function(a,b){a.widget("ui.rangeSlider",{options:{bounds:{min:0,max:100},defaultValues:{min:20,max:50},wheelMode:null,wheelSpeed:4,arrows:true,valueLabels:"show",formatter:null,durationIn:0,durationOut:400,delayOut:200,range:{min:false,max:false},step:false,scales:false},_values:null,_valuesChanged:false,bar:null,leftHandle:null,rightHandle:null,innerBar:null,container:null,arrows:null,labels:null,changing:{min:false,max:false},changed:{min:false,max:false},ruler:null,_create:function(){this._setDefaultValues();this.labels={left:null,right:null,leftDisplayed:true,rightDisplayed:true};this.arrows={left:null,right:null};this.changing={min:false,max:false};this.changed={min:false,max:false};this._createElements();this._bindResize();setTimeout(a.proxy(this.resize,this),1);setTimeout(a.proxy(this._initValues,this),1)},_setDefaultValues:function(){this._values={min:this.options.defaultValues.min,max:this.options.defaultValues.max}},_bindResize:function(){var c=this;this._resizeProxy=function(d){c.resize(d)};a(window).resize(this._resizeProxy)},_initWidth:function(){this.container.css("width",this.element.width()-this.container.outerWidth(true)+this.container.width());this.innerBar.css("width",this.container.width()-this.innerBar.outerWidth(true)+this.innerBar.width())},_initValues:function(){this.values(this._values.min,this._values.max)},_setOption:function(c,d){this._setWheelOption(c,d);this._setArrowsOption(c,d);this._setLabelsOption(c,d);this._setLabelsDurations(c,d);this._setFormatterOption(c,d);this._setBoundsOption(c,d);this._setRangeOption(c,d);this._setStepOption(c,d);this._setScalesOption(c,d)},_validProperty:function(e,d,c){if(e===null||typeof e[d]==="undefined"){return c}return e[d]},_setStepOption:function(c,d){if(c==="step"){this.options.step=d;this._leftHandle("option","step",d);this._rightHandle("option","step",d);this._changed(true)}},_setScalesOption:function(c,d){if(c==="scales"){if(d===false||d===null){this.options.scales=false;this._destroyRuler()}else{if(d instanceof Array){this.options.scales=d;this._updateRuler()}}}},_setRangeOption:function(c,d){if(c==="range"){this._bar("option","range",d);this.options.range=this._bar("option","range");this._changed(true)}},_setBoundsOption:function(c,d){if(c==="bounds"&&typeof d.min!=="undefined"&&typeof d.max!=="undefined"){this.bounds(d.min,d.max)}},_setWheelOption:function(c,d){if(c==="wheelMode"||c==="wheelSpeed"){this._bar("option",c,d);this.options[c]=this._bar("option",c)}},_setLabelsOption:function(c,d){if(c==="valueLabels"){if(d!=="hide"&&d!=="show"&&d!=="change"){return}this.options.valueLabels=d;if(d!=="hide"){this._createLabels();this._leftLabel("update");this._rightLabel("update")}else{this._destroyLabels()}}},_setFormatterOption:function(c,d){if(c==="formatter"&&d!==null&&typeof d==="function"){this.options.formatter=d;if(this.options.valueLabels!=="hide"){this._destroyLabels();this._createLabels()}}},_setArrowsOption:function(c,d){if(c==="arrows"&&(d===true||d===false)&&d!==this.options.arrows){if(d===true){this.element.removeClass("ui-rangeSlider-noArrow").addClass("ui-rangeSlider-withArrows");this.arrows.left.css("display","block");this.arrows.right.css("display","block");this.options.arrows=true}else{if(d===false){this.element.addClass("ui-rangeSlider-noArrow").removeClass("ui-rangeSlider-withArrows");this.arrows.left.css("display","none");this.arrows.right.css("display","none");this.options.arrows=false}}this._initWidth()}},_setLabelsDurations:function(c,d){if(c==="durationIn"||c==="durationOut"||c==="delayOut"){if(parseInt(d,10)!==d){return}if(this.labels.left!==null){this._leftLabel("option",c,d)}if(this.labels.right!==null){this._rightLabel("option",c,d)}this.options[c]=d}},_createElements:function(){if(this.element.css("position")!=="absolute"){this.element.css("position","relative")}this.element.addClass("ui-rangeSlider");this.container=a("
").css("position","absolute").appendTo(this.element);this.innerBar=a("").css("position","absolute").css("top",0).css("left",0);this._createHandles();this._createBar();this.container.prepend(this.innerBar);this._createArrows();if(this.options.valueLabels!=="hide"){this._createLabels()}else{this._destroyLabels()}this._updateRuler()},_createHandle:function(c){return a("")[this._handleType()](c).bind("sliderDrag",a.proxy(this._changing,this)).bind("stop",a.proxy(this._changed,this))},_createHandles:function(){this.leftHandle=this._createHandle({isLeft:true,bounds:this.options.bounds,value:this._values.min,step:this.options.step}).appendTo(this.container);this.rightHandle=this._createHandle({isLeft:false,bounds:this.options.bounds,value:this._values.max,step:this.options.step}).appendTo(this.container)},_createBar:function(){this.bar=a("").prependTo(this.container).bind("sliderDrag scroll zoom",a.proxy(this._changing,this)).bind("stop",a.proxy(this._changed,this));this._bar({leftHandle:this.leftHandle,rightHandle:this.rightHandle,values:{min:this._values.min,max:this._values.max},type:this._handleType(),range:this.options.range,wheelMode:this.options.wheelMode,wheelSpeed:this.options.wheelSpeed});this.options.range=this._bar("option","range");this.options.wheelMode=this._bar("option","wheelMode");this.options.wheelSpeed=this._bar("option","wheelSpeed")},_createArrows:function(){this.arrows.left=this._createArrow("left");this.arrows.right=this._createArrow("right");if(!this.options.arrows){this.arrows.left.css("display","none");this.arrows.right.css("display","none");this.element.addClass("ui-rangeSlider-noArrow")}else{this.element.addClass("ui-rangeSlider-withArrows")}},_createArrow:function(c){var d=a("").append("").addClass("ui-rangeSlider-"+c+"Arrow").css("position","absolute").css(c,0).appendTo(this.element),e;if(c==="right"){e=a.proxy(this._scrollRightClick,this)}else{e=a.proxy(this._scrollLeftClick,this)}d.bind("mousedown touchstart",e);return d},_proxy:function(d,e,c){var f=Array.prototype.slice.call(c);return d[e].apply(d,f)},_handleType:function(){return"rangeSliderHandle"},_barType:function(){return"rangeSliderBar"},_bar:function(){return this._proxy(this.bar,this._barType(),arguments)},_labelType:function(){return"rangeSliderLabel"},_leftLabel:function(){return this._proxy(this.labels.left,this._labelType(),arguments)},_rightLabel:function(){return this._proxy(this.labels.right,this._labelType(),arguments)},_leftHandle:function(){return this._proxy(this.leftHandle,this._handleType(),arguments)},_rightHandle:function(){return this._proxy(this.rightHandle,this._handleType(),arguments)},_getValue:function(c,d){if(d===this.rightHandle){c=c-d.outerWidth()}return c*(this.options.bounds.max-this.options.bounds.min)/(this.container.innerWidth()-d.outerWidth(true))+this.options.bounds.min},_trigger:function(c){var d=this;setTimeout(function(){d.element.trigger(c,{label:d.element,values:d.values()})},1)},_changing:function(){if(this._updateValues()){this._trigger("valuesChanging");this._valuesChanged=true}},_changed:function(c){if(this._updateValues()||this._valuesChanged){this._trigger("valuesChanged");if(c!==true){this._trigger("userValuesChanged")}this._valuesChanged=false}},_updateValues:function(){var f=this._leftHandle("value"),e=this._rightHandle("value"),d=this._min(f,e),c=this._max(f,e),g=(d!==this._values.min||c!==this._values.max);this._values.min=this._min(f,e);this._values.max=this._max(f,e);return g},_min:function(d,c){return Math.min(d,c)},_max:function(d,c){return Math.max(d,c)},_createLabel:function(c,d){var e;if(c===null){e=this._getLabelConstructorParameters(c,d);c=a("").appendTo(this.element)[this._labelType()](e)}else{e=this._getLabelRefreshParameters(c,d);c[this._labelType()](e)}return c},_getLabelConstructorParameters:function(c,d){return{handle:d,handleType:this._handleType(),formatter:this._getFormatter(),show:this.options.valueLabels,durationIn:this.options.durationIn,durationOut:this.options.durationOut,delayOut:this.options.delayOut}},_getLabelRefreshParameters:function(){return{formatter:this._getFormatter(),show:this.options.valueLabels,durationIn:this.options.durationIn,durationOut:this.options.durationOut,delayOut:this.options.delayOut}},_getFormatter:function(){if(this.options.formatter===false||this.options.formatter===null){return this._defaultFormatter}return this.options.formatter},_defaultFormatter:function(c){return Math.round(c)},_destroyLabel:function(c){if(c!==null){c.remove();c=null}return c},_createLabels:function(){this.labels.left=this._createLabel(this.labels.left,this.leftHandle);this.labels.right=this._createLabel(this.labels.right,this.rightHandle);this._leftLabel("pair",this.labels.right)},_destroyLabels:function(){this.labels.left=this._destroyLabel(this.labels.left);this.labels.right=this._destroyLabel(this.labels.right)},_stepRatio:function(){return this._leftHandle("stepRatio")},_scrollRightClick:function(c){c.preventDefault();this._bar("startScroll");this._bindStopScroll();this._continueScrolling("scrollRight",4*this._stepRatio(),1)},_continueScrolling:function(h,g,i,d){this._bar(h,i);d=d||5;d--;var f=this,c=16,e=Math.max(1,4/this._stepRatio());this._scrollTimeout=setTimeout(function(){if(d===0){if(g>c){g=Math.max(c,g/1.5)}else{i=Math.min(e,i*2)}d=5}f._continueScrolling(h,g,i,d)},g)},_scrollLeftClick:function(c){c.preventDefault();this._bar("startScroll");this._bindStopScroll();this._continueScrolling("scrollLeft",4*this._stepRatio(),1)},_bindStopScroll:function(){var c=this;this._stopScrollHandle=function(d){d.preventDefault();c._stopScroll()};a(document).bind("mouseup touchend",this._stopScrollHandle)},_stopScroll:function(){a(document).unbind("mouseup touchend",this._stopScrollHandle);this._bar("stopScroll");clearTimeout(this._scrollTimeout)},_createRuler:function(){this.ruler=a("").appendTo(this.innerBar)},_setRulerParameters:function(){this.ruler.ruler({min:this.options.bounds.min,max:this.options.bounds.max,scales:this.options.scales})},_destroyRuler:function(){if(this.ruler!==null&&a.fn.ruler){this.ruler.ruler("destroy");this.ruler.remove();this.ruler=null}},_updateRuler:function(){this._destroyRuler();if(this.options.scales===false||!a.fn.ruler){return}this._createRuler();this._setRulerParameters()},values:function(d,c){var e=this._bar("values",d,c);if(typeof d!=="undefined"&&typeof c!=="undefined"){this._changed(true)}return e},min:function(c){this._values.min=this.values(c,this._values.max).min;return this._values.min},max:function(c){this._values.max=this.values(this._values.min,c).max;return this._values.max},bounds:function(d,c){if(this._isValidValue(d)&&this._isValidValue(c)&&d