Horizontal icon menu (accordian)

Horizontal icon menu (accordian)

Hi guys, I'm having trouble creating something along the lines of an accordian menu. I'm trying to keep it to a minimum as code goes, so that it doesn't way on the page and can easily be used in mobile or desktop.

I've managed to animate the menu to open, but now I wanted to close an open button if I click on another. I supoose it's a simple "if" "else" statement, but I've tried over and over again and can't seem to get it to work as I wish.

Here goes the code as I have it:

HTML
  1. <nav>
  2.                 <ul>
  3.                     <li> <a href="#"><img src="images/header_icon_home.gif" width="45" height="45" alt="home"></a>
  4.                       <span>home</span></li>
  5.                     <li> <a href="#"><img src="images/header_icon_portfolio.gif" width="45" height="45" alt="porfolio"></a>
  6.                       <span>portfolio</span></li>
  7.                     <li> <a href="#"><img src="images/header_icon_blog.gif" width="45" height="45" alt="blog"></a>
  8.                       <span>blog</span></li>
  9.                     <li> <a href="#"><img src="images/header_icon_about.gif" width="45" height="45" alt="about"></a>
  10.                       <span>about</span></li>
  11.                     <li> <a href="#"><img src="images/header_icon_contact.gif" width="45" height="45" alt="contact"></a>
  12.                       <span>contact</span></li>
  13.                     <li> <a href="#"><img src="images/header_icon_search.gif" width="45" height="45" alt="search"></a>
  14.                   <span class="search"><input name="search" id="search" ></input></span></li>
  15.                 </ul>
  16.             </nav>

CSS:
  1. nav ul {
  2. position:absolute;
  3. right:0;
  4. top: 42px;
  5. }
  6. nav ul li {
  7. display: inline-block;
  8. float:left;
  9. }
  10. nav ul li img {
  11. float:left;
  12. }
  13. nav ul li span {
  14. background-color: #333;
  15. color: #fff;
  16. padding: 13px 5px;
  17. float:left;
  18. font-size:16px;
  19. display:none;
  20. }
  21. nav ul li span.search {
  22. padding: 12px 10px 12px 5px;
  23. background-color: #666;
  24. }
  25. nav ul li span input {
  26. font-size:12px;
  27. }

Jquery function
  1. $('nav ul li a').click(function() {
  2. $(this).next().animate({width: 'toggle'}, 200);
  3.  });