var Slider=Class.create({reset:function(){this.is_active=0;this.value=0;this.max_value=0;this.max_available=0;this.pix_per_value=1;this.update_controls_from_values()},update_controls_from_values:function(A){this.max_avail_width=Math.round(this.max_available)*this.pix_per_value;this.available_bar.style.width=this.max_avail_width+"px";this.max_timecode.update(this.format_time(this.max_value));if(!A){this.cur_timecode.update(this.format_time(this.value));this.knob_pos=Math.round(this.value*this.pix_per_value);this.knob.style.left=(this.knob_pos-this.knob_image_offset)+"px";this.call_knob_pos_callback(this.value)}this.redraw_helper.innerHTML=this.redraw_helper.innerHTML=="1"?"2":"1"},call_knob_pos_callback:function(A){if(this.knob_pos_changed_callback){if(this.max_value==0){A=-1}this.knob_pos_changed_callback(A)}},format_time:function(A){var B=Math.round(A/1000);var C=Math.floor(B/60);B=B-C*60;return C+":"+(B<10?"0"+B:B)},setValueRange:function(A,B){this.max_available=A;this.max_value=B;if(this.value>this.max_available){this.max_available=this.value}if(this.value>this.max_value){this.max_value=this.value}this.recalc_pix_per_value();this.update_controls_from_values(this.is_active)},add_bar:function(E,A,C,B){var D=new Element("div",{style:"width:"+C+"px;height:"+A+"px;position:absolute;top:"+E+"px;left:0px;border:0; background-color:"+B+";"});this.entire_slider.insert({bottom:D});return D},initialize:function(A){this.value_step=A.value_step;this.groove_length=A.groove_length;this.knob_image_offset=Math.round(A.knob_image_width/2);this.knob_pos_changed_callback=A.knob_pos_changed_callback;this.entire_slider=new Element("div",{style:"border:0;width:"+(this.groove_length+70)+"px;height:"+A.knob_image_height+"px;position:relative;"});A.container_div.update(this.entire_slider);this.add_bar(0,1,this.groove_length,"#444444");this.add_bar(1,1,this.groove_length,"#AAAAAA");this.add_bar(2,1,this.groove_length,"#DDDDDD");this.available_bar=this.add_bar(3,2,0,"#FFFFFF");this.add_bar(5,1,this.groove_length,"#DDDDDD");this.add_bar(6,1,this.groove_length,"#AAAAAA");this.add_bar(7,1,this.groove_length,"#444444");this.knob=new Element("div",{style:"position:absolute;left:0px;top:"+(-(A.knob_image_height-8)/2)+"px;width:"+A.knob_image_width+"px;height:"+A.knob_image_height+"px;border:0; background-image:url('"+A.knob_image_src+"');background-repeat: no-repeat;background-position: top left;z-index:1;cursor:pointer;"});this.knob.observe("mousedown",function(){this.is_active=1;Event.stop(event)}.bind(this));this.entire_slider.insert({bottom:this.knob});var B=new Element("div",{border:0,style:"position:absolute;left:"+(this.groove_length+10)+"px;top:-5px;white-space:nowrap;"});this.cur_timecode=new Element("span",{}).update("0:00");B.insert({bottom:this.cur_timecode});B.insert({bottom:" / "});this.max_timecode=new Element("span",{}).update("0:00");B.insert({bottom:this.max_timecode});this.entire_slider.insert({bottom:B});this.redraw_helper=new Element("div",{style:"display:none;"});this.entire_slider.insert({bottom:this.redraw_helper});A.container_div.insert({bottom:this.entire_slider});document.observe("mousemove",this.mousemove.bindAsEventListener(this));document.observe("mouseup",this.mouseup.bindAsEventListener(this,A.value_changed_callback));this.reset()},recalc_pix_per_value:function(){this.pix_per_value=this.groove_length/this.max_value},setValue:function(A){if(this.is_active){return 0}this.value=this.clean_up_value(A);if(this.value>this.max_available){this.max_available=this.value}if(this.value>this.max_value){this.max_value=this.value;recalc_pix_per_value()}this.update_controls_from_values();return 1},value_for_cur_knob_pos:function(){return this.knob_pos/this.pix_per_value},mouseup:function(B,A){if(!this.is_active){return }this.is_active=0;this.setValue(this.value_for_cur_knob_pos());if(A){A(this.value)}},clean_up_value:function(A){var A=Math.round(A/this.value_step)*this.value_step;if(A%1){A=Math.round(A*100000)/100000}if(A<0){A=0}if(A>this.max_value){A=this.max_value}return A},mousemove:function(B){if(!this.is_active){return }var C=B.pointerX()-this.entire_slider.cumulativeOffset().left;if(C<0){C=0}if(C>this.max_avail_width){C=this.max_avail_width}if(this.knob_pos!=C){this.knob_pos=C;this.knob.style.left=(this.knob_pos-this.knob_image_offset)+"px";var A=this.clean_up_value(this.value_for_cur_knob_pos());this.cur_timecode.update(this.format_time(A));this.call_knob_pos_callback(A)}},error:function(A){alert(" Error:  "+A);this.is_active=0}});
