jQuery.fn.paginate = function(settings) {
    return this.each(function() {
        var el = $(this),
            height_short = el.height(),
            copy = el.clone(),
            height_full,
            pages, page_menu,
            links = new Array();
        copy.css('overflow', 'auto')
            .css('height', 'auto')
            .hide()
            .appendTo(el);
        height_full = copy.height();
        copy.remove();

        pages = Math.floor(height_full / height_short);
        pages += height_full % height_short ? 1 : 0;
        if (pages === 1)
        {
            return;
        }

        settings = jQuery.extend({
            startingPage: 1,
            animateSpeed: 1600,
            easeMethod: 'easeOutQuint',
            linkSeparator: ' | ',
            currentClass: 'current',
            divClass: 'paginate'
        });

        // make links
        page_menu = $('<div class="' + settings.divClass + '"></div>');
        var link_class;
        for (var i = 1; i <= pages; ++i)
        {
            link_class = i === settings.page ? ' class="' + settings.currentClass + '"' : '';
            links.push('<a page="' + i + '"' + link_class + '>' + i + '</a>');
        }
        page_menu.append(links.join(settings.linkSeparator));

        // program links
        $('a', page_menu)
            .click(function() {
                var link = $(this),
                    page = link.attr('page'),
                    index = page - 1,
                    offset;
                $('a.' + settings.currentClass, page_menu).removeClass(settings.currentClass);
                link.addClass(settings.currentClass);
                if (page == pages)
                {
                    offset = height_full - height_short;
                }
                else
                {
                    offset = index * height_short;
                }

                el.animate(
                    {
                        scrollTop: offset
                    }, 
                    settings.animateSpeed,
                    settings.easeMethod
                );
            })
            .eq(settings.startingPage - 1).click();
        el.after(page_menu);
        page_menu.attr('top', ''); //IE6 bug
    });
};
