////////////////////////////
// http://adipalaz.awardspace.com/experiments/jquery/multiple_expand_all_collapse_all.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 = {
         a : '<p class="switch"><a href="#expand-all/collapse-all">',
         b : '</a></p>',
         trigger1 : '[Expand All]',
         trigger2 : '[Collapse All]',
         cont : 'div.demo:eq(' + $('div.demo').index(this) + ') ',
         ref : 'h4.expand:first',
         showMethod : 'slideDown',
         hideMethod : 'slideUp',
         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.demo').find('.collapse'),
            $exp = $(this).closest('div.demo').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);
        }
    });
});};
})(jQuery);
////////////////////////////
$(function() {

    $('.outer').find('div.collapse').hide().end()
    .find('h4.expand').css('cursor','pointer').orphans().wrap('<a style="display:block" href="#." title=""></a>');

    // --- Expand All/Collapse All --- //
    $('.outer div.demo').each(function(index) {
        var $thisDemo = $('.outer div.demo:eq(' + index + ')');
        if (index == 2) {
          $thisDemo.expandAll({
            trigger1 : '[Show]',
            trigger2 : '[Hide]',
            ref : 'div:first',
            showMethod : 'show',
            hideMethod : 'hide',
            speed: 'slow'});
        } else {
        $thisDemo.expandAll();
        }
    });


    $('.outer div.demo h4.expand').click(function() {
        $(this).toggleClass('open')
        .next('.collapse').slideToggle();
    });

	    $('.outer div.demo h4.blue').click(function() {
        $(this).toggleClass('open1')
        .next('.collapse1').slideToggle();
    });

	    $('.outer div.demo h4.maroon').click(function() {
        $(this).toggleClass('open2')
        .next('.collapse2').slideToggle();
    });


});

