

function LD_SliderJS()
{

  return {
  
    dragging: false,
    dragObj: null,
    maxval: null,
    minval: null,
    callbackfunc: null,
    lastval:-1,
   
    redraw : function()
    {
    },
 
    findAbsXPos : function(obj)
    {
      retval=0;
      while(obj)
      {
        retval=retval+obj.offsetLeft;
        obj=obj.offsetParent;
      }
      return retval;
    },
  
    moveSlider : function(e)
    {
      if (!e) e=window.event;
      if (this.dragObj!=null)
      {
        lbound=this.findAbsXPos(this.dragObj.parentNode);
        rbound=lbound+this.dragObj.parentNode.clientWidth-this.dragObj.clientWidth;
        newpos=e.clientX-(this.dragObj.clientWidth/2);
        if (newpos>=lbound && newpos<=rbound)
        {
          this.dragObj.style.left=newpos+'px';
          newpos=newpos-lbound;
          totalWidth=rbound-lbound;
          
          numIntervals=this.maxval-this.minval;
          pixPerInterval=totalWidth/numIntervals;
          newMappedPos=Math.round(newpos/pixPerInterval);
          if (newMappedPos!=this.lastval)
          {
            eval(this.callbackfunc+"("+newMappedPos+",'"+this.dragObj.id+"')");
            this.lastval=newMappedPos;
          }
        }
      }
    },
  
    dragSlider : function(obj, min, max, callback)
    {
        this.dragObj=obj;
        this.maxval=max;
        this.minval=min;
        this.callbackfunc=callback;
    },
    
    releaseSlider : function()
    {
      this.dragObj=null;
    },
    
    setCurrentPos : function(min, max, iMappedVal, dragObj)
    {
      if (iMappedVal<=max && iMappedVal>=min)
      {
        lbound=this.findAbsXPos(dragObj.parentNode);
        rbound=lbound+dragObj.parentNode.clientWidth-dragObj.clientWidth;
        totalWidth=rbound-lbound;
        numIntervals=max-min;
        pixPerInterval=totalWidth/numIntervals;
        newpos = lbound + ( (iMappedVal - min) * pixPerInterval );
        dragObj.style.left=newpos+'px';
      }
    }
  
  }

}


