var ScrollUpStatus = "false";


window.onload = function ReadCookie() {
  if (document.cookie) {                 
    var bez = "CurrentPosition=";
	  var arr = document.cookie.split(';');
	  for(var i=0; i < arr.length; i++)
    {
		  var a = arr[i];
		  while (a.charAt(0)==' ') a = a.substring(1,a.length);
		  if (a.indexOf(bez) == 0)
      {
        Wert = a.substring(bez.length,a.length);
      
        var y = parseInt(Wert);
        if (isNaN(y)) return;    
        if (y > 126) y = 126;
    
        if (((document.getElementById("center").offsetHeight+126-22) < self.innerHeight) && (y!=126)) return;
        if (document.getElementById("center").offsetHeight < self.innerHeight)
          document.getElementById("center").style.marginBottom = (self.innerHeight - document.getElementById("center").offsetHeight +1)+"px";
    
        window.scrollTo(0, y);                               
        ScrollDown();
        
        break;
      }
	  }
  }
}



window.onscroll = function ShowHideScrollUp() {
    if (YPosition() < 126) {
      document.getElementById("up").style.display = "none"; 
    } else if (ScrollUpStatus=="false") {
      document.getElementById("up").style.display = "block";           
    }  
}


function YPosition() {
  var y = 0;                                       
  if (window.pageYOffset) {
    y = window.pageYOffset;
  } else if (document.body && document.body.scrollTop) {
    y = document.body.scrollTop;
  }
  return y;
}


function ScrollDown() {  
  var y = YPosition();
   
  if (y < 126) {          
    window.scrollBy(0, Math.ceil((-y*y+15876)/5000) );     
    setTimeout("ScrollDown()", 10);                            
  }
}


function ScrollUp() { 
  var y = YPosition();
  ScrollUpStatus = "true";
  document.getElementById("up").style.display="none";
        
  if (y>0) {        
    window.scrollBy(0, -(Math.ceil(y/20)) ); 
    setTimeout("ScrollUp()", 10);                           
  } else {
    ScrollUpStatus = "false";
  }
}


function SetCookie() {
  var Verfallsdatum = new Date();                        
  var Verfallszeit = Verfallsdatum.getTime() + 2000; 
  Verfallsdatum.setTime(Verfallszeit);
  
  var y = YPosition();
  
  document.cookie = "CurrentPosition=" + y + "; expires=" + Verfallsdatum.toGMTString();
}
