// (c) 2007 KystAtlas AS (Hans Martin Mohn)

gtAssert("addGTGlobalHandler != null");function gtBeSliderKnob(element,track,image_down,image_active,tooltip,disabled,min_value,max_value,horizontal)
{if(typeof(element.m_image_up)!="undefined")
return;addGTHandlers(element);addGTHandlers(track);element.style.cursor=(disabled)?"auto":"pointer";track.onresize=function()
{var knob=this.m_knob;knob.m_origo_x=gtGetLeft(this);knob.m_origo_y=gtGetTop(this);if(knob.m_horizontal)
{knob.m_slider_range=gtGetWidth(this)-gtGetWidth(knob);knob.m_slider_min=gtGetLeft(this);knob.m_slider_max=knob.m_slider_min+knob.m_slider_range;}
else
{knob.m_slider_range=gtGetHeight(this)-gtGetHeight(knob);knob.m_slider_min=gtGetTop(this);knob.m_slider_max=knob.m_slider_min+knob.m_slider_range;}};track.gtMouseUp=function(evt){return this.m_knob.gtMouseUp(evt);};track.gtMouseMove=function(evt){return this.m_knob.gtMouseMove(evt);};element.ondragstart=function(evt)
{alert("dragStart");gtCancelBubble(evt);return gtPreventDefault(evt);};element.gtMouseDown=function(evt)
{if(this.m_disabled)
return false;var x=evt.gtX-this.m_body_margin_x;var y=evt.gtY-this.m_body_margin_y;this.m_ref_pos=(this.m_horizontal)?x-gtGetLeft(this):y-gtGetTop(this);this.m_button_down=true;this.src=this.m_image_down;if(this.onPress)
this.onPress(this.getValue());gtSetMouseCapture(this,true);gtCancelBubble(evt);return gtPreventDefault(evt);};element.gtMouseUp=function(evt)
{gtSetMouseCapture(this,false);if(this.m_disabled)
return false;src=this.m_image_up;this.m_button_down=false;if(this.onRelease)
this.onRelease(this.getValue());gtCancelBubble(evt);return gtPreventDefault(evt);};element.gtMouseMove=function(evt)
{if(this.m_disabled)
return false;if(!this.m_button_down)
return gtPreventDefault(evt);var x=evt.gtX-this.m_body_margin_x;var y=evt.gtY-this.m_body_margin_y;var pos=(this.m_horizontal)?x-this.m_ref_pos:y-this.m_ref_pos;pos=Math.max(Math.min(pos,this.m_slider_max),this.m_slider_min);this.setPosition(pos);if(this.m_cur_pos!=pos&&this.onMove)
{this.m_cur_pos=pos;this.onMove(this.getValue());}
else this.m_cur_pos=pos;return gtPreventDefault(evt);};element.gtMouseOver=function()
{if(this.m_disabled||this.m_busy)
return false;if(this.m_image_active)
this.src=this.m_image_active;return false;};element.gtMouseOut=function()
{if(this.m_disabled||this.m_busy)
return false;if(this.m_image_active!==null)
this.src=this.m_image_up;return false;};element.getValue=function()
{var knob_pos=this.m_horizontal?this.m_cur_pos-this.m_slider_min:this.m_slider_max-this.m_cur_pos;var knob_pos_relative=knob_pos/this.m_slider_range;var val=Math.floor(this.m_min_value+knob_pos_relative*this.m_range_value);return val;};element.setValue=function(value)
{var value_diff=value-this.m_min_value;var fraction=value_diff/this.m_range_value;var offset=fraction*this.m_slider_range;var pos=(this.m_horizontal)?this.m_slider_min+offset:this.m_slider_max-offset;pos=Math.max(Math.min(pos,this.m_slider_max),this.m_slider_min);this.setPosition(pos);this.m_cur_pos=pos;};element.setPosition=function(pos)
{if(this.m_horizontal)
gtSetLeft(this,pos-this.m_origo_x);else
gtSetTop(this,pos-this.m_origo_y);};element.showDisabled=function showDisabled(disabled)
{var transparency=(disabled)?0.3:0.0;gtSetTransparent(this,transparency);gtSetTransparent(this.m_track,transparency);};element.setDisabled=function setDisabled(d)
{this.m_disabled=d;this.showDisabled(this.m_busy||this.m_disabled);};element.setBusy=function setBusy(b)
{this.m_busy=b;this.showDisabled(this.m_busy||this.m_disabled);};gtBeSliderKnob.HORIZONTAL=true;gtBeSliderKnob.VERTICAL=false;track.m_knob=element;element.m_horizontal=(horizontal)?true:false;element.m_min_value=parseFloat(min_value);element.m_max_value=parseFloat(max_value);element.m_range_value=max_value-min_value;element.m_image_up=element.src;element.m_track=track;element.m_disabled=false;element.m_busy=false;var s=top.document.body.style;element.m_body_margin_x=s.marginLeft.length>0?parseInt(s.marginLeft):0;element.m_body_margin_y=s.marginTop.length>0?parseInt(s.marginTop):0;element.m_body_margin_x=0;element.m_body_margin_y=0;element.title=tooltip;element.alt=tooltip;element.m_ref_pos=0;element.m_cur_pos=0;element.m_button_down=false;var slash_pos=element.src.lastIndexOf("/");if(image_down!==null)
element.m_image_down=(slash_pos<0)?image_down:element.src.substr(0,slash_pos+1)+image_down;else
element.m_image_down=null;if(image_active!==null)
element.m_image_active=(slash_pos<0)?image_active:element.src.substr(0,slash_pos+1)+image_active;else
element.m_image_active=null;element.setDisabled((typeof(disabled)!="undefined")?disabled:false);track.onresize();}
function double2Slider(v_min,v_max,value,s_min,s_max)
{value=Math.min(Math.max(value,v_min),v_max);return(Math.log(value)-Math.log(v_min))/(Math.log(v_max)-Math.log(v_min))*(s_max-s_min)+s_min;}
function slider2Double(v_min,v_max,s_min,s_max,value)
{var lgMin=Math.log(v_min);var lgMax=Math.log(v_max);return Math.exp((value-s_min)/(s_max-s_min)*(lgMax-lgMin)+lgMin);}