var SCROLLTIMER = 3;
var SCROLLSPEED = 3;
var STARTINGOPACITY = 40;
// handles manual scrolling of the content //
function scrollContent(td,id,dir) {
  var div = document.getElementById(id);
  
  if(dir == -1)
  {
	td.style.background = 'url(Images/arrow_btns.png) no-repeat top right';
  }
  else
  {
	td.style.background = 'url(Images/arrow_btns.png) no-repeat bottom right';
  }
  clearInterval(div.timer);
  //alert(div.offsetHeight+' - '+div.parentNode.parentNode.offsetHeight);
  var limit;
  if(dir == -1) {
    limit = 0;
  } else {
    limit = div.offsetHeight - div.parentNode.offsetHeight + 20;
  }
  //alert(limit);
  div.style.opacity = STARTINGOPACITY * .01;
  div.style.filter = 'alpha(opacity=' + STARTINGOPACITY + ')';
  div.timer = setInterval( function() { scrollAnimate(td,div,dir,limit) }, SCROLLTIMER);
}

function scrollAnimate(td,div,dir,limit) {

  div.style.top = div.style.top || '0px';
  var top = div.style.top.replace('px','');
  //alert(div.id);
  if(dir == 1) {
	if(limit - Math.abs(top) <= SCROLLSPEED) {
	  cancelScroll(td,div.id,dir);
	  div.style.top = '-' + limit + 'px';
	} else {
	  div.style.top = top - SCROLLSPEED + 'px';
	}
  } else {
	if(Math.abs(top) - limit <= SCROLLSPEED) {
	  cancelScroll(td,div.id,dir);
	  div.style.top = limit + 'px';
	} else {
	  div.style.top = parseInt(top) + SCROLLSPEED + 'px';
	}
  }
}

// cancel the scrolling on mouseout //
function cancelScroll(td,id,dir) {
	//alert(td.childNodes[0]);
	  if(dir == -1)
	  {
		td.style.background = 'url(Images/arrow_btns.png) no-repeat top left';
	  }
	  else
	  {
		td.style.background = 'url(Images/arrow_btns.png) no-repeat bottom left';
	  }
	  var div = document.getElementById(id);
	  div.style.opacity = 1;
	  div.style.filter = 'alpha(opacity=100)';
	  clearTimeout(div.timer);
}
