var trackbarActive=false;var currentHoverParameter=null;var chp_trackbar=new Class({options:{mode:0,form:null,trackbar:null,inputLeft:null,inputRight:null,label:null,labeltype:0,values:null,decimals:0,step:null,limitLeft:0,limitRight:100,valueLeft:null,valueRight:null,t:null,showApply:false,extremumValueToNull:1},initialize:function(m){var g,f,k,d,c,a,b,e,h;this.setOptions(m);this.bound={start:this.start.bindWithEvent(this),drag:this.drag.bindWithEvent(this),stop:this.stop.bind(this),update:this.update.bind(this),set:this.set.bindWithEvent(this)};g=this.options.mode;f=this.options.trackbar;$(f).removeClass("hid");this.elem=f;k=f.offsetWidth;this.trackbarWidth=k;d=f.getElements(".left-slider")[0];this.sliderLeft=d;$(d).addEvent("mousedown",this.bound.start);c=d.offsetWidth;this.sliderLeftWidth=c;if(g!=1){a=f.getElements(".right-slider")[0];this.sliderRight=a;$(a).addEvent("mousedown",this.bound.start);b=a.offsetWidth}else{b=0}this.sliderRightWidth=b;this.sliderLeftX=0;this.sliderRightX=0;e=f.getElements(".chp-fullrange")[0];$(e).addListener("mousedown",this.bound.start);this.fullrange=e;if(g!=1){h=f.getElements(".chp-selrange")[0];$(h).addListener("mousedown",this.bound.start);this.range=h}this.inputLeft=this.options.form[this.options.inputLeft];if(!g){this.inputRight=this.options.form[this.options.inputRight];$(this.inputLeft).addListener("change",this.bound.set);$(this.inputRight).addListener("change",this.bound.set)}this.activePixels=k-c-b;this.rangeOfValues=this.options.limitRight-this.options.limitLeft;this.pixelsPerValue=this.activePixels/this.rangeOfValues;this.update()},start:function(a){var b,g,h,c,k,f,e,d,m;a=new Event(a);if(!currentHoverParameter){b=getParentElement(this.sliderLeft,"chp-trackbarparam");if(b){b.fireEvent("mouseenter")}}trackbarActive=true;g=false;h=getY(this.elem)-window.getScrollTop();this.elem.setProperty("style","position:fixed;width:"+this.trackbarWidth+"px;top:"+h+"px;");if(a.target==this.fullrange){if(this.options.mode==1){this.slider=this.sliderLeft;this.startX=this.slider.getLeft()+this.sliderLeftWidth/2;c=a.page.x-this.startX}else{f=this.sliderLeft.getLeft();d=a.page.x;if(d<f){this.slider=this.sliderLeft;this.startX=f+this.sliderLeftWidth/2;c=d-this.startX}else{this.slider=this.sliderRight;this.startX=this.slider.getLeft()+this.sliderRightWidth/2;c=d-this.startX}}g=true}else{if(a.target==this.range){f=this.sliderRight.getLeft();e=this.sliderLeft.getLeft();m=(f+e+this.sliderLeftWidth)/2;d=a.page.x;if(d<m){this.slider=this.sliderLeft;this.startX=e+this.sliderLeftWidth/2;c=d-this.startX}else{this.slider=this.sliderRight;this.startX=f+this.sliderRightWidth/2;c=d-this.startX}g=true}else{this.slider=a.target;this.startX=a.page.x}}k=this.slider.offsetLeft;if(this.slider===this.sliderRight){k-=this.sliderRightWidth}this.sliderPosX=(k>this.activePixels)?this.activePixels:k;document.addEvent("mousewheel",this.disableMouseWheel);if(window.addEventListener){window.addEventListener("DOMMouseScroll",this.disableMouseWheel,true)}document.addListener("mousemove",this.bound.drag);document.addListener("mouseup",this.bound.stop);if(this.options.label){this.labelValue=this.options.label.getElement(".ppvalue")}a.stop();if(g){this.calcDrag(c)}},drag:function(b){b=new Event(b);var a=b.page.x-this.startX;this.calcDrag(a);b.stop()},calcDrag:function(b){var a=((b+this.sliderPosX)/this.activePixels)*this.rangeOfValues+this.options.limitLeft;a=a.toFixed(this.options.decimals).toFloat();if($defined(this.options.step)){a=a/this.options.step;a=Math.round(a)*this.options.step}if(a<this.options.limitLeft){a=this.options.limitLeft}if(a>this.options.limitRight){a=this.options.limitRight}if(this.slider===this.sliderLeft){if(a==this.options.valueLeft||((a==this.options.valueLeft||this.options.valueLeft==null)&&a==this.options.limitLeft)){return}}else{if(a==this.options.valueRight||((a==this.options.valueRight||this.options.valueRight==null)&&a==this.options.limitRight)){return}}this.options.showApply=true;if(this.slider===this.sliderRight){this.setValueRight(a)}else{this.setValueLeft(a)}},stop:function(a){trackbarActive=false;a=new Event(a);var b={custom:true,x:a.page.x,y:a.page.y};if(currentHoverParameter){currentHoverParameter.fireEvent("mouseleave",b)}document.removeListener("mousemove",this.bound.drag);document.removeListener("mouseup",this.bound.stop);this.slider=null;this.elem.style.position="absolute";this.elem.style.top="";document.removeEvent("mousewheel",this.disableMouseWheel);if(window.removeEventListener){window.removeEventListener("DOMMouseScroll",this.disableMouseWheel,true)}},update:function(){if(this.options.labeltype==1){this.notSetLabel=true}this.setValueLeft(this.options.valueLeft);if(this.options.mode!=1){this.setValueRight(this.options.valueRight)}this.notSetLabel=false},set:function(){var a=this.inputLeft.value.toInt();var b=this.inputRight.value.toInt();if(a){this.setValueLeft(a)}else{this.setValueLeft(this.options.limitLeft)}if(b){this.setValueRight(b)}else{this.setValueRight(this.options.limitRight)}},setValueLeft:function(h){var m=this.options.valueRight;var e,b,k,f=null,c=null;var a=this.checkValue(h,m,this.options.limitLeft,"left");this.options.valueLeft=a;var d=this.options.mode;if(d==0){this.inputLeft.value=(a==null)?"":a}else{if(d==1){b=(a==null)?null:(this.options.values?this.options.values[a]:a);this.inputLeft.value=b?b:"";if(!this.notSetLabel){this.setLabel(b,null)}}else{if(a==null||a==this.options.limitLeft){if(m==null||m==this.options.limitRight){e=""}else{k=this.options.values?this.options.values[m]:m;e=":"+k;c=k}}else{if(this.options.values){b=this.options.values[a];k=this.options.values[m]}else{b=a;k=m}if(m==null||m==this.options.limitRight){if(a==this.options.limitRight){e=b+":"+b;f=c=b}else{e=b+":";f=b}}else{e=b+":"+k;f=b;c=k}}this.inputLeft.value=e;if(!this.notSetLabel){this.setLabel(f,c)}}}var g=this.width(a==null?0:(a-this.options.limitLeft));this.sliderLeft.setStyle("left",g+"px");this.sliderLeftX=g;if(d!=1){this.updateRangeWidth()}return this.options.valueLeft},setValueRight:function(m){var c=this.options.valueLeft;var g,d,b,h=null,e=null;var a=this.checkValue(m,c,this.options.limitRight,"right");this.options.valueRight=a;var f=this.options.mode;if(f==0){this.inputRight.value=(a==null)?"":a}else{if(a==null||a==this.options.limitRight){if(c==null||c==this.options.limitLeft){g=""}else{b=this.options.values?this.options.values[c]:c;g=b+":";h=b}}else{if(this.options.values){d=this.options.values[a];b=this.options.values[c]}else{d=a;b=c}if(c==null||c==this.options.limitLeft){if(a==this.options.limitLeft){g=d+":"+d;h=e=d}else{g=":"+d;e=d}}else{g=b+":"+d;h=b;e=d}}this.inputLeft.value=g;if(!this.notSetLabel){this.setLabel(h,e)}}var k=this.width(a==null?0:(this.options.limitRight-a));this.sliderRight.setStyle("right",k+"px");this.sliderRightX=k;this.updateRangeWidth();return this.options.valueRight},checkValue:function(a,b,d,c){l=this.options.limitLeft;r=this.options.limitRight;if(c=="left"){b=(b==null?r:b);a=(a==null?null:(a<l?l:(a<b?a:b)))}else{if(c=="right"){b=(b==null?l:b);a=(a==null?null:(a>r?r:(a>b?a:b)))}}return a==d&&this.options.extremumValueToNull?null:a},width:function(b){var a=(this.pixelsPerValue)*b;return Math.round(a)},updateRangeWidth:function(){$(this.range).setStyles({left:this.sliderLeftX,right:this.sliderRightX})},setLabel:function(a,d){var e=this.labelValue||this.options.label.getElement(".ppvalue"),b=this.options,c="";if(b.showApply&&b.labeltype==1){c='<button type="button" class="ppapply" onclick="applyRefines('+this.options.form.name+')">'}if(b.labeltype==0){c+='<span class="ppvalue2" data-pname="'+b.inputLeft+'" onclick="clearRefine(this,'+this.options.form.name+')" onmouseover="clearHover(this,true)" onmouseout="clearHover(this,false)">'}if(b.mode==1){c+=(a)?a:words.all}else{if(!a){a=b.values?b.values[b.limitLeft]:b.limitLeft}if(!d){d=b.values?b.values[b.limitRight]:b.limitRight}if(a==d){c+="<b>"+a+"</b>";if(b.t.u){c+=" "+b.t.u}}else{if(b.labeltype==1){c+=words.from+" <b>"+a+"</b> "+words.to+" <b>"+d+"</b>"}else{c+="<b>"+a+"</b> - <b>"+d+"</b>"}if(b.t.u){c+=" "+b.t.u}}}if(b.showApply&&b.labeltype==1){c+=" - <b>"+words.apply+"</b></button>"}if(b.labeltype==0){c+="</span>"}if(b.showApply&&b.labeltype==0){c+=' <button type="button" class="ppapply2" onclick="applyRefines('+this.options.form.name+')">'+words.apply+"</button>"}if(b.labeltype==0){c+='<div class="clear"></div>'}e.innerHTML=c},disableMouseWheel:function(a){var b=new Event(a);b.preventDefault();return false}});chp_trackbar.implement(new Options);function getY(a){var b=0;do{b+=a.offsetTop||0;a=a.offsetParent}while(a);return b}function getParentElement(a,b){do{if(a.className==b){return a}a=a.parentNode}while(a);return null}function applyRefines(d){var b=$(d).getElements("input[type='hidden']"),c=document.getElementById("high-price"),a=document.getElementById("low-price");for(i=0,j=b.length;i<j;++i){if(b[i].value==""){$(b[i]).remove?$(b[i]).remove():$(b[i]).destroy()}}if(c&&c.value==""){c.name=""}if(a&&a.value==""){a.name=""}if(chpSelfUpdating){ChP2.updateFilters2(d)}else{d.submit()}}function clearRefine(b,c){var a=chp[b.getAttribute("data-pname")];if(a.options.valueLeft==null&&a.options.valueRight==null){return}a.options.valueLeft=null;a.options.valueRight=null;a.update();applyRefines(c)}function clearHover(c,a){var b=chp[c.getAttribute("data-pname")];if(!a){$(c).removeClass("cl-hov");return}if(b.options.valueLeft==null&&b.options.valueRight==null){return}$(c).addClass("cl-hov")};