/*
  SliderBarClass, used for making a tabbed styled browser
  author: jack@inex.nl
  last update: 15/03/2004
  (c) 2004 Info Pinnacle BV
*/

function SliderBarClass(){
  
  // public interface
  this.Init=Init;
  this.StartDrag=StartDrag;
  this.EndDrag=EndDrag;
  this.Drag=Drag;
  this.SetPosition=SetPosition;
  this.GetPosition=GetPosition;
  this.UseSlider=UseSlider;
  this.IsDragging=IsDragging;
  
  //private variables
  var theObjectName="";
  var theValue=0;
  var isHorizontal;
  var dragging=false;
  var theOffset1=0;
  var theSliderBarPixels=100;
  var theSliderPixels=10;
  var theOffset2=0;
  var startSliderBarP=0;
  var sliderInUse=false;
  
  //initiate object
  //  aObjectName       -> pass unique name for the object to the object
  //  aIsHorizontal     -> define if slider is horizontal or fertical (boolean)
  //  aOffset1          -> left or top (depending on aIsHorizontal boolean) starting point of slider widget 
  //  aSliderBarPixels  -> movement range of widget
  //  aSliderPixels     -> actual width or height(...) of the widget
  //  aOffset2          -> right or bottom(...) end point of sliderwidget
  function Init(aObjectName,aIsHorizontal, aOffset1, aSliderBarPixels, aSliderPixels, aOffset2){
    theObjectName=aObjectName;
    theOffset1=aOffset1;
    theSliderBarPixels=aSliderBarPixels;
    theSliderPixels=aSliderPixels;
    theOffset2=aOffset2;
    isHorizontal = aIsHorizontal;
    
    if(isHorizontal)
      startSliderBarP=document.getElementById(theObjectName+"BarDiv").style.pixelLeft;
    else
      startSliderBarP=document.getElementById(theObjectName+"BarDiv").style.pixelTop;
  }
  
  // (dis)activate usage of slider ((dont)accept mouseevents)
  function UseSlider(aBool){sliderInUse=aBool;}
  
  //returns if the slider is currently being dragged
  function IsDragging(){return dragging;}
  
  //start dragging
  function StartDrag(aStartP){
    if(sliderInUse){
      dragging=true;
      //document.getElementById(theObjectName+"Div").style.className="cwc"+theObjectName+"Div-a";
      //status="cwc"+theObjectName+"Div-a";
      Drag(aStartP);
    }
  }
  
  //end dragging
  function EndDrag(aValue){
    dragging=false;
    //document.getElementById(theObjectName+"Div").style.className="cwc"+theObjectName+"Div";
  }
  
  //get the position of the widget
  function GetPosition(){
    return theValue;
  }
  
  //update the position of the widget, during sliderdragging
  function Drag(newP){
    if(dragging){
      var newPos=newP-startSliderBarP-(theSliderPixels/2);
      if(newPos>theSliderBarPixels-theOffset2)newPos=theSliderBarPixels-theOffset2;
      if(newPos<theOffset1)newPos=theOffset1;
      if(isHorizontal)document.getElementById(theObjectName+"Div").style.pixelLeft=newPos;
      if(!isHorizontal)document.getElementById(theObjectName+"Div").style.pixelTop=newPos;
      theValue=(newPos-theOffset1)/(theSliderBarPixels-theOffset1-theOffset2);
    }
  }
  
  //update widget position externaly
  function SetPosition(aValue){
    if(!dragging){
      theValue=aValue;
      var newPos=theOffset1+aValue*(theSliderBarPixels-theOffset1-theOffset2);
      if(newPos<theOffset1)newPos=theOffset1;
      if(isHorizontal)document.getElementById(theObjectName+"Div").style.pixelLeft=newPos;
      if(!isHorizontal)document.getElementById(theObjectName+"Div").style.pixelTop=newPos; 
    }
  }
}