(function ($) {
  
  function fixupDisclosures() {
    function doDisclosure() {
      $('> :gt(2)', this.parentNode).toggle();
      $('img:lt(2)', this.parentNode).toggle();
    }
    
  	$('.disclosure').livequery(function(){
  		// arrange for the heading to be clickable
  	  $(this).find(':header:first').click(doDisclosure);
	  
  	  // insert the open disclosure image and make it clickable also
  	  var open = $('<img src="images/disclosure_open.gif" class="disclosure-img">')
  	    .click(doDisclosure);
		
  		$(this).prepend(open);

  	  // insert the close disclosure image and also make it clickable
  	  var close = $('<img src="images/disclosure_closed.gif" class="disclosure-img">')
  	    .click(doDisclosure)
  	    .css('display', 'none');
	  
  		$(this).prepend(close);
  	});
  	
  	$('.disclosure-closed').livequery(function(){
  	  // arrange for the heading to be clickable
  	  $(this).find(':header:first').click(doDisclosure);
  	  
  	  // insert the open and close disclosure images and make them clickable also
  	  var open = $('<img src="images/disclosure_open.gif" class="disclosure-img">')
  	    .click(doDisclosure)
  	    .css('display', 'none');
  	
  		$(this).prepend(open);

  	  // insert the close disclosure image and also make it clickable
  	  var close = $('<img src="images/disclosure_closed.gif" class="disclosure-img">')
  	    .click(doDisclosure);
	  
  		$(this).prepend(close);
  		
  		// hide the content
  	  $('> :gt(2)', this).css('display', 'none');
  	});
  }

  $(fixupDisclosures);
})(jQuery);