text: /*
  * spinControl
  *
  *     touch spin input control for mobile WebKit
  *     (also works on desktop webkit browsers for testing/dev purposes)
  *
  * Copyright (c) 2010
  * http://42at.com/lab/spinControl
  * Released under MIT license
  *
  * Version 0.2 - Last updated: 2013.08.01
  */
  (function(a){a.spinControl=i;a.spinToggle=e;i.version=e.version="0.2";var g=false,h,c;function i(t,p,o){var n=this;var q=o||{};var k=arguments.length;this.valuesFnc=null;this._position=0;if(p instanceof Array){this.values=p}else{if(k>4){q=arguments[4];this.values=f(arguments[1],arguments[2],arguments[3])}else{if(k==4){q=typeof arguments[3]=="object"?arguments[3]:null;this.values=f(arguments[1],arguments[2],q?1:arguments[3])}else{if(k==3){q=typeof arguments[2]=="object"?arguments[2]:null;if(q){if(typeof arguments[1]!="function"){this.values=f(1,arguments[1],1)}else{this.valuesFnc=arguments[1];this.values=f(0,100,1)}}else{this.values=f(arguments[1],arguments[2],1)}}else{if(k==2){q=typeof arguments[1]=="object"?arguments[1]:null;if(q||typeof arguments[1]=="function"){this.values=f(0,100,1)}else{if(typeof arguments[1]!="function"){this.values=f(1,arguments[1],1)}else{this.valuesFnc=arguments[1]}}}else{this.values=f(0,100,1)}}}}}this.options=j(j({},i.options.defaults),q);if(this.options.hints&&typeof this.options.hints=="string"){this.options.hints=this.options.hints.split("|")}this.wrapper=document.querySelector(t);this.thumb=this.options.thumbSelector?this.wrapper.querySelector(this.options.thumbSelector):null;this.$value=this.options.valueSelector?document.querySelector(this.options.valueSelector):null;this.labelsDiv=null;this.valueIndex=0;this.startIndex=-1;this.moving=false;this.value=this.values?this.values[this.valueIndex]:null;this.percent=0;if(!this.thumb){var m=document.createElement("div");m.className=this.options.thumbClass;this.thumb=this.wrapper.appendChild(m)}this.wrapper.className+=" "+this.options.spinClass;for(var r in this.options.spinCss){this.wrapper.style[r]=this.options.spinCss[r]}for(var r in this.options.thumbCss){this.thumb.style[r]=this.options.thumbCss[r]}this.thumb.webkitTransitionProperty="-webkit-transform";this.thumb.style.webkitTransitionTimingFunction=this.options.easing;this.thumb.style.webkitTransform="translate3d(0, 0, 0)";this.thumb.addEventListener("touchstart",this,true);this.thumb.addEventListener("mousedown",this,true);this.numberOfTouches=1;b(this);if(this.options.spinToClick||this.options.enableToggle){this.wrapper.addEventListener("click",this,true)}if(typeof window.orientation!="undefined"){document.body.addEventListener("orientationchange",this,true)}this.refresh();if(typeof this.options.initialValue!="undefined"){if(this.options.initialValue!==null){this.valueIndex=-1;this.setValue(this.options.initialValue)}}else{this.setIndex(0)}if(this.options.disabled){this.disable()}}i.options={defaults:{easing:"ease-out",easingDuration:350,labels:true,spinToClick:true,enableSnap:true,enableToggle:false,hints:null,disabled:false,bounciness:0.2,acceleration:1,alignToEdge:false,valueSelector:".spinValue",spinClass:"spin",thumbClass:"spinThumb",labelClass:"spinLabel",selectedClass:"selected",labelsDivClass:"spinLabelsDiv",disabledClass:"spinDisabled",spinCss:{},thumbCss:{},labelWidthAdjust:1,onspinbegin:null,onspin:null,onspinend:null,onchange:null,onclick:null,dummy:null}};i.prototype={spin:function(k){if(typeof this.options.onspin=="function"){return this.options.onspin.apply(this,arguments)}},change:function(){if(typeof this.options.onchange=="function"){return this.options.onchange.apply(this,arguments)}if(this.$value){this.$value.innerHTML=this.options.hints?this.options.hints[this.valueIndex]:this.value}},spinend:function(){if(typeof this.options.onspinend=="function"){return this.options.onspinend.apply(this,arguments)}},spinbegin:function(){if(typeof this.options.onspinbegin=="function"){return this.options.onspinbegin.apply(this,arguments)}},click:function(){if(typeof this.options.onclick=="function"){return this.options.onclick.apply(this,arguments)}return true},getValue:function(){return this.value},getIndex:function(){return this.valueIndex},setValue:function(l){if(typeof l!="undefined"&&this.values){for(var k in this.values){if(l==this.values[k]){this.setIndex(k);break}}}return this.value},setIndex:function(l){if(typeof l!="undefined"&&this.values&&l>=0&&l<this.values.length){var n=this.positionAtIndex(l),m=this.adjustDuration(l);if(l!=this.valueIndex){var k=this.position();this.updateValue(l>>0);this.triggerCallback("spin",n-k,true);this.change()}this.spinTo(n,m)}return this.valueIndex},toggle:function(){var k=this.valueIndex;if(k<this.values.length-1){k++}else{k=0}this.setIndex(k);return this.value},next:function(m){m=typeof m=="undefined"?1:m;var l=this.valueIndex,k=this.values.length-1;if(l+m>k||l+m<0){return null}this.setIndex(l+m);return this.value},prev:function(k){k=typeof k=="undefined"?1:k;return this.next(-k)},first:function(){this.setIndex(0);return this.value},last:function(){this.setIndex(this.values.length-1);return this.value},disable:function(){this.disabled=true;this.wrapper.className+=" "+this.options.disabledClass},enable:function(){this.disabled=false;this.wrapper.className=this.wrapper.className.replace(new RegExp("\\b"+this.options.disabledClass+"\\b","g"),"")},destroy:function(){this.destroyLabels();if(this.thumb){this.thumb.removeEventListener("touchstart",this,true);this.thumb.removeEventListener("mousedown",this,true);this.wrapper.removeChild(this.thumb);this.thumb=null}if(this.options.spinToClick||this.options.enableToggle){this.wrapper.removeEventListener("click",this,true)}if(typeof window.orientation!="undefined"){document.body.removeEventListener("orientationchange",this,true)}for(var k in this.options.spinCss){this.wrapper.style[k]=""}this.wrapper=null;this.$value=null},positionAtIndex:function(m){if(!this.values){return 0}var l=0,k=0,o=0,p,n;if(this.options.alignToEdge&&(this.moving||this.options.type=="spinToggle")){p=1;k=0}else{p=0.5;k=Math.floor(this.wrapper.offsetWidth/2)}while(l<=m){n=this.labelsDiv.children[l++];o=n.offsetWidth+parseInt(getComputedStyle(n,null).getPropertyValue("margin-left"))+parseInt(getComputedStyle(n,null).getPropertyValue("margin-right"));k-=o}k=Math.floor(k+p*o);if(this.options.alignToEdge&&!this.moving){k=this.alignPosition(k)}return k},indexFromNode:function(l){var k=-1;while(l){l=l.previousSibling;k++}return k},alignPosition:function(k){var n=-this.labelsDivWidth+this.wrapper.offsetWidth-(this.options.type=="spinToggle"?0:2);if(k<n){return n}var s=k,o=0,t=0,v,l,u;v=0.5;u=this.labelsDiv.firstChild.offsetWidth;var q=this.labelsDiv.children,r=q.length;while(s<-0.5*u&&o<r){var m=q[o++];u=m.offsetWidth+parseInt(getComputedStyle(m,null).getPropertyValue("margin-left"))+parseInt(getComputedStyle(m,null).getPropertyValue("margin-right"));s+=u;t-=u}return t},indexFromPos:function(o){if(!this.values){return 0}var k=o,l=0,q,n,m;if(this.options.alignToEdge){q=0.5;m=-this.labelsDiv.firstChild.offsetWidth}else{q=1;m=0.5*this.wrapper.clientWidth}while(k<q*m&&l<this.values.length){if(this.options.alignToEdge){m=this.labelsDiv.children[l].offsetWidth}k+=this.labelsDiv.children[l++].offsetWidth}return Math.max(0,--l)},triggerCallback:function(m){var l=this,k=[].slice.call(arguments);k.shift();setTimeout(function(){l[m].apply(l,k)},0)},handleEvent:function(k){if(this.disabled){return}if(g&&k.type.indexOf("mouse")==0){return}switch(k.type){case"touchstart":case"mousedown":g=k.type==="touchstart";this.onTouchStart(k);break;case"touchmove":case"mousemove":this.onTouchMove(k);break;case"touchend":case"mouseup":this.onTouchEnd(k);break;case"click":if(!this.moving&&this.click(k)!==false){this.moving=false;this.onClick(k)}this.moving=false;break;case"orientationchange":this.onOrientation(k);break;case"webkitTransitionEnd":this.onTransitionEnd(k);break}},position:function(k){if(typeof k!="undefined"){this._position=k;this.thumb.style.webkitTransform="translate3d("+k+"px, 0, 0)"}return this._position},refresh:function(){this.thumb.style.webkitTransitionDuration="0";this.wrapperWidth=this.wrapper.clientWidth;this.labelsDivWidth=d(this);var k=this.labelsDivWidth;if(this.options.alignToEdge){this.maxSlide=-k+this.wrapperWidth;this.minSlide=0}else{this.maxSlide=-Math.floor(k-0.5*(this.wrapper.offsetWidth+this.labelsDiv.lastChild.offsetWidth));this.minSlide=Math.floor(0.5*(this.wrapper.offsetWidth-this.labelsDiv.firstChild.offsetWidth))}},onClick:function(m){var l=m.target;if(m.target.parentNode!=this.labelsDiv){return}var k=this.indexFromNode(l);if(this.options.spinToClick&&k!=this.valueIndex){this.startIndex=this.valueIndex;this.setIndex(k)}else{if(this.options.enableToggle){this.toggle()}}},destroyLabels:function(){if(!this.labelsDiv){return}var k=this.labelsDiv;while(k.firstChild){k.removeChild(k.firstChild)}k.parentNode.removeChild(k)},onOrientation:function(k){this.refresh();if(this.wrapperWidth!=this.wrapper.clientWidth){this.setIndex(this.valueIndex)}},onTouchStart:function(k){h=g?"touchmove":"mousemove";c=g?"touchend":"mouseup";if(k.targetTouches&&k.targetTouches.length!=this.numberOfTouches){return}this.moving=false;if(this.values){this.startIndex=this.valueIndex}this.startX=k.targetTouches?k.targetTouches[0].clientX:k.clientX;this.startY=k.targetTouches?k.targetTouches[0].clientY:k.clientY;this.startTime=k.timeStamp;this.thumb.addEventListener(h,this,false);this.thumb.addEventListener(c,this,false);this.triggerCallback("spinbegin")},onTouchMove:function(n){if(n.targetTouches&&n.targetTouches.length!=this.numberOfTouches){return}var r=n.targetTouches?n.targetTouches[0].clientX:n.clientX;var p=n.targetTouches?n.targetTouches[0].clientY:n.clientY;var m=window.getComputedStyle(this.thumb,null).webkitTransform;m=new WebKitCSSMatrix(m).m41;var l=r-this.startX;var k=p-this.startY;if(1.5*Math.abs(k)>Math.abs(l)||l==0){return true}n.preventDefault();var s=l;this.scrollTime=n.timeStamp-this.startTime;this.startTime=n.timeStamp;if((s>0&&m>=this.minSlide)||(s<0&&m<=this.maxSlide)){s/=3;s=s<0?Math.ceil(s):Math.floor(s)}var q=this.position(),o=q+s;if(this.options.bounciness==0){o=Math.max(Math.min(o,this.minSlide),this.maxSlide);if(m==o){return}s=o-q}this.moving=true;this.position(o);this.startX=r;this.delta=s;this.triggerCallback("spin",s);return},updateValue:function(k){this.value=this.valuesFnc?this.valuesFnc(k):this.values[k];this.valueIndex=k},onTouchEnd:function(r){r.preventDefault();this.thumb.removeEventListener(h,this,false);this.thumb.removeEventListener(c,this,false);if(!this.moving){return false}if(!this.options.enableSnap||this.options.easingDuration==0){this.triggerCallback("spinend")}var m,q;if(!this.options.enableSnap){m=this.indexFromPos(this._position);if(this.startIndex!=m){this.updateValue(m);this.triggerCallback("change");this.updateSelected()}return false}var n=this.delta/this.scrollTime,l=0.00005/(1+Math.abs(this.options.acceleration))*this.wrapper.clientWidth,k,s;l=Math.max(0.0001,l);k=(this.delta<0?-1:1)*Math.floor(n*n/l);s=this._position+k;m=this.indexFromPos(s);if(this.options.alignToEdge){q=this.alignPosition(s)}else{if(m==this.valueIndex&&Math.abs(n)>0.1){m+=(n>0?-1:1)}if(m<0){m=0}if(m>this.values.length-1){m=this.values.length-1}q=this.positionAtIndex(m)}var o=this.adjustDuration(m);this.updateValue(m);this.spinTo(q,o);if(this.valueIndex!=this.startIndex){this.triggerCallback("change")}},adjustDuration:function(m){var k=Math.abs(this.valueIndex-m);if(!this.values||k<=1){return this.options.easingDuration}var l=0.7*(1+k)/this.values.length;var n=Math.floor(this.options.easingDuration*(1+l));return n},onTransitionEnd:function(k){this.thumb.style.webkitTransitionDuration="0";this.thumb.removeEventListener("webkitTransitionEnd",this,false);this.updateSelected();this.triggerCallback("spinend")},spinTo:function(p,n){n=n||this.options.easingDuration;if(n==0){this.position(p);this.updateSelected();return}if(p==this._position){this.updateSelected();return}var k=3,o=Math.floor(this.options.bounciness*(p-this._position)),l;if(this.valueIndex>0&&this.valueIndex<this.values.length-1){o=0}if(Math.abs(o)<k){o=0}l=o?Math.floor(0.7*n):n;this.thumb.style.webkitTransitionTimingFunction=this.options.easing;this.thumb.style.webkitTransitionDuration=l+"ms";if(o){var m=this;setTimeout(function(){m.thumb.style.webkitTransitionDuration=Math.floor(0.3*n)+"ms";m.thumb.addEventListener("webkitTransitionEnd",m,false);m.position(m._position-o)},l+20)}else{this.thumb.addEventListener("webkitTransitionEnd",this,false)}this.position(p+o);return},updateSelected:function(l){l=l||"";if(this.startIndex!=this.valueIndex&&this.options.selectedClass&&this.labelsDiv){if(l=="off"||l==""){var k=this.labelsDiv.querySelector("."+this.options.selectedClass);if(k){k.className=k.className.replace(new RegExp("\\b"+this.options.selectedClass+"\\b","g"),"")}}if(l=="on"||l==""){if(this.labelsDiv.childNodes.length>this.valueIndex){this.labelsDiv.childNodes[this.valueIndex].className+=" "+this.options.selectedClass}}}}};i.range=f;function f(s,m,q){var k=arguments.length;if(k==0){return[]}if(k==1){return arguments.callee(0,s,1)}if(k==2){return arguments.callee(s,m,1)}var o=[];if(q==0){return[]}if((s<=m&&q<0)||(s>=m&&q>0)){q=-q}var r=-1;var p=q.toString().indexOf(".");if(p!=-1){r=q.toString().length-(1+p);p=true}else{s>>=0;m>>=0;q>>=0;p=false}for(;q>0?s<=m:s>=m;s+=q){o.push(p?parseFloat(s.toFixed(r)):s)}return o}function b(t){var p=t.options.labels;switch(typeof p){case"boolean":case"number":p=t.values;break;case"string":p=p.split(/\|/);if(p.length!=t.values.length){p=new Array(t.values.length+1).join(p+"\u0000").split("\u0000",t.values.length)}break}var k=document.createElement("div");k.className=t.options.labelsDivClass;t.labelsDiv=t.thumb.appendChild(k);var q="",m=t.values.length>1?t.values.length:p.length,s=Math.floor(t.wrapper.clientWidth/t.values.length)-t.options.labelWidthAdjust;var l=false;if(t.options.labels==false||t.options.labels.length==0){l=" "}for(var o in t.values){var r=l||p[o];if(r===undefined){r=""}q+='<span class="'+t.options.labelClass+'">'+r+"</span>"}t.labelsDiv.innerHTML=q}function d(l){var k=0,n,m=l.labelsDiv.children.length;while(--m>=0){n=l.labelsDiv.children[m];k+=parseInt(n.offsetWidth)+parseInt(getComputedStyle(n,null).getPropertyValue("margin-left"))+parseInt(getComputedStyle(n,null).getPropertyValue("margin-left"))}return k}function j(k,m){for(var l in m){k[l]=m[l]}return k}function e(m,x,l){l=l||{};var q=l.labels||x;delete l.labels;if(x.length!=2){throw"spinToggle: values must be an array with only two values! id="+m+", values="+x}var y={type:"spinToggle",labels:q,selectedClass:"",enableToggle:true,bounciness:0,easingDuration:50,spinClass:"spinToggle",alignToEdge:true,spinToClick:l.enableToggle,_onchange:function(){}};if(l.onOffStyle){y.spinClass+=" onOffStyle"}for(var o in l){y[o]=l[o]}delete y.initialValue;var k=new i(m,x,y);k.base_click=k.click;k.click=function(v){this.toggle();this.base_click(v);return false};var r=document.createElement("span");r.className=k.options.labelClass+" thimbleClass";r.innerHTML="";r=k.labelsDiv.insertBefore(r,k.labelsDiv.lastChild);var p=k.labelsDiv.firstChild.offsetWidth-k.labelsDiv.lastChild.offsetWidth,m=p>0?k.labelsDiv.lastChild:k.labelsDiv.firstChild;p=Math.abs(p);if(p>0){var u=Math.floor(p/2),n=p-u;m.style.paddingLeft=u+parseInt(getComputedStyle(m,null).getPropertyValue("padding-left"))+"px";m.style.paddingRight=n+parseInt(getComputedStyle(m,null).getPropertyValue("padding-right"))+"px"}var t=parseInt(getComputedStyle(k.thumb,null).getPropertyValue("padding-left"))+parseInt(getComputedStyle(k.thumb,null).getPropertyValue("border-left-width"));var s=2*t+k.labelsDiv.firstChild.offsetWidth+r.offsetWidth;k.wrapper.style.width=s+"px";k.refresh();k.maxSlide=-k.labelsDiv.firstChild.offsetWidth;k.labelsDivWidth+=2*t;k.onOrientation=function(){};if("initialValue" in l){k.setValue(l.initialValue)}else{k.setIndex(0)}return k}})(this);