jQuery load and append issue
<p>im getting a little issue here. I have a wordpress theme that i need to add an infinite scroll effect. Ok, its working, but it doesnt look work properly. I set the current page and the number of pages, but it keeps adding the second page every time i reach the bottom.</p>

<p>What im doing wrong?</p>

<p>Ps.: I have tried the inifite-scroll plugin for wordpress, and it dont works with my template. Thanks!</p>

<pre><code>$(function() {
    var currentPage = 1;
    var numPages = Math.ceil(pages / 4);
    var browserName = "";
    var ua = navigator.userAgent.toLowerCase();
    if (ua.indexOf("opera") != -1) {
        browserName = "opera";
    } else if (ua.indexOf("msie") != -1) {
        browserName = "msie";
    } else if (ua.indexOf("safari") != -1) {
        browserName = "safari";
    } else if (ua.indexOf("mozilla") != -1) {
        if (ua.indexOf("firefox") != -1) {
            browserName = "firefox";
        } else {
            browserName = "mozilla";
        }
    }
    $(window).scroll(function() {
        if (browserName != "safari") {
            var curScrollPos = $('html').scrollTop();
        }
        else {
            var curScrollPos = $('body').scrollTop();
        }
        if (curScrollPos &gt; 218) {
            $("#sidebar").addClass("open");
        }
        if (curScrollPos &lt; 218) {
            $("#sidebar").removeClass("open");
        }
        var scrollBottom = $(document).height() - $(window).height() - $(window).scrollTop();
        if (scrollBottom == 0) {
            if (currentPage &lt; numPages) {
                $("&lt;div&gt;").load("page/" + (currentPage + 1), function() {
                    var newPosts = $(this).find("#content").html();
                    $("#content").append(newPosts);
                });
                currentPage++;
            }
            else {
            }
        }
    });
    // Infinite Scroll
});​
</code></pre>
