jQuery automate multiple scripts for multiple divs
<p>in jQuery I always encounter alot of double work. I mean, I write the same thing for different divs.</p>

<p>I have the following code:</p>

<pre><code>var about = $('#about').offset().top - parseFloat($('#about').css('margin-top').replace(/auto/, 0));
var education = $('#education').offset().top - parseFloat($('#education').css('margin-top').replace(/auto/, 0));
var work = $('#work').offset().top - parseFloat($('#work').css('margin-top').replace(/auto/, 0));
</code></pre>

<p>and</p>

<pre><code>$(window).scroll(function (event) {
    // what the y position of the scroll is
    var y = $(this).scrollTop();

    // whether that's below the form
    if (y &gt;= about) {
        // if so, ad the fixed class
        $('#nav li').removeClass('current');
        $('.ab_about').addClass('current');
    } else {
        // otherwise remove it
        $('.ab_about').removeClass('current');
    }

    // whether that's below the form
    if (y &gt;= education) {
        // if so, ad the fixed class
        $('#nav li').removeClass('current');
        $('.ab_education').addClass('current');
    } else {
        // otherwise remove it
        $('.ab_education').removeClass('current');
    }

    // whether that's below the form
    if (y &gt;= work) {
        // if so, ad the fixed class
        $('#nav li').removeClass('current');
        $('.ab_work').addClass('current');
    } else {
        // otherwise remove it
        $('.ab_work').removeClass('current');
    }

});
</code></pre>

<p>You can say that if I have 20 of those items, it's gonna be a very long script :P
Any idea on how to automate things and make it smaller. I tried something with the .each method, but that was a dead end for me.</p>

<p>Ty</p>
