title: Toggling display of a div with jQuery
body: <p>I have two links, one with id #calendar_arrival_open and another with #calendar_departure_open.  Both links control whether or not a div containing a calendar is displayed, but in both cases the calendar displayed is the same calendar, to avoid loading two identical calendars. I'm trying to use the following code to toggle the opening and closing of the calendar when the links are clicked.</p>
  
  <pre><code>var state = "closed";
  if(state == "closed"){
      $("#calendar_arrival_open").click(function () {
          $("#calendar_box").show();
          $("#select_arrival_date").show();
          $("#select_departure_date").hide();
          state = "arrival_open";
      });
      $("#calendar_departure_open").click(function () {
          $("#calendar_box").show();
          $("#select_departure_date").show();
          $("#select_arrival_date").hide();
          state = "departure_open";
      });
  }
  
  if(state == "arrival_open"){
      $("#calendar_arrival_open").click(function () {
          $("#calendar_box").hide();
          state = "closed";
      });
      $("#calendar_departure_open").click(function () {
          $("#select_departure_date").show();
          $("#select_arrival_date").hide();
          state = "departure_open";
      });
  }
  
  if(state == "departure_open"){
      $("#calendar_arrival_open").click(function () {
          $("#calendar_box").hide();
          $("#select_departure_date").hide();
          $("#select_arrival_date").show();
          state = "arrival_open";
      });
      $("#calendar_departure_open").click(function () {
          $("#calendar_box").hide();
          state = "closed";
      });
  }
  </code></pre>
  
  <p>This code works for opening the calendar, but not for closing it. I can't see why. As you can see, if the "arrival calendar" is open and the departure calendar link is clicked, the "departure calendar" appears, and vice-versa.  However, if the arrival calendar is open and the arrival calendar link is clicked, then the calendar closes.</p>
  
  <p>Can anyone see the problem? Is this "state" method the best for handling what I need?</p>