$(document).ready(prepGenItemList)

function prepGenItemList() {
   $('.gil_title').click(switchListItem);
}

function switchListItem() {
   //do nothing when the already active item is clicked
   if ($(this).parent().hasClass('gil_item_active')) {
      return;
   }

   $('.gil_item_active h2').each(toggleListItem);
   toggleListItem(this);
}

function toggleListItem(mixInput) {
   var itemHeader;
   //per jQuery, the calling context either provides the .each index, or the dom element.
   if (typeof mixInput == 'number') itemHeader = $(this).get(mixInput);
   else itemHeader = mixInput;

   var parent = $(itemHeader).parent();
   var content = $(itemHeader).next();

   parent.slideToggle('normal', function () {
      parent.toggleClass('gil_item_active');

      //in ASP, this line should be replaced with ajax loading, depending on the display state.
      content.toggle();

      parent.slideToggle();
   });
}
