function move_scroller(classname) {
    var width = $("." + classname).width();

    var scroll_function = function() {
        var window_top = $(window).scrollTop();
        var anchor_top = $("." + classname + " .scroller-anchor").offset().top;
        var scroller = $("." + classname + " .scroller-inner");
        
        if (window_top > anchor_top) {
            scroller.css({
              position: "fixed",
              top: "0px",
              zIndex: "10",
              width: width + "px"
            })
        } else {
          if (window_top <= anchor_top) {
              scroller.css({
                position: "relative",
                top: ""
              })
          }
        }
    };
    $(window).scroll(scroll_function);
    scroll_function();
}

(function(){
    $('.scroller').each(function(){
        var new_class = 'scroller_' + (new Date()).getMilliseconds();
        $(this).addClass(new_class);
        var html = $(this).html();

        $(this).html(
            $('<div/>')
                .addClass("scroller-anchor")
                .after($('<div/>')
                    .addClass("scroller-inner")
                    .html(html)
                )
        );

        move_scroller(new_class);
    });
})();
