$(document).ready( function() {
  
      function bar_init(page) {
  
          div = $("#bar-content");
              
          $("#bar-close").show();
          
          $.post('bar-ajax.php', {'p':'open'});
          
          div.html('<iframe id="bar-frame" src="bar-' + page + '.php"></iframe>');
          
          div.slideDown();
          
          $("#bar-menu a").removeClass('selected');
          $("#bar-menu a[rel=" + page + "]").addClass('selected');
      
      }
      
      $("#bar-menu a.bar-section, #bar-menu a.bar-new").click( function(e) {
      
          e.preventDefault();
          
          page = $(this).attr('rel');
          
          bar_init(page);
          
      });
      
      $("#bar-close").live( 'click', function(e) {
      
          e.preventDefault();
          
          $.post('bar-ajax.php', {'p':'close'});
          $(this).hide();          
          $("#bar-content").slideUp();
          $("#bar-content").html('');
      
      });
      
      $("#main").click( function() {
      
          $.post('bar-ajax.php', {'p':'close'});
          $("#bar-close").hide();          
          $("#bar-content").slideUp();
          $("#bar-content").html('');
      
      });
  
  });
