var target_x = 3;
var target_y = 0;
var begin_top = 175;
var fm_id='floatdiv';
var floating_menu = null;
var fm_shift_x, fm_shift_y, fm_next_x, fm_next_y;
var fm_height = 0;
var sliderCell = null;
var sTop = 0;

function right_onload()
{
  setTimeout("floater_init();", 50);
}
function floater_init()
{
  floating_menu =
    document.getElementById
    ? document.getElementById(fm_id)
    : document.all
      ? document.all[fm_id]
      : document.layers[fm_id];

  fm_height = floating_menu.offsetHeight;
  sliderCell = document.getElementById("slidercell")
  compute_shifts();

  if (document.layers)
  {
    // Netscape 4 cannot perform init move
    // when the page loads.
    fm_next_x = 0;
    fm_next_y = 0;
  }
  else
  {
    fm_next_x = fm_shift_x + target_x;
    fm_next_y = fm_shift_y + target_y;
    move_menu();
  }

  float_menu();
}
function move_menu()
{
  if (document.layers)
  {
    floating_menu.top = fm_next_y;
  }
  else
  {
    floating_menu.style.top = fm_next_y + 'px';

  }
}
function pageHeight()
{
  return window.innerHeight != null? window.innerHeight : document.documentElement && document.documentElement.clientHeight ?  document.documentElement.clientHeight : document.body != null? document.body.clientHeight : null;
}
function compute_shifts()
{
  //fm_shift_y = the middle of the screen (based on scroller) - the height of the floater/2
  sTop = document.body.scrollTop;
  if(pageHeight() + sTop - floating_menu.offsetHeight >= sliderCell.offsetHeight-40)
  {
    //bottom position
    fm_shift_y = sliderCell.offsetHeight - floating_menu.offsetHeight;
  }
  else if(sTop - begin_top >= 0)
  {
    //in between
    offset = pageHeight()-floating_menu.offsetHeight;
    if(offset > 0) {offset = offset/2;}
    var shift = sTop - begin_top + offset;
    if(shift < 0) { shift = 0; }
    fm_shift_y = shift;
  }
  else
  {
    //top position
    fm_shift_y = 0;
  }

}

function float_menu()
{
  var step_x, step_y;

  compute_shifts();
  step_y = (fm_shift_y + target_y - fm_next_y) * .07;
  if (Math.abs(step_y) < .5)
      step_y = fm_shift_y + target_y - fm_next_y;

  if (Math.abs(fm_next_y) > sliderCell.offsetHeight- floating_menu.offsetParent.offsetHeight)
  {
    if (step_y < 0)
    {
      fm_next_y += step_y;
      move_menu();
    }
    else
    {
      move_menu();
    }
  }
  else if (Math.abs(step_x) > 0 || Math.abs(step_y) > 0)
  {
    fm_next_y += step_y;
    move_menu();
  }
  setTimeout('float_menu()', 20);
}