////////////////////////////
// http://adipalaz.awardspace.com/experiments/jquery/accordion4.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 $trigger=$(txt);
};

//Jonas Raoni Soares Silva - http://jsfromhell.com/string/capitalize [rev. #2]
String.prototype.capitalize = function(){
    return this.replace(/\S+/g, function(a){
        return a.charAt(0).toUpperCase() + a.slice(1).toLowerCase();
    });
};

$.fn.wrapper = function(){
    return this.each(function() {
        if ($(this).parent('.expand').next('div.collapse').attr("id")) {
            var $destination = $(this).parent('.expand').next('div.collapse').attr("id"),
                $title = '';// + $destination.capitalize();
        }
        else {
            var $destination = $title = 'Expand/Collapse';
        }
        $(this).wrap('<a style="display:block" href=#' + $destination + ' title=' + $title + '></a>');
    });
};
})(jQuery);
////////////////////////////
$(function() {
    $('#outer div.expand').orphans().wrapper();
   
    //Queued Slide Effects 
    $('#outer div.demo').find('div.expand:eq(0)').addClass('open').end()
    .find('div.collapse:gt(0)').hide().end()
    .find('div.expand').each(function() {
          $(this).click(function() {

              var $thisCllps = $(this).next('div.collapse');
              var $cllpsVisible = $(this).siblings('div.expand').next('div.collapse:visible');
              
              ($cllpsVisible.length) ? $(this).toggleClass('open').siblings('div.expand').removeClass('open')
                  .next('div.collapse:visible').slideUp('fast', function() {
                  $thisCllps.slideDown();
                  }) : $(this).toggleClass('open').next('div.collapse').slideToggle();
              return false;
          });
     });

});
