var nav_scroll_timer;

function nav_scroll()
{
    setTimeout("nav_scroll_start()", 250);
}

function nav_scroll_start()
{
    // cancel an in-progress timer and restart (if there is one)
    if ( typeof(nav_scroll_timer) != "undefined" )
	clearInterval (nav_scroll_timer);
    nav_scroll_timer = setInterval(nav_scroll_step, 10);
}

function UserException(message) {
   this.message = message;
   this.name = "UserException";
}

function nav_scroll_step()
{
    var curr_y; 
    var nav_y;
    var new_y;
    var diff;
    var dy = 5;
    var final_y;
    var nobj = $('nav');
    if ( ! nobj ) return;

    nav_y = nobj.offsetTop;
    curr_y = (document.all) ? document.body.scrollTop : window.pageYOffset;
    final_y = (curr_y + 95);

    if ( nav_y == final_y )
    {
	clearInterval (nav_scroll_timer);
	nav_scroll_timer = undefined;
	return;
    }

    diff = Math.abs(final_y - nav_y);

    if ( diff > 75 ) dy = 25;
    else if ( diff > 25 ) dy = 10;
    else if ( diff > 5 ) dy = 5;
    else dy = 2;

    if ( diff < dy )
	dy = diff;

    if ( nav_y > final_y ) dy *= -1;
    new_y = nav_y + dy;

    nobj.style.top = new_y + "px";

    /*
    myUserException = new UserException(
	"nav_scroll()" + nobj.style.top + " curry=" + curr_y
	+ " nobj.style.top = " + nobj.offsetTop
	+ " nav_y=" + nav_y 
	+ " final_y=" + final_y
	+ " dy=" + dy
	+ " new_y=" + new_y);
    throw myUserException;
    */
}
