jQuery.fn.not_exists = function () { return jQuery(this).length == 0; };
jQuery.fn.jqcollapse = function (o) {

    // Defaults
    o = jQuery.extend({
        slide: true,
        speed: 300,
        easing: ''
    }, o);
    $(this).each(function () {

        var e = $(this).attr('id');
        var no = 0;
        var id;

        $('#' + e + ' li > ul').each(function (i) {
            var parentLi = $(this).parent('li');
            var subUl = $(this).remove();

            // Create 'a' tag for parent if DNE

            if (parentLi.children('a').not_exists()) {
                parentLi.wrapInner('<a/>');
            }

            no++;
            id = 'cid' + no;
            parentLi.find('a').attr('id', id);
            parentLi.find('a').attr('href', '#' + id);


            parentLi.find('a').addClass('jqcNode').css('cursor', 'pointer').click(function () {

                if (o.slide == true) {
                    subUl.slideToggle(o.speed, o.easing);
                } else {
                    subUl.toggle();
                }
            });
            parentLi.append(subUl);
        });

        //Hide all sub-lists
        $('#' + e + ' ul').hide();




    });



    $(document).ready(function () {

        var anchor;


        anchor = '#' + $(location).attr('href').split('#')[1];


        $(anchor).click();
        $(anchor).closest('ul').closest('li').children('a').click();





    });

};

