jQuery(document).ready(function() {
    var $siblings;

    if ($('.accordion .csc-header, .accordion .category_title').length > 0) {

        $('.accordion .csc-header, .accordion .category_title').each(function(e) {
            if($(this).closest('.accordion').hasClass('act')) {
                $(this).find('h1, h2, h3').addClass('act');
            }

            $siblings = $(this).siblings();
            if ($siblings.length > 1) {
                $siblings.wrapAll('<div class="itemwrapper" />');
            }
            if($(this).find('h1, h2, h3').hasClass('act')) {
                $(this).next().show();
            }
            else {
                $(this).next().hide();
            }

        });

        $('.accordion .csc-header, .accordion .category_title').click(function(e) {
            var $header = $(this).find('h1, h2, h3');
            if ($header.hasClass('act')) {
                $(this).next().slideUp('slow');
                $header.removeClass('act');
            }
            else {
                $(this).next().slideDown('slow');

                $header.addClass('act');
                $(this).parent().css('padding-bottom', '0px');
            }
            return false;
        });
    };

    // Order Materials
    if ($('div.tx_cbinventory form fieldset.order > ul > li > h3').length > 0) {

        $('div.tx_cbinventory form fieldset.order > ul > li > h3').each(function(e) {
            if($(this).hasClass('act')) {
                $(this).next().show();
            }
            else {
                $(this).next().hide();
            }
        });

        $('div.tx_cbinventory form fieldset.order > ul > li > h3').click(function(e) {
            var $header = $(this);
            if ($header.hasClass('act')) {
                $(this).next().slideUp('slow');
                $header.removeClass('act');
            }
            else {
                $(this).next().slideDown('slow');
                $header.addClass('act');
                //$(this).parent().css('padding-bottom', '0px');
            }
            return false;
        });
    };




});
