// JavaScript für Scroll-Funtionen
//
// Änderungen:
// 09.07.2006, ecki: Bug entfernt: parseInt("09") wird oktal interpretiert: verwende parseInt("09", 10)
//
// Hält ein HTML-Element beim Scrollen im sichtbaren Bereich
// topOffset: Initialer Abstand des HTML-Elements zum oberen sichtbaren Rand (in Pixel)
// elementHeight: Höhe des HTML-Elementes (in Pixel)
// element: HTML-Element, das immer sichtbar bleiben soll
//          (muß mit style="position:relative;top:0" initialisiert sein)
ka_scroll_lastScrollTop = 0;
function ka_scroll_keepInWindow(topOffset, elementHeight, element) {
    scroll_top = document.body.scrollTop;
    scroll_down = (ka_scroll_lastScrollTop < scroll_top);
    ka_scroll_lastScrollTop = scroll_top;
    window_height = document.body.clientHeight;
    diff_height = window_height - elementHeight;
    low_height = topOffset + elementHeight - window_height;
    up_height = topOffset;
    current_top = parseInt(element.style.top, 10);
    low_diff = scroll_top - low_height - current_top;
    up_diff = scroll_top - up_height - current_top;
    if (scroll_down && (low_diff > 0) && (diff_height < 0)) {
      if (scroll_top < low_height)
        scroll_top = low_height
      element.style.top = scroll_top - low_height;
    } else if ((!scroll_down && (up_diff < 0) && (diff_height < 0)) || (diff_height > 0)) {
      if (scroll_top < up_height)
        scroll_top = up_height;
      element.style.top = scroll_top - up_height;
    }
}
