function activateFancyScrolling(content_offset, $content_scrollbar_mode, 
      $div_fixed, $div_main, $div_content) {
    if ($div_fixed.size() == 0 || $div_main.size() == 0 
		|| $div_content.size() == 0) {
      return 0;
    }
    var getContentOverlap = function() {
        var val = $div_content.children('div').get(0).offsetHeight 
                  - $div_content.height()
                  - parseInt($div_content.css('padding-top'));
        if (val < 0) return 0;
        return val;
    }
    var getViewOverlap = function() {
        var val = content_offset
                  + $div_content.height() 
                  + parseInt($div_content.css('padding-top'))
                  + parseInt($div_content.css('padding-bottom')) 
                  - $(window).height();
        if (val < 0) return 0; 
        return val;
    }
    var getFooterOverlap = function() {
        var val = $div_main.height() - $(window).height() - getViewOverlap();
        if (val < 0) return 0;
        return val;
    }
    $div_fixed.css('position', 'fixed');
    $div_fixed.css('width', '100%');
    $div_content.wrapInner('<div style="width:' 
        + $div_content.width() + ';"></div>');
    if ($content_scrollbar_mode != 'visible') 
        $div_content.css('overflow', 'hidden');
    $div_fixed.after('<div id="fsplaceholder" />');
    $("div#fsplaceholder").css('z-index', -10);
    var resize = function() {
        var height = getContentOverlap() + getViewOverlap() 
                     + getFooterOverlap() + $(window).height();
        $("div#fsplaceholder").css('height', height);
    }
    $(window).resize(resize);
    $div_content.children("div").resize(resize);
    resize();
    $(window).scroll(function () { 
        var vol = getViewOverlap();
        var col = getContentOverlap();
        //var scrollpos = document.documentElement.scrollTop;
        var scrollpos = window.pageYOffset;
        if (typeof scrollpos == 'undefined') {
            scrollpos = document.documentElement.scrollTop;
        }
        if (vol > 0) {
            if (scrollpos <= vol) {
                $div_main.css('margin-top', -scrollpos);
                $div_content.get(0).scrollTop = 0;
                return;
            }
        }
        if (scrollpos <= vol + col) {
            $div_main.css('margin-top', -vol);
            $div_content.get(0).scrollTop = 
                scrollpos - vol;
        }
        else {
            $div_main.css('margin-top', -scrollpos + col);
            $div_content.get(0).scrollTop = col;
        }
    });
    if ($content_scrollbar_mode == 'auto') {
        $div_content.mouseenter(function () {
            var s = $div_content.get(0).scrollTop;
            $div_content.css('overflow', 'auto');
            $div_content.get(0).scrollTop = s;
        });
        $div_content.mouseleave(function () {
            $div_content.css('overflow', 'hidden');
        });
    }
    var current_hash = location.hash.replace(/\?.*$/, '');
    if ($div_content.find(current_hash).size() > 0) {
        c = getViewOverlap() - content_offset + parseInt($div_content.css('padding-top'));
        if (c < 0) c = 0;
        p = parseInt($div_content.css('padding-top'));
        $div_content.parents("div").not($div_main).each(function() { p += parseInt($(this).css('padding-top')); })
        window.scrollTo(0, $div_content.find(current_hash).position().top + p + getViewOverlap() - c);
    }
}


