﻿jQuery.fn.quickTree = function() {

    var toggleMinus = '/images/layout/minus.gif';
    var togglePlus = '/images/layout/plus.gif';
    var expclass = '.' + this.attr('class') + ' span.expand';
    
    return this.each(function() {
        var $tree = $(this);

        var $roots = $tree.find('li');

        $tree.find('li:last-child').addClass('last');
        //$tree.addClass('tree');
        $tree.find('ul').hide();
        $roots.each(function() {
            var $timg = togglePlus;
            if ($(this).children('ul.exp').length > 0) { $timg = toggleMinus; $(this).children('ul.exp').show(); };

            if ($(this).children('ul').length > 0) {

                $(this).addClass('root').prepend('<span class="expand"><img src="' + $timg + '" alt="expand / collapse this section" /> </span>');
            }
        });



        $(expclass).toggle(

            function() {
                $(this).nextAll('ul').slideDown();
                $(this).children('img').attr('src', toggleMinus);
            },
            function() {
                $(this).nextAll('ul').slideUp();
                $(this).children('img').attr('src', togglePlus);
            }
        );
    });
};
   
