var BBG_scrollTimer = null;
var BBG_scrollTimeout = 5;
var BBG_scrollStep = 4;

function BBG_startScroll(key, direction) {
   var id = 'bbg_scroll_container_' + key;
   if (!$(id)) {
      return false;
   }
   
   if (BBG_scrollTimer == null) {
      BBG_scrollTimer = setInterval("BBG_onScrollTimeout('" + direction + "', '" + id + "')", BBG_scrollTimeout);
   }
}

function BBG_stopScroll() {
   if (BBG_scrollTimer != null) {
      clearInterval(BBG_scrollTimer);
      BBG_scrollTimer = null;
   }
}

function BBG_onScrollTimeout(direction, key) {
   if ('down' == direction) {
      BBG_scrollDown(key);
   } else if('up' == direction) {
      BBG_scrollUp(key);
   }
}

function BBG_scrollUp(id) {
   if (!$(id)) {
      return false;
   }
   $(id).scrollTop -= BBG_scrollStep;
}

function BBG_scrollDown(id) {
   if (!$(id)) {
      return false;
   }
   $(id).scrollTop += BBG_scrollStep;
}