jQuery, next, prev, cycling to first and last
<p>Sorry for this confusing title.
What i'm trying to do is a function (or just a simple way), which will do simple <strong>.next()</strong>, but if there's no next element, match first. And the same for <strong>.prev()</strong> - if there's no previous element, match last.
So i made it this way:</p>

<pre><code>var current_selected = getSelected();
if(current_selected.length) {
    var prev = current_selected.prev();
    if(prev.length) {
        setSelected(prev);
        return;
    }
}
setSelected(getLast());
</code></pre>

<p>But i don't really like it, i think there's some pretty way do it. Any thoughts?
(<strong>getSelected</strong> and <strong>getLast</strong> returns jQuery objects.</p>
