jQuery(".pad-toggle-source").each(function( ){
    let classList = jQuery(this).attr('class').split(' ');
    let classToToggle = classList.find(c => c.startsWith('pad-toggle-targets-'));
    if (classToToggle === undefined) return;

    classToToggle = classToToggle.replace('pad-toggle-targets-', 'pad-toggle-target-')

    jQuery( this ).find("input[value='1']").on('click',
        function (){
            padToggleItems(classToToggle, true);
    });

    jQuery( this ).find("input[value='0']").on('click',
        function (){
            padToggleItems(classToToggle, false);
        });

    jQuery( this ).find("input[value='']").on('click',
        function (){
            padToggleItems(classToToggle, false);
        });

    jQuery( this ).find(".pad-toggle-object").on('click',
        function (){
            let newState = !jQuery( this ).hasClass('pad-toggle-open');
            jQuery( this ).toggleClass('pad-toggle-open');
            padToggleItems(classToToggle, newState);
        });
});

function padToggleItems( targetClass, targetState ){
    jQuery('.' + targetClass).each(function (){
        if (jQuery( this ).hasClass('pad-toggle-state-block') && !targetState){
            jQuery( this ).hide('slow', function (){
                jQuery( this ).removeClass('pad-toggle-state-block');
                jQuery( this ).addClass('pad-toggle-state-none');
            });
        }

        if (jQuery( this ).hasClass('pad-toggle-state-none') && targetState){
            jQuery( this ).show('slow', function (){
                jQuery( this ).removeClass('pad-toggle-state-none');
                jQuery( this ).addClass('pad-toggle-state-block');
            });
        }
    });
}