jQuery.fn.not_exists = function () { return jQuery(this).length == 0; }

jQuery.fn.jqcollapse = function (o) {

    // Defaults
    var o = jQuery.extend({
        slide: true,
        speed: 1000,
        easing: 'easeOutBounce'
    }, o);

    $(this).each(function () {

        var e = $(this).attr('id');

	//first check if there's more than one item - if so - show it! (and quit)
	var grp_cnt	= $('#'+ e).children().length;
	if (grp_cnt == 1)
		return;

        $('#' + e + ' li > ul').each(function (i) {
            var parent_li = $(this).parent('li');
            var sub_ul = $(this).remove();

            // Create 'a' tag for parent if DNE
            if (parent_li.children('a').not_exists()) {
                parent_li.wrapInner('<a/>');
            }

            parent_li.find('a').addClass('jqcNode plus').click(function () {
                var is_vis = parent_li.children('ul').is(":visible");
                if (is_vis) {//hide it
                    parent_li.find('a').removeClass('minus');
                    parent_li.find('a').addClass('plus');
                    sub_ul.slideToggle(o.speed, 'easeOutQuint');
                } else {//show it
                    //first - hide all!
                    minimize_all_locations(e);

                    parent_li.find('a').removeClass('plus');
                    parent_li.find('a').addClass('minus');
                    sub_ul.slideToggle(o.speed, 'easeInQuint');
                }

            });


            parent_li.append(sub_ul);
        });

        //Hide all sub-lists
        $('#' + e + ' ul').hide();

    });

};

