﻿	Control.SliderSmooth = Class.create();
	Control.SliderSmooth.prototype = Control.Slider.prototype;
	Control.SliderSmooth.prototype.startDragParent = Control.Slider.prototype.startDrag;
	Control.SliderSmooth.prototype.setValueParent = Control.Slider.prototype.setValue;
	
	Control.SliderSmooth.prototype.animating = false;
	Control.SliderSmooth.prototype.tickPause = 20;
	Control.SliderSmooth.prototype.steps = 5;
	Control.SliderSmooth.prototype.startAnimation = function(){
		this.setValue = this.setValueParent;
		this.stopAnimation();
		this.animating = true;
	}
	Control.SliderSmooth.prototype.stopAnimation = function(){
		if (this.animating){
			clearTimeout(this.animTimerID);
			this.animating = false;
			this.setValue = this.setValueNew;
		}		
	}
	Control.SliderSmooth.prototype.slideTo = function(value){
		this.startAnimation();
		var self = this;
		this.animTimerID = setTimeout( function() { self.moveOneTick(value); }, this.tickPause );
	}
	Control.SliderSmooth.prototype.moveOneTick = function(value){
		var step = this.getNextStep(this.value, value);
		var dx = value - this.value;
		if (Math.abs(dx) <= (this.maximum - this.minimum)/(this.steps * 10)){
			this.setValue(value, 0);
			this.stopAnimation();
		}else{
			var newval = this.value + step;
			this.setValue(newval, 0);
			this.value = newval; // to prevent endless loop with descreet values
			var self = this;
			this.animTimerID = setTimeout( function() { self.moveOneTick(value); }, this.tickPause );
		}
	}
	Control.SliderSmooth.prototype.getNextStep = function(current, dest){
		return (dest - current)/this.steps;
	}
	
	Control.SliderSmooth.prototype.setValueNew = function(sliderValue, handleIdx){
		if (!this.dragging){
			this.slideTo(sliderValue);
		}else{
			this.setValueParent(sliderValue, handleIdx);
		}
	}
	Control.SliderSmooth.prototype.setValue = Control.SliderSmooth.prototype.setValueNew;
	Control.SliderSmooth.prototype.startDrag = function(event) {
		this.stopAnimation();
		this.startDragParent(event);
	}