(function($) {
  $.collapsibleModule = {
    defaults: {
      startIndex: 0
    }
  };
  $.fn.collapsibleModule = function(conf) {
    return this.each(function(){
      var config = $.extend({}, $.collapsibleModule.defaults, conf);
      var model = new Object();
      var i = config.startIndex;
      model.current_section = $(this).find("li:eq(" + i + ")");
      $(this).find("li:eq(" + i + ") h1").addClass('expanded');
      $(this).find("li:not(:eq(" + i + ")) div.content").hide();
      $(this).find("li:eq(" + i + ") div.status").hide();
      $(this).find("li:not(:eq(" + i + ")) div.selected_status").hide();
      $(this).find("li:last").addClass('last');
      $(this).find("li h1").click(function(model){return function(){
        var content = $(this).parent().find("div.content");
        var current_content = model.current_section.find("> div.content");
        if (content.get()[0] != current_content.get()[0]) {
          model.current_section.find("div.status").show();
          model.current_section.find("div.selected_status").hide();

          $(this).addClass('expanded');
          $(this).parent().find("div.status").hide();
          $(this).parent().find("div.selected_status").show();
          content.slideDown("fast");
          var previous_header = model.current_section.find("h1");
          current_content.slideUp("fast", function(x){return function(){x.removeClass('expanded')}}(previous_header));
          model.current_section = $(this).parent();
        }
      }}(model));
    });
  };
})(jQuery);