/* ---------------------------------------------
http://adipalaz.awardspace.com/experiments.html
Requires: jQuery v1.3+
Copyright (c) 2009 Adriana Palazova
Dual licensed under the MIT (http://www.adipalaz.com/docs/mit-license.txt) and GPL (http://www.adipalaz.com/docs/gpl-license.txt) licenses
------------------------------------------------ */
(function($) {
$.fn.toggler = function(options) {
    var defaults = {
         cllpsEl : 'div.collapse',
         method : 'toggleHeight',
         speed : 'slow',
         container : 'div.tabber', //(optional)
         initShow : '.shown', //the initially expanded sections (optional)
         state : 'hidden'
    };
    var o = $.extend({}, defaults, options);
    $(this).append('<a class="trigger" style="display:block" href="#"></a>');
    return this.each(function() {
      if (o.state == 'hidden') {
        $(this).next(o.cllpsEl + ':not(.shown)').hide()
          .prev().find('a').removeClass('open').attr("title", "More");
      } else {
        var txt="Close";
        $(this).find('a').attr("title", "Close");
      }
      var container;
      if (o.container) {
        container = o.container;
       } else {
        container = 'div';
      }
      if (o.initShow) {
        $(this).closest(container).find(o.initShow).show().addClass('shown')
          .prev().find('a').addClass('open');
      }
      $(this).click(function() {
          var obj = $(this), link = obj.find('a');
          if(link.hasClass('open')) {
            link.attr("title", "More");
          } else {
            link.attr("title", "Close");
          }
          link.animate({opacity: 0}, o.speed, function() {
            link.toggleClass('open');
            obj.next(o.cllpsEl)[o.method](o.speed, function() {
              link.animate({opacity: 1}, o.speed).blur();
            });
          });
          return false;
    });
});};
$.fn.toggleHeight = function(speed, easing, callback) {
    return this.animate({height: 'toggle'}, speed, easing, callback);
};
})(jQuery);
