var maxY = 0 ;
var curY = 0 ;
var step = 200 ;
var wnd, lyr;
var aup, adn;

function initScroll(strDiv) {

  if (!strDiv || strDiv.length==0) strDiv = "lyrid" ;
  
  aup = document.getElementById("arrowupid") ;
  adn = document.getElementById("arrowdownid") ;
  
  resetScroll(strDiv) ;
}

function resetScroll(strDiv) {

  wnd = document.getElementById("wndid") ;
  lyr = document.getElementById(strDiv);

  //alert(strDiv+" is "+lyr) ;  

  lyr.style.top  = this.y = 0 ;
  lyr.style.left = this.x = 0 ;

  curY = 0 ;
  
  maxY = (lyr.offsetHeight - wnd.offsetHeight > 0)? lyr.offsetHeight - wnd.offsetHeight: 0;
  
  bScroll = (maxY>0) ;
  
  setVisible(aup, false) ;
  setVisible(adn, bScroll) ;
}

function up() { doScroll(-1) ; }
function down() { doScroll(1) ; }

function doScroll(dir) {

  if (bScroll) {
   
    if (dir<0 && curY>0) {
      curY -= 1 ;
      curY = curY-(curY%step) ;
      
      if (curY==0) {
        setVisible(aup, false) ;
      }
      setVisible(adn, true) ;
    }
  
    if (dir>0 && curY<maxY) {
      curY+= step ;
      if (curY>maxY) {
        curY = maxY ;
        setVisible(adn, false) ;
      }
      setVisible(aup, true) ;
    }

    lyr.style.top = -curY+"px" ;
  }
}

function setVisible(oDiv, bFlag) {

  oDiv.style.visibility = (bFlag ? "visible" : "hidden") ;
}


