/* These are functions we wrote specifically for this application, but that extend Jquery. */


// here you go, Russ.  ;-)
// $('fieldset.toggler').setupToggleFieldset();
// $('fieldset.toggler-open').setupToggleFieldset(true);
// analyze the name of the fieldset we passed in, extrapolate what the 'handler/toggler' would be
// then call toggleFieldset on it.
(function($){
   $.fn.setupToggleFieldset=function(startOpen) {
     if (startOpen != true) startOpen = false; 
     return this.each(function(){
        $("#" + $(this).attr('id') + '_toggle' ).toggleFieldset( "#" + $(this).attr('id'), startOpen );
     });
   }
})(jQuery);



// ie, $('#anchorid').toggleFieldset('#fieldsetid',true/false);
// make sure there is a <div class="fieldset_wrapper"> wrapping inside the fieldset
(function($){
   $.fn.toggleFieldset=function(fieldset,startOpen) {
      if (startOpen != true) startOpen = false;
      if (startOpen == false) { $(fieldset+' div.fieldset_wrapper').hide().parent().addClass('collapsed').find('legend').find('a:first').removeClass('opened').addClass('closed'); }
      else { $(fieldset+' div.fieldset_wrapper').show().parent().removeClass('collapsed').find('legend').find('a:first').removeClass('closed').addClass('opened'); }
       
      return this.each(function(){
         // add a new class icon/open/close
         $(this).addClass('opened');
         
         $(this).click(function(){ 
            $(fieldset+' > div.fieldset_wrapper:visible').each(function(){
              $(this).slideUp('fast').parent().addClass('collapsed').find('legend').find('a:first').removeClass('opened').addClass('closed');
            }); 
            $(fieldset+' > div.fieldset_wrapper:hidden').each(function(){
              $(this).slideDown('fast').parent().removeClass('collapsed').find('legend').find('a:first').removeClass('closed').addClass('opened');
            }); 
         });
      });
   }
})(jQuery); 


// pass in a fieldset(s) you want collapsed
(function($){
  $.fn.collapseFieldset=function(fieldset) {
    return this.each(function(){
      $(this).find('div.fieldset_wrapper').each(function(){
        $(this).slideUp('fast').parent().addClass('collapsed').find('legend').find('a:first').removeClass('opened').addClass('closed');
      }); 
    }); 
  }
})(jQuery); 

// pass in a fieldset(s) you want opened
(function($){
  $.fn.expandFieldset=function() {
    return this.each(function(){
      $(this).find('div.fieldset_wrapper').each(function(){
        $(this).slideDown('fast').parent().removeClass('collapsed').find('legend').find('a:first').removeClass('closed').addClass('opened');
      }); 
    }); 
  }
})(jQuery); 




