////////////////////////////
// http://adipalaz.awardspace.com/experiments/jquery/accordion3.html
///////////////////////////
(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);
};
})(jQuery);
////////////////////////////
// useful link: http://www.learningjquery.com/2007/03/accordion-madness
$(function() {
    $('#outer h4.expand').orphans().wrap('<a style="display:block" href="#expand/collapse" title="expand/collapse"></a>');
   
    // demo 1 - div.demo:eq(0) -  Simple slide effect with first section initially expanded
    $('#outer div.demo:eq(0)').find('h4.expand:eq(0)').addClass('open').end()
    .find('div.collapse:gt(0)').hide().end()
    .find('h4.expand').click(function() {
        $(this).toggleClass('open')
        .next('div').slideToggle().end()
    });
    
    //demo 2 - div.demo:eq(1) - Accordion slide effect with first section initially expanded
    $('#outer div.demo:eq(1)').find('h4.expand:eq(0)').addClass('open').end()
    .find('div.collapse:gt(0)').hide().end()
    .find('h4.expand').click(function() {
        $(this).toggleClass('open').siblings().removeClass('open').end()
        .next('div.collapse').slideToggle('fast').siblings('div.collapse:visible').slideUp('fast');
    });
    
    //demo 3 - div.demo:eq(2) - Accordion slide effect with first section initially expanded. Always keeps one section visible 
    $('#outer div.demo:eq(2)').find('h4.expand:eq(0)').addClass('open').end()
    .find('div.collapse:gt(0)').hide().end()
    .find('h4.expand').click(function() {
        $(this).addClass('open').siblings().removeClass('open').end()
        .next('div.collapse:hidden').slideToggle('fast').siblings('div.collapse:visible').slideUp('fast');
    });
    
    //demo 4 - div.demo:eq(3) - Queued Slide Effects 
    $('#outer div.demo:eq(3)').find('h4.expand:eq(0)').addClass('open').end()
    .find('div.collapse:gt(0)').hide().end()
    .find('h4.expand').each(function() {
          $(this).click(function() {
          
              var $thisCllps = $(this).next('div.collapse');
              var $cllpsVisible = $(this).siblings('h4.expand').next('div.collapse:visible');
              
              ($cllpsVisible.length) ? $(this).toggleClass('open').siblings('h4.expand').removeClass('open')
                  .next('div.collapse:visible').slideUp('fast', function() {
                  $thisCllps.slideDown();
                  }) : $(this).toggleClass('open').next('div.collapse').slideToggle();
              return false;
          });
     });

});
