(function(a){a.fn.extend({slider:function(c){var b=Array.prototype.slice.call(arguments,1);if(c=="value"){return a.data(this[0],"ui-slider").value(arguments[1])}return this.each(function(){if(typeof c=="string"){var d=a.data(this,"ui-slider");d[c].apply(d,b)}else{if(!a.data(this,"ui-slider")){new a.ui.slider(this,c)}}})}});a.ui.slider=function(d,c){var b=this;this.element=a(d);a.data(d,"ui-slider",this);this.element.addClass("ui-slider");this.options=a.extend({},c);var e=this.options;a.extend(e,{axis:e.axis||(d.offsetWidth<d.offsetHeight?"vertical":"horizontal"),maxValue:!isNaN(parseInt(e.maxValue))?parseInt(e.maxValue):100,minValue:parseInt(e.minValue)||0,startValue:parseInt(e.startValue)||"none"});e.realMaxValue=e.maxValue-e.minValue;e.stepping=parseInt(e.stepping)||(e.steps?e.realMaxValue/e.steps:0);a(d).bind("setData.slider",function(g,f,h){b.options[f]=h}).bind("getData.slider",function(g,f){return b.options[f]});this.handle=e.handle?a(e.handle,d):a("> *",d);a(this.handle).mouseInteraction({executor:this,delay:e.delay,distance:e.distance||0,dragPrevention:e.prevention?e.prevention.toLowerCase().split(","):["input","textarea","button","select","option"],start:this.start,stop:this.stop,drag:this.drag,condition:function(g,f){if(!this.disabled){if(this.currentHandle){this.blur(this.currentHandle)}this.focus(f,1);return !this.disabled}}}).wrap('<a href="javascript:void(0)"></a>').parent().bind("focus",function(f){b.focus(this.firstChild)}).bind("blur",function(f){b.blur(this.firstChild)}).bind("keydown",function(f){if(/(37|39)/.test(f.keyCode)){b.moveTo((f.keyCode==37?"-":"+")+"="+(b.options.stepping?b.options.stepping:(b.options.realMaxValue/b.size)*5),this.firstChild)}});if(e.helper=="original"&&(this.element.css("position")=="static"||this.element.css("position")=="")){this.element.css("position","relative")}if(e.axis=="horizontal"){this.size=this.element.outerWidth();this.properties=["left","width"]}else{this.size=this.element.outerHeight();this.properties=["top","height"]}this.element.bind("click",function(f){b.click.apply(b,[f])});if(!isNaN(e.startValue)){this.moveTo(e.startValue,0)}if(this.handle.length==1){this.previousHandle=this.handle}if(this.handle.length==2&&e.range){this.createRange()}};a.extend(a.ui.slider.prototype,{plugins:{},createRange:function(){this.rangeElement=a("<div></div>").addClass("ui-slider-range").css({position:"absolute"}).css(this.properties[0],parseInt(a(this.handle[0]).css(this.properties[0]))+this.handleSize(0)/2).css(this.properties[1],parseInt(a(this.handle[1]).css(this.properties[0]))-parseInt(a(this.handle[0]).css(this.properties[0]))).appendTo(this.element)},updateRange:function(){this.rangeElement.css(this.properties[0],parseInt(a(this.handle[0]).css(this.properties[0]))+this.handleSize(0)/2);this.rangeElement.css(this.properties[1],parseInt(a(this.handle[1]).css(this.properties[0]))-parseInt(a(this.handle[0]).css(this.properties[0])))},getRange:function(){return this.rangeElement?this.convertValue(parseInt(this.rangeElement.css(this.properties[1]))):null},ui:function(b){return{instance:this,options:this.options,handle:this.currentHandle,value:this.value(),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("ul-slider").unbind(".slider");this.handles.removeMouseInteraction()},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(b){if(this.handle.length==1){this.currentHandle=this.handle}return((parseInt(a(b!=undefined?this.handle[b]||b:this.currentHandle).css(this.properties[0]))/(this.size-this.handleSize()))*this.options.realMaxValue)+this.options.minValue},convertValue:function(b){return(b/(this.size-this.handleSize()))*this.options.realMaxValue},translateValue:function(b){return((b-this.options.minValue)/this.options.realMaxValue)*(this.size-this.handleSize())},handleSize:function(b){return a(b!=undefined?this.handle[b]:this.currentHandle)["outer"+this.properties[1].substr(0,1).toUpperCase()+this.properties[1].substr(1)]()},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.previousHandle){this.focus(this.previousHandle,1)}this.offset=this.element.offset();this.moveTo(this.convertValue(c[this.properties[0]=="top"?"pageY":"pageX"]-this.offset[this.properties[0]]-this.handleSize()/2))},start:function(c,b){var d=this.options;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)}return false},drag:function(g,f){var h=this.options;var c={top:g.pageY-this.offset.top-this.clickOffset.top,left:g.pageX-this.offset.left-this.clickOffset.left};var b=c[this.properties[0]];if(b>=this.size-this.handleSize()){b=this.size-this.handleSize()}if(b<=0){b=0}if(h.stepping){var d=this.convertValue(b);d=Math.round(d/h.stepping)*h.stepping;b=this.translateValue(d)}if(this.rangeElement){if(this.currentHandle[0]==this.handle[0]&&b>=this.translateValue(this.value(1))){b=this.translateValue(this.value(1))}if(this.currentHandle[0]==this.handle[1]&&b<=this.translateValue(this.value(0))){b=this.translateValue(this.value(0))}}this.currentHandle.css(this.properties[0],b);if(this.rangeElement){this.updateRange()}this.propagate("slide",g);return false},moveTo:function(c,b){var d=this.options;if(b==undefined&&!this.currentHandle&&this.handle.length!=1){return false}if(b==undefined&&!this.currentHandle){b=0}if(b!=undefined){this.currentHandle=this.previousHandle=a(this.handle[b]||b)}if(c.constructor==String){c=/\-\=/.test(c)?this.value()-parseInt(c.replace("-=","")):this.value()+parseInt(c.replace("+=",""))}if(d.stepping){c=Math.round(c/d.stepping)*d.stepping}c=this.translateValue(c);if(c>=this.size-this.handleSize()){c=this.size-this.handleSize()}if(c<=0){c=0}if(this.rangeElement){if(this.currentHandle[0]==this.handle[0]&&c>=this.translateValue(this.value(1))){c=this.translateValue(this.value(1))}if(this.currentHandle[0]==this.handle[1]&&c<=this.translateValue(this.value(0))){c=this.translateValue(this.value(0))}}this.currentHandle.css(this.properties[0],c);if(this.rangeElement){this.updateRange()}this.propagate("start",null);this.propagate("stop",null);this.propagate("change",null)}})})(jQuery);
