﻿var animated = false;
var dx = 0;
var tout = 0;
function scroll(id, direction, idx, height)
{
    if (direction == 1 && !$(id).getStyle("top"))
        return;
    if (direction == 1 && parseInt($(id).getStyle("top").replace("px", "")) == 0)
        return;
    if (direction == -1 && parseInt($(id).getStyle("top").replace("px", "")) <= -height)
        return;
        
    if (!animated)
    {
        clearTimeout(tout);
        animated = true;
        dx = idx;
        tout = setTimeout("onScrollTimeout('" + id + "', " + direction + ")", 1);
    }
}
function onScrollTimeout(id, direction)
{
    if (dx == 0)
    {
        animated = false;
    }
    else
    {
        var top = parseInt($(id).getStyle("top").replace("px", ""));
        if (direction == -1)
            top = top - ((dx > 1) ? 2 : 1);
        else
            top = top + ((dx > 1) ? 2 : 1);    
        $(id).setStyle({ top: top + "px" });
        dx = dx - ((dx > 1) ? 2 : 1);
        
        tout = setTimeout("onScrollTimeout('" + id + "', " + direction + ")", 1);
    }    
}
