jQuery Show/Hide Repeat Dance
<p>I have a jQuery Cycle with pager that creates an unordered list and, when clicked on, changes the slide. I am attempting to use the unordered list to also show/hide associated text for each of the slides. And, to complicate the process further, there is a set of default text for when there is no text associated to the slide.</p>

<p>The html looks like this:</p>

<pre><code>&lt;div class="slideshow"&gt;
  &lt;img src="img1.png" /&gt;
  &lt;img src="img2.png" /&gt;
  &lt;img src="img3.png" /&gt;
&lt;/div&gt;
&lt;div class="slidetxt slide-3-text" style="display:none;"&gt;Text to appear with slide 3&lt;/div&gt;
&lt;div class="slidetxt slide-1-text"&gt;Text to appear with slide 1&lt;/div&gt;
&lt;div class="slidetxt defaultcontent" style="display:none;"&gt;This is the default text for the page.&lt;/div&gt;
</code></pre>

<p>The jQuery looks like this:</p>

<pre><code>jQuery(document).ready(function() {
    jQuery('.slideshow')
    .after('&lt;ul id="slidenav" /&gt;')
    .cycle({
        fx: 'fade',
        timeout: 0,
        pager: '#slidenav',
        pagerAnchorBuilder: function(idx, slide) {
            return '&lt;li&gt;&lt;a href="#"&gt;&lt;/a&gt;&lt;/li&gt;';
        }
    });
    jQuery('#slidenav li a').click(function(){
        var index = jQuery(this).parent('li').index();
        index = index + 1;
        var slidetxt = ".slide-"+index+"-text";
        jQuery(".slidetxt").hide("slow", function(){
            if(jQuery(slidetxt).length){
                jQuery(slidetxt).show("slow");
            }else{
                jQuery(".defaultcontent").show("slow");
            }           
        });
    });
});
</code></pre>

<p>For some reason, clicking on the third nav button always works fine but clicking on the second one always shows the default text and then immediately hides it and then shows it again and clicking on the first nav button sometimes works ok and sometimes does the show/hide/show dance.</p>

<p>I am guessing that it is something to do with jQuery thinking it has completed the action before it really has but maybe it's just my sloppy code! :-) All help will be greatly appreciated!! Thanks.</p>
