title: Function only works on second click, then works fine?
body: <p>I am having trouble with a navigation menu I have created. Basically, the navigation consists of several tabs that is collapsible upon click a button and then expandable when you click that button again. When collapsed, the ends of the tabs are still visible, and when you hover over the tabs will go back out, and go back in when hovering out.</p>
  
  <p>So I have the following navigation laid out:</p>
  
  <pre><code>&lt;ul id="navigation"&gt;
  &lt;li&gt;&lt;a href="../name1/"&gt;Name1&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href="../name2/"&gt;Name2&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href="../name3/"&gt;Name3&lt;/a&gt;&lt;/li&gt;
  &lt;li id = "collapser"&gt;&lt;a href = "javascript:void(0)"&gt;Collapse All&lt;/a&gt;&lt;/li&gt;
  &lt;/ul&gt;
  </code></pre>
  
  <p>And I have the following jQuery/javascript laid out to do this:</p>
  
  <pre><code>           $("#collapser").click(function(){
              if($("#collapser").hasClass("clicked")){
                  $(function() {
                    $('#navigation a').stop().animate({'marginLeft':'-118px'},1000);
  
                    $('#navigation &gt; li').hover(
                          function () {
                              $('a',$(this)).stop().animate({'marginLeft':'0px'},400);
                          },
                          function () {
                              $('a',$(this)).stop().animate({'marginLeft':'-118px'},400);
                          }
                      );
                   });
                   $("#collapser").removeClass("clicked");
                   $("#collapser").addClass("unclicked");
                   $("#collapser").html('&lt;a href = "javascript:void(0)"&gt;Expand All&lt;/a&gt;')
               }
               else{
                  $(function() {
                    $('#navigation a').stop().animate({'marginLeft':'0px'},1000);
  
                    $('#navigation &gt; li').hover(
                          function () {
                              $('a',$(this)).stop().animate({'marginLeft':'0px'},400);
                          },
                          function () {
                              $('a',$(this)).stop().animate({'marginLeft':'0px'},400);
                          }
                      );
                   });
                   $("#collapser").removeClass("unclicked");
                   $("#collapser").addClass("clicked");
                   $("#collapser").html('&lt;a href = "javascript:void(0)"&gt;Collapse All&lt;/a&gt;')
               }
           })
  </code></pre>
  
  <p>The code works, but only when you click the link a second time. I can't seem to figure out what I did to make it work only after clicking it once already.</p>
  
  <p>Any help would be appreciated, thank you very much!!
  -Quintin</p>
  
  <p>EDIT:
  Here is the CSS for the navigation:</p>
  
  <pre><code>ul#navigation {
  position: fixed;
  margin: 0px;
  padding: 0px;
  font-size:14px;
  top: 14px;
  left: 0px;
  list-style: none;
  z-index:9999;}
  
  ul#navigation li {
  width: 100px;
  }
  
  ul#navigation li a {
  display:block;
  margin-bottom:3px;
  width:126px;
  padding:3px;
  padding-left:15px;
  background-color:#ffffff;
  background-repeat:no-repeat;
  background-position:center center;
  opacity:0.7;
  filter:progid:DXImageTransform.Microsoft.Alpha(opacity=60);
  -moz-box-shadow: 0px 1px 3px #000;
  -webkit-box-shadow: 0px 1px 3px #000;
  }
  
  ul#navigation .checked a{
  color:#ffffff;
  background-color:#000000;
  }
  </code></pre>