(function(A){A.fn.unwrap=A.fn.unwrap||function(B){return this.each(function(){A(this).parents(B).eq(0).after(this).remove()
})
};
A.widget("ui.slider",{plugins:{},ui:function(B){return{options:this.options,handle:this.currentHandle,value:this.options.axis!="both"||!this.options.axis?Math.round(this.value(null,this.options.axis=="vertical"?"y":"x")):{x:Math.round(this.value(null,"x")),y:Math.round(this.value(null,"y"))},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");
if(this.handle&&this.handle.length){this.handle.unwrap("a");
this.handle.each(function(){A(this).data("mouse")._mouseDestroy()
})
}this.generated&&this.generated.remove()
},_setData:function(B,C){A.widget.prototype._setData.apply(this,arguments);
if(/min|max|steps/.test(B)){this._initBoundaries()
}if(B=="range"){C?this.handle.length==2&&this._createRange():this._removeRange()
}},_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 D=A("<div/>").addClass("ui-slider-handle").appendTo(B.element);
if(this.id){D.attr("id",this.id)
}return D[0]
})
}var C=function(D){this.element=A(D);
this.element.data("mouse",this);
this.options=B.options;
this.element.bind("mousedown",function(){if(B.currentHandle){this.blur(B.currentHandle)
}B._focus(this,true)
});
this._mouseInit()
};
A.extend(C.prototype,A.ui.mouse,{_mouseStart:function(D){return B._start.call(B,D,this.element[0])
},_mouseStop:function(D){return B._stop.call(B,D,this.element[0])
},_mouseDrag:function(D){return B._drag.call(B,D,this.element[0])
},_mouseCapture:function(){return true
},trigger:function(D){this._mouseDown(D)
}});
A(this.handle).each(function(){new C(this)
}).wrap('<a href="javascript:void(0)" style="outline:none;border:none;"></a>').parent().bind("focus",function(D){B._focus(this.firstChild)
}).bind("blur",function(D){B._blur(this.firstChild)
}).bind("keydown",function(D){if(!B.options.noKeyboard){B._keydown(D.keyCode,this.firstChild)
}});
this.element.bind("mousedown.slider",function(D){B._click.apply(B,[D]);
B.currentHandle.data("mouse").trigger(D);
B.firstValue=B.firstValue+1
});
A.each(this.options.handles||[],function(D,E){B.moveTo(E.start,D,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()
}},_initBoundaries:function(){var B=this.element[0],C=this.options;
this.actualSize={width:this.element.outerWidth(),height:this.element.outerHeight()};
A.extend(C,{axis:C.axis||(B.offsetWidth<B.offsetHeight?"vertical":"horizontal"),max:!isNaN(parseInt(C.max,10))?{x:parseInt(C.max,10),y:parseInt(C.max,10)}:({x:C.max&&C.max.x||100,y:C.max&&C.max.y||100}),min:!isNaN(parseInt(C.min,10))?{x:parseInt(C.min,10),y:parseInt(C.min,10)}:({x:C.min&&C.min.x||0,y:C.min&&C.min.y||0})});
C.realMax={x:C.max.x-C.min.x,y:C.max.y-C.min.y};
C.stepping={x:C.stepping&&C.stepping.x||parseInt(C.stepping,10)||(C.steps?C.realMax.x/(C.steps.x||parseInt(C.steps,10)||C.realMax.x):0),y:C.stepping&&C.stepping.y||parseInt(C.stepping,10)||(C.steps?C.realMax.y/(C.steps.y||parseInt(C.steps,10)||C.realMax.y):0)}
},_keydown:function(F,E){var C=F;
if(/(33|34|35|36|37|38|39|40)/.test(C)){var G=this.options,B,I;
if(/(35|36)/.test(C)){B=(C==35)?G.max.x:G.min.x;
I=(C==35)?G.max.y:G.min.y
}else{var H=/(34|37|40)/.test(C)?"-=":"+=";
var D=/(37|38|39|40)/.test(C)?"_oneStep":"_pageStep";
B=H+this[D]("x");
I=H+this[D]("y")
}this.moveTo({x:B,y:I},E)
}},_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
}},_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.options.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[0].offsetHeight/2,"y"),x:this._convertValue(C.pageX-this.offset.left-this.currentHandle[0].offsetWidth/2,"x")},null,!this.options.distance)
},_createRange:function(){if(this.rangeElement){return 
}this.rangeElement=A("<div></div>").addClass("ui-slider-range").css({position:"absolute"}).appendTo(this.element);
this._updateRange()
},_removeRange:function(){this.rangeElement.remove();
this.rangeElement=null
},_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)||0)+this._handleSize(0,this.options.axis=="vertical"?"y":"x")/2);
this.rangeElement.css(B,(parseInt(A(this.handle[1]).css(C),10)||0)-(parseInt(A(this.handle[0]).css(C),10)||0))
},_getRange:function(){return this.rangeElement?this._convertValue(parseInt(this.rangeElement.css(this.options.axis=="vertical"?"height":"width"),10),this.options.axis=="vertical"?"y":"x"):null
},_handleIndex:function(){return this.handle.index(this.currentHandle[0])
},value:function(D,B){if(this.handle.length==1){this.currentHandle=this.handle
}if(!B){B=this.options.axis=="vertical"?"y":"x"
}var C=A(D!=undefined&&D!==null?this.handle[D]||D:this.currentHandle);
if(C.data("mouse").sliderValue){return parseInt(C.data("mouse").sliderValue[B],10)
}else{return parseInt(((parseInt(C.css(B=="x"?"left":"top"),10)/(this.actualSize[B=="x"?"width":"height"]-this._handleSize(D,B)))*this.options.realMax[B])+this.options.min[B],10)
}},_convertValue:function(C,B){return this.options.min[B]+(C/(this.actualSize[B=="x"?"width":"height"]-this._handleSize(null,B)))*this.options.realMax[B]
},_translateValue:function(C,B){return((C-this.options.min[B])/this.options.realMax[B])*(this.actualSize[B=="x"?"width":"height"]-this._handleSize(null,B))
},_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),B)
}}if(this.options.handles){var C=this.options.handles[this._handleIndex()];
if(D<this._translateValue(C.min,B)){D=this._translateValue(C.min,B)
}else{if(D>this._translateValue(C.max,B)){D=this._translateValue(C.max,B)
}}}return D
},_translateLimits:function(C,B){if(C>=this.actualSize[B=="x"?"width":"height"]-this._handleSize(null,B)){C=this.actualSize[B=="x"?"width":"height"]-this._handleSize(null,B)
}if(C<=0){C=0
}return C
},_handleSize:function(C,B){return A(C!=undefined&&C!==null?this.handle[C]:this.currentHandle)[0]["offset"+(B=="x"?"Width":"Height")]
},_oneStep:function(B){return this.options.stepping[B]||1
},_pageStep:function(B){return 10
},_start:function(C,B){var D=this.options;
if(D.disabled){return false
}this.actualSize={width:this.element.outerWidth(),height:this.element.outerHeight()};
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);
this._drag(C,B);
return true
},_stop:function(B){this._propagate("stop",B);
if(this.firstValue!=this.value()){this._propagate("change",B)
}this._focus(this.currentHandle,true);
return false
},_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,"x");
B.top=this._translateLimits(B.top,"y");
if(F.stepping.x){var C=this._convertValue(B.left,"x");
C=Math.round(C/F.stepping.x)*F.stepping.x;
B.left=this._translateValue(C,"x")
}if(F.stepping.y){var C=this._convertValue(B.top,"y");
C=Math.round(C/F.stepping.y)*F.stepping.y;
B.top=this._translateValue(C,"y")
}B.left=this._translateRange(B.left,"x");
B.top=this._translateRange(B.top,"y");
if(F.axis!="vertical"){this.currentHandle.css({left:B.left})
}if(F.axis!="horizontal"){this.currentHandle.css({top:B.top})
}this.currentHandle.data("mouse").sliderValue={x:Math.round(this._convertValue(B.left,"x"))||0,y:Math.round(this._convertValue(B.top,"y"))||0};
if(this.rangeElement){this._updateRange()
}this._propagate("slide",E);
return false
},moveTo:function(F,E,G){var H=this.options;
this.actualSize={width:this.element.outerWidth(),height:this.element.outerHeight()};
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,I=F.y
}else{var B=F,I=F
}if(B!==undefined&&B.constructor!=Number){var D=/^\-\=/.test(B),C=/^\+\=/.test(B);
if(D||C){B=this.value(null,"x")+parseInt(B.replace(D?"=":"+=",""),10)
}else{B=isNaN(parseInt(B,10))?undefined:parseInt(B,10)
}}if(I!==undefined&&I.constructor!=Number){var D=/^\-\=/.test(I),C=/^\+\=/.test(I);
if(D||C){I=this.value(null,"y")+parseInt(I.replace(D?"=":"+=",""),10)
}else{I=isNaN(parseInt(I,10))?undefined:parseInt(I,10)
}}if(H.axis!="vertical"&&B!==undefined){if(H.stepping.x){B=Math.round(B/H.stepping.x)*H.stepping.x
}B=this._translateValue(B,"x");
B=this._translateLimits(B,"x");
B=this._translateRange(B,"x");
H.animate?this.currentHandle.stop().animate({left:B},(Math.abs(parseInt(this.currentHandle.css("left"))-B))*(!isNaN(parseInt(H.animate))?H.animate:5)):this.currentHandle.css({left:B})
}if(H.axis!="horizontal"&&I!==undefined){if(H.stepping.y){I=Math.round(I/H.stepping.y)*H.stepping.y
}I=this._translateValue(I,"y");
I=this._translateLimits(I,"y");
I=this._translateRange(I,"y");
H.animate?this.currentHandle.stop().animate({top:I},(Math.abs(parseInt(this.currentHandle.css("top"))-I))*(!isNaN(parseInt(H.animate))?H.animate:5)):this.currentHandle.css({top:I})
}if(this.rangeElement){this._updateRange()
}this.currentHandle.data("mouse").sliderValue={x:Math.round(this._convertValue(B,"x"))||0,y:Math.round(this._convertValue(I,"y"))||0};
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,animate:false}
})(jQuery);
