////////////////////////////
// http://adipalaz.awardspace.com/experiments/jquery/multiple_expand_all_collapse_all.html
// * When using this script, please keep the above url intact.
///////////////////////////
//use jQuery via $j for no conflict with prototype 
var $j = jQuery.noConflict();

(function($j) {
$j.fn.expandAll = function(options) {
    var defaults = {
         trigger1 : '[Expand All]',
         trigger2 : '[Collapse All]',
         container : 'div.demo:eq(' + $j('div.demo').index(this) + ') ',
         ref : 'span.expand:first',
         showMethod : 'slideDown',
         hideMethod : 'slideUp',
         speed : ''
    };
    var options = $j.extend({}, defaults, options);   
    return this.each(function() {
        $j('<p class="switch"><a href="#">' + options.trigger1 + '</a></p>').insertBefore(options.container + options.ref);
        $j(this).find('p.switch a').click(function() {
        var $jcllps = $j(this).closest('div.demo').find('.collapse'),
            $jexp = $j(this).closest('div.demo').find('strong.expand');
        if ($j(this).text() == options.trigger1) {
          $j(this).text(options.trigger2);
          $jexp.addClass('open');
          $jcllps[options.showMethod](options.speed);
        } else {
          $j(this).text(options.trigger1);
          $jexp.removeClass('open');
          $jcllps[options.hideMethod](options.speed);
        }
        return false;
    });
});};
})(jQuery);
////////////////////////////
$j(function() {
    // --- Initially hide collapsible sections. Generate links around the elements that trigger expand/collapse --- //
    $j('#outer').find('div.collapse').hide().end()
    .find('span.expand').css('cursor','pointer').wrapInner('<a style="display:block" href="#expand/collapse" title="expand/collapse"></a>');
    
    // --- Expand All/Collapse All --- //
    $j('#outer div.demo').each(function(index) {
        var $jthisDemo = $j('#outer div.demo:eq(' + index + ')');
        if (index == 2) {
          $jthisDemo.expandAll({
            trigger1 : '[Show]', 
            trigger2 : '[Hide]', 
            ref : 'div:first', 
            showMethod : 'show', 
            hideMethod : 'hide', 
            speed: 'slow'});
        } else {
        $jthisDemo.expandAll();
        }
    });
    
    // --- Toggle --- //
    $j('#outer div.demo span.expand').click(function() {
        $j(this).toggleClass('open')
        .next('.collapse').slideToggle();
    });
    
});

