////////////////////////////
// http://adipalaz.awardspace.com/experiments/jquery/expand.html
///////////////////////////
(function($) {
$.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.addTrigger = function(options) {
    var defaults = {
         expand : '',
         collapse : '',
         a : '',
         b : '<span class="hidden">',
         c : '</span>',
         ref : 'div:first',
         el : '#' + this.attr("id") + ' '
    };
    var options = $.extend(defaults, options);   
    return this.each(function() {
        $(options.a + options.expand + options.b + options.collapse + options.c).insertBefore(options.el + options.ref);
});};
//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').addTrigger().find('div.collapse').hide().end()
    .find('h4.expand').css('cursor','pointer').orphans().wrap('<a style="display:block" href="#expand/collapse" title="expand/collapse"></a>');
        /* ---  * If you want to have your DIVs initially expanded:
            remove: $('.collapse').hide();
            --- * The first DIV initially expanded:
            $('#outer').addTrigger().find('div.collapse:gt(0)').hide().end()
            .find('h4.expand:eq(0)').addClass('open').end() ...  --- */  
   
    $('#outer div.demo h4.expand').click(function() {
        $(this).toggleClass('open')
        .next('div.normal').slideFadeToggle().end()
        .next('div.slow').slideFadeToggle('slow','linear');
    });
	
});
