  var a,b,c;
  var intervalID;
  var IEQuirksMode = true;

 
  function startScrolling()
  {
    checkIEMode();
    intervalID = window.setInterval('scroll()',20);
  }
   
  function isAtBottom()
  {
  
    if (IEQuirksMode)
    {
      a=getDocHeight();
      b=document.body.scrollTop || document.documentElement.scrollTop;
      c=document.body.clientHeight;
    } else  
    {  
      a=document.documentElement.scrollHeight;
      b=document.documentElement.scrollTop;
      c=document.documentElement.clientHeight
    }
      
//    console.log("a=" + a + " b=" + b + " c=" + c);
    return ((a-b)<=c);
  }

  function scroll()
  {
    (isAtBottom())?atBottom():scrollBy(0,1);
  }
    
  function atBottom()
  {
    clearInterval(intervalID);
    setTimeout('scrollTo(0,0)',5000);
    setTimeout('startScrolling()',10000);
  }
  
  function getDocHeight()
  {
    var D = document;
    return Math.max(
        Math.max(D.body.scrollHeight, D.documentElement.scrollHeight),
        Math.max(D.body.offsetHeight, D.documentElement.offsetHeight),
        Math.max(D.body.clientHeight, D.documentElement.clientHeight)
    );
  }
  
  function checkIEMode()
  {
    var mode=document.compatMode;
    if(mode)
    {
      if(mode=='BackCompat')
        IEQuirksMode=true;
      else  
        IEQuirksMode=false;
    }
  }  
  
