(function(A){A.widget("ui.slider",{init:function(){var B=this;this.element.addClass("ui-slider");this.initBoundaries();this.handle=A(this.options.handle,this.element);if(!this.handle.length){B.handle=B.generated=A(B.options.handles||[0]).map(function(){var C=A("
").addClass("ui-slider-handle").appendTo(B.element);if(this.id){C.attr("id",this.id)}return C[0]})}A(this.handle).mouse({executor:this,delay:this.options.delay,distance:this.options.distance,dragPrevention:this.options.prevention?this.options.prevention.toLowerCase().split(","):["input","textarea","button","select","option"],start:this.start,stop:this.stop,drag:this.drag,condition:function(D,C){if(!this.disabled){if(this.currentHandle){this.blur(this.currentHandle)}this.focus(C,1);return !this.disabled}}}).wrap('').parent().bind("focus",function(C){B.focus(this.firstChild)}).bind("blur",function(C){B.blur(this.firstChild)}).bind("keydown",function(C){if(/(37|38|39|40)/.test(C.keyCode)){B.moveTo({x:/(37|39)/.test(C.keyCode)?(C.keyCode==37?"-":"+")+"="+B.oneStep(1):null,y:/(38|40)/.test(C.keyCode)?(C.keyCode==38?"-":"+")+"="+B.oneStep(2):null},this.firstChild)}});this.actualSize={width:this.element.outerWidth(),height:this.element.outerHeight()};this.element.bind("mousedown.slider",function(C){B.click.apply(B,[C]);B.currentHandle.data("mouse").trigger(C);B.firstValue=B.firstValue+1});A.each(this.options.handles||[],function(C,D){B.moveTo(D.start,C,true)});if(!isNaN(this.options.startValue)){this.moveTo(this.options.startValue,0,true)}this.previousHandle=A(this.handle[0]);if(this.handle.length==2&&this.options.range){this.createRange()}},setData:function(C,B,D){this.options[B]=D;if(/min|max|steps/.test(B)){this.initBoundaries()}},initBoundaries:function(){var B=this.element[0];var C=this.options;A.extend(C,{axis:C.axis||(B.offsetWidth").addClass("ui-slider-range").css({position:"absolute"}).appendTo(this.element);this.updateRange()},updateRange:function(){var C=this.options.axis=="vertical"?"top":"left";var B=this.options.axis=="vertical"?"height":"width";this.rangeElement.css(C,parseInt(A(this.handle[0]).css(C),10)+this.handleSize(0,this.options.axis=="vertical"?2:1)/2);this.rangeElement.css(B,parseInt(A(this.handle[1]).css(C),10)-parseInt(A(this.handle[0]).css(C),10))},getRange:function(){return this.rangeElement?this.convertValue(parseInt(this.rangeElement.css(this.options.axis=="vertical"?"height":"width"),10)):null},ui:function(B){return{instance:this,options:this.options,handle:this.currentHandle,value:this.options.axis!="both"||!this.options.axis?Math.round(this.value(null,this.options.axis=="vertical"?2:1)):{x:Math.round(this.value(null,1)),y:Math.round(this.value(null,2))},range:this.getRange()}},propagate:function(C,B){A.ui.plugin.call(this,C,[B,this.ui()]);this.element.triggerHandler(C=="slide"?C:"slide"+C,[B,this.ui()],this.options[C])},destroy:function(){this.element.removeClass("ui-slider ui-slider-disabled").removeData("slider").unbind(".slider");this.handle.mouse("destroy");this.generated&&this.generated.remove()},enable:function(){this.element.removeClass("ui-slider-disabled");this.disabled=false},disable:function(){this.element.addClass("ui-slider-disabled");this.disabled=true},focus:function(B,C){this.currentHandle=A(B).addClass("ui-slider-handle-active");if(C){this.currentHandle.parent()[0].focus()}},blur:function(B){A(B).removeClass("ui-slider-handle-active");if(this.currentHandle&&this.currentHandle[0]==B){this.previousHandle=this.currentHandle;this.currentHandle=null}},value:function(D,B){if(this.handle.length==1){this.currentHandle=this.handle}if(!B){B=this.options.axis=="vertical"?2:1}var C=((parseInt(A(D!=undefined&&D!==null?this.handle[D]||D:this.currentHandle).css(B==1?"left":"top"),10)/(this.actualSize[B==1?"width":"height"]-this.handleSize(D,B)))*this.options.realMax[B==1?"x":"y"])+this.options.min[B==1?"x":"y"];var E=this.options;if(E.stepping[B==1?"x":"y"]){C=Math.round(C/E.stepping[B==1?"x":"y"])*E.stepping[B==1?"x":"y"]}return C},convertValue:function(C,B){if(!B){B=this.options.axis=="vertical"?2:1}return this.options.min[B==1?"x":"y"]+(C/(this.actualSize[B==1?"width":"height"]-this.handleSize(null,B)))*this.options.realMax[B==1?"x":"y"]},translateValue:function(C,B){if(!B){B=this.options.axis=="vertical"?2:1}return((C-this.options.min[B==1?"x":"y"])/this.options.realMax[B==1?"x":"y"])*(this.actualSize[B==1?"width":"height"]-this.handleSize(null,B))},handleSize:function(C,B){if(!B){B=this.options.axis=="vertical"?2:1}return A(C!=undefined&&C!==null?this.handle[C]:this.currentHandle)[0][B==1?"offsetWidth":"offsetHeight"]},click:function(C){var D=[C.pageX,C.pageY];var B=false;this.handle.each(function(){if(this==C.target){B=true}});if(B||this.disabled||!(this.currentHandle||this.previousHandle)){return }if(!this.currentHandle&&this.previousHandle){this.focus(this.previousHandle,true)}this.offset=this.element.offset();this.moveTo({y:this.convertValue(C.pageY-this.offset.top-this.currentHandle.outerHeight()/2),x:this.convertValue(C.pageX-this.offset.left-this.currentHandle.outerWidth()/2)},null,!this.options.distance)},start:function(C,B){var D=this.options;if(!this.currentHandle){this.focus(this.previousHandle,true)}this.offset=this.element.offset();this.handleOffset=this.currentHandle.offset();this.clickOffset={top:C.pageY-this.handleOffset.top,left:C.pageX-this.handleOffset.left};this.firstValue=this.value();this.propagate("start",C);return false},stop:function(B){this.propagate("stop",B);if(this.firstValue!=this.value()){this.propagate("change",B)}this.focus(this.currentHandle,true);return false},oneStep:function(B){if(!B){B=this.options.axis=="vertical"?2:1}return this.options.stepping[B==1?"x":"y"]?this.options.stepping[B==1?"x":"y"]:(this.options.realMax[B==1?"x":"y"]/this.actualSize[B==1?"width":"height"])*5},translateRange:function(D,B){if(this.rangeElement){if(this.currentHandle[0]==this.handle[0]&&D>=this.translateValue(this.value(1),B)){D=this.translateValue(this.value(1,B)-this.oneStep(B),B)}if(this.currentHandle[0]==this.handle[1]&&D<=this.translateValue(this.value(0),B)){D=this.translateValue(this.value(0,B)+this.oneStep(B))}}if(this.options.handles){var C=this.options.handles[this.handleIndex()];if(Dthis.translateValue(C.max,B)){D=this.translateValue(C.max,B)}}}return D},handleIndex:function(){return this.handle.index(this.currentHandle[0])},translateLimits:function(C,B){if(!B){B=this.options.axis=="vertical"?2:1}if(C>=this.actualSize[B==1?"width":"height"]-this.handleSize(null,B)){C=this.actualSize[B==1?"width":"height"]-this.handleSize(null,B)}if(C<=0){C=0}return C},drag:function(E,D){var F=this.options;var B={top:E.pageY-this.offset.top-this.clickOffset.top,left:E.pageX-this.offset.left-this.clickOffset.left};if(!this.currentHandle){this.focus(this.previousHandle,true)}B.left=this.translateLimits(B.left,1);B.top=this.translateLimits(B.top,2);if(F.stepping.x){var C=this.convertValue(B.left,1);C=Math.round(C/F.stepping.x)*F.stepping.x;B.left=this.translateValue(C,1)}if(F.stepping.y){var C=this.convertValue(B.top,2);C=Math.round(C/F.stepping.y)*F.stepping.y;B.top=this.translateValue(C,2)}B.left=this.translateRange(B.left,1);B.top=this.translateRange(B.top,2);if(F.axis!="vertical"){this.currentHandle.css({left:B.left})}if(F.axis!="horizontal"){this.currentHandle.css({top:B.top})}if(this.rangeElement){this.updateRange()}this.propagate("slide",E);return false},moveTo:function(F,E,G){var H=this.options;if(E==undefined&&!this.currentHandle&&this.handle.length!=1){return false}if(E==undefined&&!this.currentHandle){E=0}if(E!=undefined){this.currentHandle=this.previousHandle=A(this.handle[E]||E)}if(F.x!==undefined&&F.y!==undefined){var B=F.x;var I=F.y}else{var B=F,I=F}if(B&&B.constructor!=Number){var D=/^\-\=/.test(B),C=/^\+\=/.test(B);if(D){B=this.value(null,1)-parseInt(B.replace("-=",""),10)}else{if(C){B=this.value(null,1)+parseInt(B.replace("+=",""),10)}}}if(I&&I.constructor!=Number){var D=/^\-\=/.test(I),C=/^\+\=/.test(I);if(D){I=this.value(null,2)-parseInt(I.replace("-=",""),10)}else{if(C){I=this.value(null,2)+parseInt(I.replace("+=",""),10)}}}if(H.axis!="vertical"&&B){if(H.stepping.x){B=Math.round(B/H.stepping.x)*H.stepping.x}B=this.translateValue(B,1);B=this.translateLimits(B,1);B=this.translateRange(B,1);this.currentHandle.css({left:B})}if(H.axis!="horizontal"&&I){if(H.stepping.y){I=Math.round(I/H.stepping.y)*H.stepping.y}I=this.translateValue(I,2);I=this.translateLimits(I,2);I=this.translateRange(I,2);this.currentHandle.css({top:I})}if(this.rangeElement){this.updateRange()}if(!G){this.propagate("start",null);this.propagate("stop",null);this.propagate("change",null);this.propagate("slide",null)}}});A.ui.slider.getter="value";A.ui.slider.defaults={handle:".ui-slider-handle",distance:1}})(jQuery);