function Slider_Class(oData){this.oData=oData||{};this.parentID=this.oData.parentID?this.oData.parentID:"";this.parentEl=this.parentID!=""?Element.get(this.parentID):Element.create("div",{},[],document.getElementsByTagName("body")[0]);this.sliderClass=this.oData.sliderClass?this.oData.sliderClass:"sliderBar";this._initNumbers();this._init();}
Slider_Class.prototype._init=function(){this.handles=[];this.handlesLen=0;this.orientation=this.oData.orientation?this.oData.orientation:"leftToRight";this.isVertical=this.orientation=="topToBottom"||this.orientation=="bottomToTop";this.isBackwards=this.orientation=="bottomToTop"||this.orientation=="rightToLeft";this.handleOverlap=this.oData.handleOverlap?this.oData.handleOverlap:"handleEdge";this._drawSliderBar();this._calculateMagicNumbers();}
Slider_Class.prototype._initNumbers=function(){this.maxVal=!isNaN(parseFloat(this.oData.maxVal))?parseFloat(this.oData.maxVal):100;this.minVal=!isNaN(parseFloat(this.oData.minVal))?parseFloat(this.oData.minVal):0;this.handleOffsetHigh=0;this.handleOffsetLow=0;if(this.oData.handleOffset){if(typeof(this.oData.handleOffset)=="object"){this.handleOffsetLow=this.oData.handleOffset[0]?this.oData.handleOffset[0]:this.handleOffsetLow;this.handleOffsetHigh=this.oData.handleOffset[1]?this.oData.handleOffset[1]:this.handleOffsetHigh;}
else if(!isNaN(parseInt(this.oData.handleOffset))){this.handleOffsetLow=parseInt(this.oData.handleOffset);this.handleOffsetHigh=this.handleOffsetLow;}}}
Slider_Class.prototype._drawSliderBar=function(){this.sliderBar=Element.create("div",{className:this.sliderClass,style:"position:relative"},null,this.parentEl)
this._setDefaults();}
Slider_Class.prototype._calculateMagicNumbers=function(){if(this.isVertical){this.offsetFromEdge=Element.getXY(this.sliderBar).y;this.barLength=Element.getSize(this.sliderBar).height;}else{this.offsetFromEdge=Element.getXY(this.sliderBar).x;this.barLength=Element.getSize(this.sliderBar).width;}
this.minPix=0;this.maxPix=this.barLength-(this.handleOffsetLow+this.handleOffsetHigh);this.valuePerPixel=this.maxPix?(this.maxVal-this.minVal)/this.maxPix:1;this.pixelPerValue=this.valuePerPixel?(1/this.valuePerPixel):1;}
Slider_Class.prototype._setDefaults=function(){if(!Element.getSize(this.sliderBar).height){Element.setHeight(this.sliderBar,this.isVertical?100:10);Element.setWidth(this.sliderBar,this.isVertical?10:100);this.sliderBar.style.backgroundColor="#CCC";this.sliderBar.style.fontSize="1px";}}
Slider_Class.prototype.addHandle=function(){var handle;for(var i=0,len=arguments.length;i<len;i++){handle=arguments[i];if(handle.el){this.handles.push(handle)
Element.addChild(this.sliderBar,handle.el);handle.init(this,this.handlesLen);this.handlesLen++;}}}
function SliderHandle_Class(oData){this._preInit(oData);this.drawHandle();}
SliderHandle_Class.prototype.MyUpdateValue=function(mouseEvent,direction){}
SliderHandle_Class.prototype._preInit=function(oData){this.oData=oData||{};this.defaultVal=!isNaN(parseFloat(this.oData.defaultVal))?parseFloat(this.oData.defaultVal):0;this.increment=!isNaN(parseFloat(this.oData.increment))?parseFloat(this.oData.increment):1;this.tabindex=this.oData.tabindex?String(this.oData.tabindex):"1";this.handleClassName=this.oData.handleClassName?this.oData.handleClassName:"sliderHandle";this.handleLength=1;this.halfOfHandle=1;}
SliderHandle_Class.prototype.init=function(parentSliderBar,whichHandle){this.parentSliderBar=parentSliderBar;this.whichHandle=whichHandle;Element.addClass(this.el,this.handleClassName+this.whichHandle);this.setMaxVal(this.parentSliderBar.maxVal);this.setMaxPix(this.parentSliderBar.maxPix);this.setMinVal(this.parentSliderBar.minVal);this.setMinPix(this.parentSliderBar.minPix);this._setDefaults();this.handleLength=this.parentSliderBar.isVertical?Element.getSize(this.el).height:Element.getSize(this.el).width;this.halfOfHandle=Math.floor(this.handleLength/2);this.finalDisplayFromValue(this.defaultVal);Element.setStyle(this.el,"visibility:visible;");this._initEvents();}
SliderHandle_Class.prototype.drawHandle=function(){this.el=Element.create("div",{className:this.handleClassName,tabIndex:this.tabindex,style:"position:absolute;visibility:hidden"})}
SliderHandle_Class.prototype._setDefaults=function(){if(!Element.getSize(this.el).height||!Element.getSize(this.el).width){Element.setSize(this.el,10,10);this.el.style.backgroundColor="#C33";this.el.style.fontSize="1px";}
this._setZIndex(this.whichHandle);}
SliderHandle_Class.prototype._initEvents=function(){this.mouseDownEvent=Events.add({type:'mousedown',handler:this.startMoveHandler,context:this});this.mouseMoveEvent=Events.add({type:'mousemove',handler:this.moveHandler,context:this});this.mouseUpEvent=Events.add({type:'mouseup',handler:this.endMoveHandler,context:this});this.keyDownEvent=Events.add({type:'keydown',handler:this.keyDownHandler,context:this});this.mouseDownEvent.addElement(this.el);this.keyDownEvent.addElement(this.el);}
SliderHandle_Class.prototype.startMoveHandler=function(evt){evt.cancel();this.mouseMoveEvent.addElement(document);this.mouseUpEvent.addElement(document);if(this.parentSliderBar.isVertical){this.eventCoord=isNaN(evt.nativeEvent.clientY)||evt.nativeEvent.clientY<0?0:evt.nativeEvent.clientY;}else{this.eventCoord=isNaN(evt.nativeEvent.clientX)||evt.nativeEvent.clientX<0?0:evt.nativeEvent.clientX;}
this._setZIndex(this.parentSliderBar.handlesLen);this.findMouseOffset(this.eventCoord);if(this.parentSliderBar.handlesLen>1){this.multipleHandleMinMax();}
this.MyUpdateValue("mousestart",null);}
SliderHandle_Class.prototype.moveHandler=function(evt){evt.cancel();if(this.parentSliderBar.isVertical){this.eventCoord=isNaN(evt.nativeEvent.clientY)||evt.nativeEvent.clientY<0?0:evt.nativeEvent.clientY;}else{this.eventCoord=isNaN(evt.nativeEvent.clientX)||evt.nativeEvent.clientX<0?0:evt.nativeEvent.clientX;}
this.prevCurrentValue=this.currentValue;this.finalDisplayFromPosition(this.eventCoord-this.parentSliderBar.offsetFromEdge-this.parentSliderBar.handleOffsetLow+this.mouseOffset);this.MyUpdateValue("mousemove",this.currentValue>this.prevCurrentValue?"up":this.currentValue<this.prevCurrentValue?"down":null)}
SliderHandle_Class.prototype.endMoveHandler=function(e){e.cancel();this.mouseMoveEvent.removeAllElements();this.mouseUpEvent.removeAllElements();this._setZIndex(this.whichHandle);this.MyUpdateValue("mouseend",null);}
SliderHandle_Class.prototype.keyDownHandler=function(evt,el){var k=evt.nativeEvent;var keyNum=k.keyCode||k.charCode;if(this.KEYMAP[keyNum]=="rightArrowKey"||this.KEYMAP[keyNum]=="downArrowKey"){if(this.parentSliderBar.handlesLen>1){this.multipleHandleMinMax()}
if(this.parentSliderBar.isBackwards){this.incrementValue(-1);this.MyUpdateValue("keydown","down")}else{this.incrementValue(1);this.MyUpdateValue("keydown","up")}}
else if(this.KEYMAP[keyNum]=="leftArrowKey"||this.KEYMAP[keyNum]=="upArrowKey"){if(this.parentSliderBar.handlesLen>1){this.multipleHandleMinMax()}
if(this.parentSliderBar.isBackwards){this.incrementValue(1);this.MyUpdateValue("keydown","up")}else{this.incrementValue(-1);this.MyUpdateValue("keydown","down")}}
else if(this.KEYMAP[keyNum]=="enterKey"||this.KEYMAP[keyNum]=="tabKey"){this.MyUpdateValue("mouseend",null);}}
SliderHandle_Class.prototype.KEYMAP={39:"rightArrowKey",54:"rightArrowKey",37:"leftArrowKey",52:"leftArrowKey",38:"upArrowKey",104:"upArrowKey",40:"downArrowKey",98:"downArrowKey",16:"shiftKey",9:"tabKey",13:"enterKey"}
SliderHandle_Class.prototype._setZIndex=function(num){this.el.style.zIndex=10+num;var parentID=(this.el.parentNode).parentNode.id;parentID=parentID.replace("sliderParent_","");var labelDiv=Element.get("sliderDataInner_"+parentID);}
SliderHandle_Class.prototype.setMaxVal=function(val){this.maxVal=val;}
SliderHandle_Class.prototype.getMaxVal=function(){return this.maxVal;}
SliderHandle_Class.prototype.setMaxPix=function(pos){this.maxPix=pos;}
SliderHandle_Class.prototype.getMaxPix=function(){return this.maxPix;}
SliderHandle_Class.prototype.setMinVal=function(val){this.minVal=val;}
SliderHandle_Class.prototype.getMinVal=function(){return this.minVal;}
SliderHandle_Class.prototype.setMinPix=function(pos){this.minPix=pos;}
SliderHandle_Class.prototype.getMinPix=function(){return this.minPix;}
SliderHandle_Class.prototype.getPosition=function(){return this.currentPosition;}
SliderHandle_Class.prototype.setPosition=function(pos){this.currentPosition=pos;}
SliderHandle_Class.prototype.finalDisplayFromValue=function(newVal){var newVal=newVal!=null?newVal:this.currentValue;var newPos=Math.round(this.getPositionOfValue(newVal));if(newVal!=this.currentValue){if(newVal>=this.minVal&&newVal<=this.maxVal){this.setPosition(newPos);this.setValue(newVal);this._updateHandle()}
else if(newVal<this.minVal){if(this.parentSliderBar.isBackwards){this.setPosition(this.maxPix)}
else{this.setPosition(this.minPix)}
this.setValue(this.minVal);this._updateHandle()}
else if(newVal>this.maxVal){if(this.parentSliderBar.isBackwards){this.setPosition(this.minPix)}else{this.setPosition(this.maxPix)}
this.setValue(this.maxVal);this._updateHandle()}}}
SliderHandle_Class.prototype.finalDisplayFromPosition=function(newPos){var newPos=newPos!=null?Math.round(newPos):this.currentPosition;var newVal=this.getValueOfPosition(newPos);if(newPos!=this.currentPosition){if(newPos>=this.minPix&&newPos<=this.maxPix){this.setPosition(newPos);this.setValue(newVal);this._updateHandle()}
else if(newPos<this.minPix){this.setPosition(this.minPix)
if(this.parentSliderBar.isBackwards){this.setValue(this.maxVal);}else{this.setValue(this.minVal);}
this._updateHandle()}
else if(newPos>this.maxPix){this.setPosition(this.maxPix)
if(this.parentSliderBar.isBackwards){this.setValue(this.minVal);}else{this.setValue(this.maxVal);}
this._updateHandle()}}}
SliderHandle_Class.prototype._updateHandle=function(){this.handleEdgePosition=(this.currentPosition-this.halfOfHandle+this.parentSliderBar.handleOffsetLow);if(this.parentSliderBar.isVertical){this.el.style.top=this.handleEdgePosition+"px";}else{this.el.style.left=this.handleEdgePosition+"px";}}
SliderHandle_Class.prototype.getValue=function(){return this.currentValue;}
SliderHandle_Class.prototype.setValue=function(val){this.currentValue=val;}
SliderHandle_Class.prototype.incrementValue=function(multiple){this.finalDisplayFromValue(this.currentValue+(this.increment*multiple))}
SliderHandle_Class.prototype.getValueOfPosition=function(pos){if(this.parentSliderBar.isBackwards){return this.parentSliderBar.maxVal-(Math.round(pos)*this.parentSliderBar.valuePerPixel);}else{return this.parentSliderBar.minVal+(Math.round(pos)*this.parentSliderBar.valuePerPixel);}}
SliderHandle_Class.prototype.getPositionOfValue=function(val){if(this.parentSliderBar.isBackwards){return(this.parentSliderBar.maxVal-val)*this.parentSliderBar.pixelPerValue;}else{return(val-this.parentSliderBar.minVal)*this.parentSliderBar.pixelPerValue;}}
SliderHandle_Class.prototype.findMouseOffset=function(pos){this.mouseOffset=this.currentPosition-(Math.round(pos)-this.parentSliderBar.offsetFromEdge-this.parentSliderBar.handleOffsetLow);}
SliderHandle_Class.prototype.multipleHandleMinMax=function(){if(this.parentSliderBar.handleOverlap!="none"){var overlapPix=this.parentSliderBar.handleOverlap=="handleEdge"?this.handleLength:(this.parentSliderBar.handleOverlap=="nextPixel"?1:!isNaN(Number(this.parentSliderBar.handleOverlap))?Number(this.parentSliderBar.handleOverlap):0);if(this.whichHandle>0){this.setMinPix(this.parentSliderBar.handles[this.whichHandle-1].getPosition()+overlapPix)
this.setMinVal(this.getValueOfPosition(this.getMinPix()));}
if(this.whichHandle<this.parentSliderBar.handlesLen-1){this.setMaxPix(this.parentSliderBar.handles[this.whichHandle+1].getPosition()-overlapPix)
this.setMaxVal(this.getValueOfPosition(this.getMaxPix()));}}}
SliderHandle_Class.prototype.keyPressMinMax=function(dir){if(this.parentSliderBar.handleOverlap!="all"){var overlapPix=this.parentSliderBar.handleOverlap=="handleEdge"?this.handleLength:(this.parentSliderBar.handleOverlap=="nextPixel"?1:!isNaN(Number(this.parentSliderBar.handleOverlap))?Number(this.parentSliderBar.handleOverlap):0);if(dir=="right"){if(this.parentSliderBar.handles[this.whichHandle+1]){this.parentSliderBar.handles[this.whichHandle+1].setMinPix(this.getPosition()+overlapPix)}}
else if(dir=="left"){if(this.parentSliderBar.handles[this.whichHandle-1]){this.parentSliderBar.handles[this.whichHandle-1].setMaxPix(this.getPosition()-overlapPix)}}}}