// The methods in this file are intended to be used only for
// Spinbox Control defined in spinbox.htc using behavior.
// Only SetContinuousSpin() method is intended to be called
// externally.  Other methods are for internal support only.

// global constants needed
var INTERVAL_INITIAL = 500;
var INTERVAL_FINAL = 10;
var INTERVAL_RATIO = 0.75;

// global variables needed
var timer;
var interval;

// calls spinbox's method to actually spins up
function Increment(id)
{
  document.all.item(id).SpinUp();
  
  UpdateInterval();
  timer = setTimeout("Increment('" + id + "')", interval);
}

// calls spinbox's method to actually spins down
function Decrement(id)
{
  document.all.item(id).SpinDown();
  
  UpdateInterval();
  timer = setTimeout("Decrement('" + id + "')", interval);
}

// continuously spins up while up arrow is pressed
function SpinUp()
{
  var id = event.srcElement.id;
  timer = setTimeout("Increment('" + id + "')", interval);
}

// continuously spins down while down arrow is pressed
function SpinDown()
{
  var id = event.srcElement.id;
  timer = setTimeout("Decrement('" + id + "')", interval);
}

// when stop spinning, clear the timer
// so that no spin up or down happens
function StopSpin()
{
  if(timer != null)
  {
    clearTimeout(timer);
	timer = null;
	interval = INTERVAL_INITIAL;
  }
}

function UpdateInterval()
{
  if(interval < INTERVAL_FINAL)
    return;
	
  interval = interval * INTERVAL_RATIO;
}

// sets up spin control to be continuously spins up
// or down while up arrow or down arrow is pressed
function SetContinuousSpin(spin_box)
{
  //spin_box = document.all.item(id);
  spin_box.onincrement = SpinUp;
  spin_box.ondecrement = SpinDown;
  spin_box.onspincompleted = StopSpin;
  
  timer = null;
  interval = INTERVAL_INITIAL;
}

