var Slider={sliderType:"vps",defaultValue:1,minValue:1,maxValue:10,labelValue:{singular:"{{value}}",plural:"{{value}}"},offset:1,imagesDir:"/static/images/slider/",imagesList:["slider_bar_off.png","slider_bar_on.png","slider_handle.png","slider_handle_bar.png","slider_handle_hover.png"],extraValue:{},extraPrice:0,selectors:{sliderInput:"#slider_shares",sliderContainer:"#slider_container",sliderBar:"#show_shares span",sliderHandle:".fd-slider-handle",sliderProductValue:"#*_value",sliderProductLabel:"#*_label"},products:[{name:"",quantityRatio:0,priceRatio:0,maxValue:0,step:0,forceStep:true,calculation:function(){},label:{singular:"",plural:""},linkedTo:""}],initialize:function(){this.preloadImages()},preloadImages:function(){var b=this.imagesDir+this.sliderType+"/";var a=this.imagesList;var c=[];$.each(a,function(d,e){c[d]=new Image();c[d].src=b+e})},updateSlider:function(a){var c=a.elem;var b=a.value;this.updateBar(b);this.updateLabel(b);this.updateProducts(b)},updateBar:function(c){var b=-(c-(this.maxValue/2))*this.offset;var a=Math.round(($(this.selectors.sliderContainer).width()*(100/this.maxValue)*c)/100+b);$(this.selectors.sliderBar).css("width",a+"px")},updateLabel:function(b){var a=(b>1)?this.labelValue.plural:this.labelValue.singular;$(this.selectors.sliderHandle).html(a.replace(/{{value}}/,b))},updateProducts:function(c){var a=this.selectors.sliderProductValue;var b=this.maxValue;$.each(this.products,function(e,f){var h=$(a.replace(/\*/,f.name));var i=f.step||Math.ceil(f.quantityRatio);Slider.extraValue[f.name]=0;Slider.extraPrice=0;if(f.type!=="link"){Slider.formatAndUpdateProduct("share",f,c)}var d=parseInt(h.val());var g=(typeof(f.maxValue)!=="undefined")?f.maxValue:-1;if(h.is("input")){h.incrementer({min:d,max:g,step:i,callback:function(){Slider.formatAndUpdateProduct("product",f,c)}})}})},updateExtraValues:function(e,h,j){var c=Math.ceil(j.quantityRatio);var k=parseInt(h.val());var a=Math.ceil(j.quantityRatio*e);var g=k%c;if(g&&j.forceStep){if(g>c/2){k+=c%g}else{k-=g%c}}if(k>a&&k<=j.maxValue){this.extraValue[j.name]=k-a}else{this.extraValue[j.name]=0}var d=this.extraPrice;$.each(Slider.extraValue,function(l,m){var n=Slider.getProductItem(l);if(typeof(n.priceRatio)!=="undefined"){d+=m*n.priceRatio}});var f=this.getProductItem("price");var i=$(this.selectors.sliderProductValue.replace(/\*/,f.name));var b=f.calculation((f.quantityRatio*e)+d);i.html(b);return j.calculation((j.quantityRatio*e)+this.extraValue[j.name])},formatAndUpdateProduct:function(b,c,f){var e=$(this.selectors.sliderProductValue.replace(/\*/,c.name));var a=$(this.selectors.sliderProductLabel.replace(/\*/,c.name));switch(b){case"share":var d=c.calculation(c.quantityRatio*f);break;case"linked":var d=c.calculation(f);break;case"":default:var d=this.updateExtraValues(f,e,c);break}if(e.is("input")){e.val(d)}else{e.html(d)}if(a&&typeof(c.label)!=="undefined"){if(typeof(c.label["plural"])!=="undefined"&&parseInt(d)>1){a.html(c.label["plural"])}else{a.html(c.label["singular"])}}if(typeof(c.linkedTo)!=="undefined"){$.each(c.linkedTo,function(g,h){Slider.formatAndUpdateProduct("linked",Slider.getProductItem(h),parseInt(d))})}},getProductItem:function(a){var b;$.each(this.products,function(c,d){if(d.name===a){b=d}});return b}};
