/*
 * jQuery UI Slider 1.8.1
 *
 * Copyright (c) 2010 AUTHORS.txt (http://jqueryui.com/about)
 * Dual licensed under the MIT (MIT-LICENSE.txt)
 * and GPL (GPL-LICENSE.txt) licenses.
 *
 * http://docs.jquery.com/UI/Slider
 *
 * Depends:
 *	jquery.ui.core.js
 *	jquery.ui.mouse.js
 *	jquery.ui.widget.js
 */

(function(d){d.widget("ui.slider",d.ui.mouse,{widgetEventPrefix:"slide",options:{animate:!1,distance:0,max:100,min:0,orientation:"horizontal",range:!1,step:1,value:0,values:null},_create:function(){var b=this,a=this.options;this._mouseSliding=this._keySliding=!1;this._animateOff=!0;this._handleIndex=null;this._detectOrientation();this._mouseInit();this.element.addClass("ui-slider ui-slider-"+this.orientation+" ui-widget ui-widget-content ui-corner-all");a.disabled&&this.element.addClass("ui-slider-disabled ui-disabled");
this.range=d([]);if(a.range){if(a.range===!0){this.range=d("<div></div>");if(!a.values)a.values=[this._valueMin(),this._valueMin()];if(a.values.length&&a.values.length!==2)a.values=[a.values[0],a.values[0]]}else this.range=d("<div></div>");this.range.appendTo(this.element).addClass("ui-slider-range");(a.range==="min"||a.range==="max")&&this.range.addClass("ui-slider-range-"+a.range);this.range.addClass("ui-widget-header")}d(".ui-slider-handle",this.element).length===0&&d("<a href='#'></a>").appendTo(this.element).addClass("ui-slider-handle");
if(a.values&&a.values.length)for(;d(".ui-slider-handle",this.element).length<a.values.length;)d("<a href='#'></a>").appendTo(this.element).addClass("ui-slider-handle");this.handles=d(".ui-slider-handle",this.element).addClass("ui-state-default ui-corner-all");this.handle=this.handles.eq(0);this.handles.add(this.range).filter("a").click(function(a){a.preventDefault()}).hover(function(){a.disabled||d(this).addClass("ui-state-hover")},function(){d(this).removeClass("ui-state-hover")}).focus(function(){a.disabled?
d(this).blur():(d(".ui-slider .ui-state-focus").removeClass("ui-state-focus"),d(this).addClass("ui-state-focus"))}).blur(function(){d(this).removeClass("ui-state-focus")});this.handles.each(function(a){d(this).data("index.ui-slider-handle",a)});this.handles.keydown(function(a){var f=!0,e=d(this).data("index.ui-slider-handle"),g,h,i;if(!b.options.disabled){switch(a.keyCode){case d.ui.keyCode.HOME:case d.ui.keyCode.END:case d.ui.keyCode.PAGE_UP:case d.ui.keyCode.PAGE_DOWN:case d.ui.keyCode.UP:case d.ui.keyCode.RIGHT:case d.ui.keyCode.DOWN:case d.ui.keyCode.LEFT:if(f=
!1,!b._keySliding&&(b._keySliding=!0,d(this).addClass("ui-state-active"),g=b._start(a,e),g===!1))return}i=b.options.step;g=b.options.values&&b.options.values.length?h=b.values(e):h=b.value();switch(a.keyCode){case d.ui.keyCode.HOME:h=b._valueMin();break;case d.ui.keyCode.END:h=b._valueMax();break;case d.ui.keyCode.PAGE_UP:h=g+(b._valueMax()-b._valueMin())/5;break;case d.ui.keyCode.PAGE_DOWN:h=g-(b._valueMax()-b._valueMin())/5;break;case d.ui.keyCode.UP:case d.ui.keyCode.RIGHT:if(g===b._valueMax())return;
h=g+i;break;case d.ui.keyCode.DOWN:case d.ui.keyCode.LEFT:if(g===b._valueMin())return;h=g-i}b._slide(a,e,h);return f}}).keyup(function(a){var f=d(this).data("index.ui-slider-handle");if(b._keySliding)b._keySliding=!1,b._stop(a,f),b._change(a,f),d(this).removeClass("ui-state-active")});this._refreshValue();this._animateOff=!1},destroy:function(){this.handles.remove();this.range.remove();this.element.removeClass("ui-slider ui-slider-horizontal ui-slider-vertical ui-slider-disabled ui-widget ui-widget-content ui-corner-all").removeData("slider").unbind(".slider");
this._mouseDestroy();return this},_mouseCapture:function(b){var a=this.options,c,f,e,g,h,i;if(a.disabled)return!1;this.elementSize={width:this.element.outerWidth(),height:this.element.outerHeight()};this.elementOffset=this.element.offset();c={x:b.pageX,y:b.pageY};f=this._normValueFromMouse(c);e=this._valueMax()-this._valueMin()+1;h=this;this.handles.each(function(a){var b=Math.abs(f-h.values(a));e>b&&(e=b,g=d(this),i=a)});a.range===!0&&this.values(1)===a.min&&(i+=1,g=d(this.handles[i]));if(this._start(b,
i)===!1)return!1;this._mouseSliding=!0;h._handleIndex=i;g.addClass("ui-state-active").focus();a=g.offset();this._clickOffset=!d(b.target).parents().andSelf().is(".ui-slider-handle")?{left:0,top:0}:{left:b.pageX-a.left-g.width()/2,top:b.pageY-a.top-g.height()/2-(parseInt(g.css("borderTopWidth"),10)||0)-(parseInt(g.css("borderBottomWidth"),10)||0)+(parseInt(g.css("marginTop"),10)||0)};f=this._normValueFromMouse(c);this._slide(b,i,f);return this._animateOff=!0},_mouseStart:function(){return!0},_mouseDrag:function(b){var a=
this._normValueFromMouse({x:b.pageX,y:b.pageY});this._slide(b,this._handleIndex,a);return!1},_mouseStop:function(b){this.handles.removeClass("ui-state-active");this._mouseSliding=!1;this._stop(b,this._handleIndex);this._change(b,this._handleIndex);this._clickOffset=this._handleIndex=null;return this._animateOff=!1},_detectOrientation:function(){this.orientation=this.options.orientation==="vertical"?"vertical":"horizontal"},_normValueFromMouse:function(b){var a;this.orientation==="horizontal"?(a=this.elementSize.width,
b=b.x-this.elementOffset.left-(this._clickOffset?this._clickOffset.left:0)):(a=this.elementSize.height,b=b.y-this.elementOffset.top-(this._clickOffset?this._clickOffset.top:0));a=b/a;a>1&&(a=1);a<0&&(a=0);this.orientation==="vertical"&&(a=1-a);b=this._valueMax()-this._valueMin();return this._trimAlignValue(this._valueMin()+a*b)},_start:function(b,a){var c={handle:this.handles[a],value:this.value()};if(this.options.values&&this.options.values.length)c.value=this.values(a),c.values=this.values();return this._trigger("start",
b,c)},_slide:function(b,a,c){var d;if(this.options.values&&this.options.values.length){d=this.values(a?0:1);if(this.options.values.length===2&&this.options.range===!0&&(a===0&&c>d||a===1&&c<d))c=d;c!==this.values(a)&&(d=this.values(),d[a]=c,b=this._trigger("slide",b,{handle:this.handles[a],value:c,values:d}),this.values(a?0:1),b!==!1&&this.values(a,c,!0))}else c!==this.value()&&(b=this._trigger("slide",b,{handle:this.handles[a],value:c}),b!==!1&&this.value(c))},_stop:function(b,a){var c={handle:this.handles[a],
value:this.value()};if(this.options.values&&this.options.values.length)c.value=this.values(a),c.values=this.values();this._trigger("stop",b,c)},_change:function(b,a){if(!this._keySliding&&!this._mouseSliding){var c={handle:this.handles[a],value:this.value()};if(this.options.values&&this.options.values.length)c.value=this.values(a),c.values=this.values();this._trigger("change",b,c)}},value:function(b){if(arguments.length)this.options.value=this._trimAlignValue(b),this._refreshValue(),this._change(null,
0);return this._value()},values:function(b,a){var c,f,e;arguments.length>1&&(this.options.values[b]=this._trimAlignValue(a),this._refreshValue(),this._change(null,b));if(arguments.length)if(d.isArray(arguments[0])){c=this.options.values;f=arguments[0];for(e=0;e<c.length;e+=1)c[e]=this._trimAlignValue(f[e]),this._change(null,e);this._refreshValue()}else return this.options.values&&this.options.values.length?this._values(b):this.value();else return this._values()},_setOption:function(b,a){var c,f=0;
if(d.isArray(this.options.values))f=this.options.values.length;d.Widget.prototype._setOption.apply(this,arguments);switch(b){case "disabled":a?(this.handles.filter(".ui-state-focus").blur(),this.handles.removeClass("ui-state-hover"),this.handles.attr("disabled","disabled"),this.element.addClass("ui-disabled")):(this.handles.removeAttr("disabled"),this.element.removeClass("ui-disabled"));break;case "orientation":this._detectOrientation();this.element.removeClass("ui-slider-horizontal ui-slider-vertical").addClass("ui-slider-"+
this.orientation);this._refreshValue();break;case "value":this._animateOff=!0;this._refreshValue();this._change(null,0);this._animateOff=!1;break;case "values":this._animateOff=!0;this._refreshValue();for(c=0;c<f;c+=1)this._change(null,c);this._animateOff=!1}},_value:function(){var b=this.options.value;return b=this._trimAlignValue(b)},_values:function(b){var a,c;if(arguments.length)a=this.options.values[b],a=this._trimAlignValue(a);else{a=this.options.values.slice();for(c=0;c<a.length;c+=1)a[c]=
this._trimAlignValue(a[c])}return a},_trimAlignValue:function(b){if(b<this._valueMin())return this._valueMin();if(b>this._valueMax())return this._valueMax();var a=this.options.step,c=b%a;b-=c;c>=a/2&&(b+=a);return parseFloat(b.toFixed(5))},_valueMin:function(){return this.options.min},_valueMax:function(){return this.options.max},_refreshValue:function(){var b=this.options.range,a=this.options,c=this,f=!this._animateOff?a.animate:!1,e,g={},h,i,j,k;if(this.options.values&&this.options.values.length)this.handles.each(function(b){e=
(c.values(b)-c._valueMin())/(c._valueMax()-c._valueMin())*100;g[c.orientation==="horizontal"?"left":"bottom"]=e+"%";d(this).stop(1,1)[f?"animate":"css"](g,a.animate);if(c.options.range===!0)if(c.orientation==="horizontal"){if(b===0)c.range.stop(1,1)[f?"animate":"css"]({left:e+"%"},a.animate);if(b===1)c.range[f?"animate":"css"]({width:e-h+"%"},{queue:!1,duration:a.animate})}else{if(b===0)c.range.stop(1,1)[f?"animate":"css"]({bottom:e+"%"},a.animate);if(b===1)c.range[f?"animate":"css"]({height:e-h+
"%"},{queue:!1,duration:a.animate})}h=e});else{i=this.value();j=this._valueMin();k=this._valueMax();e=k!==j?(i-j)/(k-j)*100:0;g[c.orientation==="horizontal"?"left":"bottom"]=e+"%";this.handle.stop(1,1)[f?"animate":"css"](g,a.animate);if(b==="min"&&this.orientation==="horizontal")this.range.stop(1,1)[f?"animate":"css"]({width:e+"%"},a.animate);if(b==="max"&&this.orientation==="horizontal")this.range[f?"animate":"css"]({width:100-e+"%"},{queue:!1,duration:a.animate});if(b==="min"&&this.orientation===
"vertical")this.range.stop(1,1)[f?"animate":"css"]({height:e+"%"},a.animate);if(b==="max"&&this.orientation==="vertical")this.range[f?"animate":"css"]({height:100-e+"%"},{queue:!1,duration:a.animate})}}});d.extend(d.ui.slider,{version:"1.8.1"})})(jQuery);
