// Script taken from http://stevelosh.com/blog/

var h2s = null;
function place_scrolly_header() {
    var c = 25;
    var e = $(window).scrollTop();
    var d = null;
    var a = null;
    var b = null;
    h2s.each(function() {
        var h = $(this).position()["top"] - c;
        if (e < h) {
            return false
        }
        b = h;
        d = $(this).html().replace(/&nbsp;/g, " ");
        var f = e - (b + c);
        a = f / c;
        if (a > 1) {
            a = 1
        }
        if (a > 0.99) {
            var j = $(this).nextAll("h2");
            if (j.length) {
                var i = j.first().position()["top"];
                var g = i - e;
                if (g <= c * 2) {
                    a = 1 / (c - g / 3)
                }
            }
        }
    });
    $("#scrolling-header").css({opacity:a}).css("left", h2s.first().position()["left"] - 140).html(d)
}
$(function() {
    $("body").append('<div id="scrolling-header"></div>');
    h2s = $("#main article h2");
    $(window).scroll(function() {
        place_scrolly_header()
    });
});
