jQuery: Rotate through <p>, hiding all but one. Then Repeat
<p>I've got this code to work mostly right. It hides all but one of the <code>&lt;p&gt;</code> tags of a certain class, then rotates to the next one on a click.  I want it to reset when it reaches the last <code>&lt;p&gt;</code> tag, and display the first one again, but it doesn't.  What am I doing wrong? </p>

<p>Here's the javascript code:</p>

<pre><code>$(document).ready(function() {
var curPoem=1;

if ($("h2.title").length==1) { break; }
else { $("h2.title").eq(0).after("\&lt;sup\&gt;\&lt;small style='font-size: 10px; margin: 0 10px; float: right; position: relative; right: 50px; bottom: 30px;' \&gt;Click the title to change the poem\&lt;\/small\&gt;\&lt;\/sup&gt;") }

$("p.lit").not($("p.lit:eq(0)")).hide();
$("p.lit").eq(0).show();
$("h2.title").not($("h2.title:eq(0)")).hide();

$("h2.title").eq(0).bind("click", function()
    {   $("p.lit").not($("p.lit:eq("+curPoem+")")).hide();
        $("p.lit").eq(curPoem).show();

        $("h2.title").eq(0).empty();
        for (i=0; i&lt;$("h2.title").length-1; i++)
        {   $("h2.title").eq(0).append(litTitle[curPoem]);
        }
        document.title=litTitle[curPoem]+" by "+author;

        if (curPoem&lt;$("h2.title").length)
        {   curPoem=(curPoem+1);
        }
        else if (curPoem==$("h2.title").length)
        {   curPoem=1;
        }
    });
});
</code></pre>

<p>The HTML It act's on:</p>

<pre><code>&lt;script type="text/javascript"&gt;
        var author="Bud Robert Berkich";
        var litTitle=["In the End", "Rental Car"];
    &lt;/script&gt;

&lt;div id="content"&gt;
        &lt;h2 class="title"&gt;In the End&lt;/h2&gt;
        &lt;h3 class="author"&gt;Bud Robert Berkich&lt;/h3&gt;
        &lt;hr /&gt;
        &lt;p class="lit"&gt;
            your other  for another for yourself    and not for me  selfish&lt;br /&gt;
            &lt;br /&gt;
            that other  indifferent not for you and now not for me too&lt;br /&gt;
            &lt;br /&gt;
            never   for me  but I never I othered   another selfless&lt;br /&gt;
            &lt;br /&gt;
            (I othered  the same    for you)&lt;br /&gt;
            &lt;br /&gt;
            and now nothing&lt;br /&gt;
            &lt;br /&gt;
            in the end  nothing&lt;br /&gt;
        &lt;/p&gt;
        &lt;h2 class="title"&gt;Rental Car&lt;/h2&gt;
        &lt;p class="lit"&gt;
            4 AM.&lt;br /&gt;
            &lt;br /&gt;
            I find myself&lt;br /&gt;
            in the vicinity&lt;br /&gt;
            of the lake&lt;br /&gt;
            that five years before&lt;br /&gt;
            witnessed&lt;br /&gt;
            "the fishing trip from hell."&lt;br /&gt;
            &lt;br /&gt;
            For me,&lt;br /&gt;
            the beginning of the end.&lt;br /&gt;
            &lt;br /&gt;
            And I'm aware&lt;br /&gt;
            of the fact&lt;br /&gt;
            that if I'm&lt;br /&gt;
            in the middle&lt;br /&gt;
            of no front and back,&lt;br /&gt;
            &lt;br /&gt;
            I can easily&lt;br /&gt;
            slip up a non-gated&lt;br /&gt;
            park entrance&lt;br /&gt;
            unawares.  But&lt;br /&gt;
            &lt;br /&gt;
            as the darkness&lt;br /&gt;
            pushes in&lt;br /&gt;
            and the insects&lt;br /&gt;
            mock me&lt;br /&gt;
            from behind trees&lt;br /&gt;
            I can't see,&lt;br /&gt;
            a feeling&lt;br /&gt;
            &lt;br /&gt;
            hell will be paid.&lt;br /&gt;
            &lt;br /&gt;
            I leave.
        &lt;/p&gt;
        &lt;hr /&gt;
        &lt;p class="lit_bio"&gt;
            Bud Robert Berkich was born in Somerville, New Jersey and raised in Bound Brook, New Jersey.  He is a graduate of Bound Brook High School.  Bud holds an Associate of Arts in Humanities degree from Raritan Valley Community College and a Bachelor of Arts in Liberal Studies degree from Rider University.  He has been writing creatively since the age of eight.  He has had poetry published in The Idiom and a one-act play entitled End Streetpublished in The Rockhurst Review.  Bud is the co-founder and Director of the Somerset Poetry Group in Bridgewater, New Jersey.  He currently lives in Manville, New Jersey.
        &lt;/p&gt;
    &lt;/div&gt;
</code></pre>
