////////////////////////////
// http://adipalaz.awardspace.com/experiments/jquery/expand.html
// * - When using this script, please keep the above url intact.
///////////////////////////
(function($) {
//http://www.mail-archive.com/jquery-en@googlegroups.com/msg43851.html
$.fn.orphans = function(){
    var txt = [];
    this.each(function(){$.each(this.childNodes, function() {
        if (this.nodeType == 3 && $.trim(this.nodeValue)) txt.push(this)
    })}); 
    return $(txt);
};

$.fn.expandAll = function(options) {
    var defaults = {
         
         trigger1 : '[Expand All]',
         trigger2 : '[Collapse All]',
         cont : '#' + this.attr("id") + ' ',
         ref : 'div:first',
         showMethod : 'show',
         hideMethod : 'hide',
         speed : ''
    };
    var options = $.extend(defaults, options);   
    return this.each(function() {
        $(options.a + options.trigger1 + options.b).insertBefore(options.cont + options.ref);
        $(this).find('#switch a').click(function() {
        var $cllps = $(this).closest('div').find('.collapse'),
            $exp = $(this).closest('div').find('h4.expand');
        if ($(this).text() == options.trigger1) {
          $(this).text(options.trigger2);
          $exp.addClass('open');
          $cllps[options.showMethod](options.speed);
        } else {
          $(this).text(options.trigger1);
          $exp.removeClass('open');
          $cllps[options.hideMethod](options.speed);
        }
    });
});};

//http://www.learningjquery.com/2008/02/simple-effects-plugins:
$.fn.fadeToggle = function(speed, easing, callback) {
    return this.animate({opacity: 'toggle'}, speed, easing, callback);
};
$.fn.slideFadeToggle = function(speed, easing, callback) {
    return this.animate({opacity: 'toggle', height: 'toggle'}, speed, easing, callback);
};
})(jQuery);
////////////////////////////
$(function() {
    $('#outer').expandAll().find('div.collapse').hide().end()
    .find('h4.expand').css('cursor','pointer').orphans().wrap('<a style="display:block" href="#expand/collapse" title="Expand/Collapse"></a>');
    
    // 1. div.demo:eq(0):
    $('#outer div.demo:eq(0) h4.expand').click(function() {
        $(this).toggleClass('open')
        .next('div.normal').toggle().end()
        .next('div.slow').toggle('slow');
    });
    // 2. div.demo:eq(1):
    $('#outer div.demo:eq(1) h4.expand').click(function() {
        $(this).toggleClass('open')
        .next('div.normal').slideToggle().end()
        .next('div.slow').slideToggle('slow','linear');
    });
    // 3. div.demo:eq(2):
    $('#outer div.demo:eq(2) h4.expand').click(function() {
        $(this).toggleClass('open')
        .next('div.normal').fadeToggle('slow','linear').end()
        .next('div.slow').slideFadeToggle('slow','linear');
    });
});
