var SCROLLTIMER = 3;
var SCROLLSPEED = 3;
var nitem = 7;
var itemheight = 27;
var maxitem = 29;
var maxitem_cancer = 11;

function scrollContent(id,dir, max) {
  var div = document.getElementById(id);
  clearInterval(div.timer);
  var limit;
  if(dir == -1) { limit = 0; } 
  else { 
    if(id=='biomarkermenu') limit = (max-nitem) * itemheight; 
    else if(id=='cancermenu') limit = (max-nitem) * itemheight; 
  }
  // alert('scroll init');
  div.timer = setInterval( function() { scrollAnimate(div,dir,limit) }, SCROLLTIMER);
}

function scrollAnimate(div,dir,limit) {
  div.style.top = div.style.top || '0px';
  var top = parseInt(div.style.top.replace('px',''));
  if(dir == 1) {
  	if(limit - Math.abs(top) <= SCROLLSPEED) {
  	  clearTimeout(div.timer);
  	  div.style.top = '-' + limit + 'px';
  	} else {
  	  div.style.top = (top - SCROLLSPEED) + 'px';
  	}
  } else {
  	if(Math.abs(top) - limit <= SCROLLSPEED) {
  	  clearTimeout(div.timer);
  	  div.style.top = limit + 'px';
  	} else {
  	  div.style.top = (top + SCROLLSPEED) + 'px';
  	}
  }
}

function cancelScroll(id, max) {
  // alert('cancel scroll');
  var div = document.getElementById(id);
  div.style.top = div.style.top || '0px';
  var top = parseInt(div.style.top.replace('px',''));
  top = Math.round((Math.abs(top) / itemheight));
  if(id=='biomarkermenu'){
    if (top > (max-nitem)) top = max - nitem;
  } else {
    if (top > (max-nitem)) top = max- nitem;
  }
  top = top * itemheight;
  div.style.top = '-' + top + 'px';
  clearTimeout(div.timer);
}

