var body, menu;

function init() {
  if ( !( menu || body ) )
    if ( document && document.getElementsByTagName && window && window.innerHeight )
      if ( ( menu = document.getElementById("menu") ) && ( body = document.getElementsByTagName("body").item(0) ) ) {
        var temp = 136;
        menu = { element:menu, top:temp, y:temp, timer:false };
        step();
      }
  onload = document.onload = null;
}

function step() {
  if ( !menu ) return false;
  else if ( !body.scrollTop && document.documentElement.scrollTop ) body = document.documentElement;
  var menuBottom   = menu.y + menu.element.clientHeight;
  var windowBottom = window.innerHeight + body.scrollTop;
  var t = menu.y;
  if ( window.innerHeight >= menu.element.clientHeight ) {
    if ( menu.y > body.scrollTop || menuBottom < windowBottom )
      t += ( body.scrollTop - menu.y )/4;
  } else {
    if ( menu.y > body.scrollTop )
      t += ( body.scrollTop - menu.y )/4;
    else if ( menuBottom < windowBottom )
      t += ( windowBottom - menuBottom )/4;
  }
  if ( t < menu.top-1 ) t = menu.top;
  menu.element.style.top = ( menu.y = t )+"px";
  menu.timer = setTimeout("step()", 10);
}
onclick=step;

onload   = document.onload   = init;
onunload = document.onunload = function() { if ( menu && menu.timer ) window.clearTimeout(menu.timer); }