$j(document).ready(function() {
    
        var show_accordion = $j('.acc_container');
        if (show_accordion.length >= 1) {
		$j('<div class="accordion"><img src="typo3conf/ext/hgf/images/ic_closed_pluszeich.gif" /></div>').prependTo('.acc_content_visible .acc_content_visible_header');
	}
	
    
        $j('.accordion_all').bind("click", function(){

                        var list = $j('.acc_content_hidden');

                        if ($j('.accordion_all span').text() == 'Alle ausklappen') {
                                for (i=0; i<list.length; i++) {
                                        if (list.eq(i).css('display') == 'none'){
                                                list.eq(i).show("fast");
                                        }
                                }

                                $j('.accordion_all img').attr('src', 'typo3conf/ext/hgf/images/ic_open_minuszeich.gif');
                                $j('.accordion img').attr('src', 'typo3conf/ext/hgf/images/ic_open_minuszeich.gif');
                                $j('.accordion_all').html('<img src="typo3conf/ext/hgf/images/ic_open_minuszeich.gif" /><span>Alle einklappen</span>');
                        }
                        else {
                                for (i=0; i<list.length; i++) {
                                        if (list.eq(i).css('display') != 'none'){
                                                list.eq(i).hide("fast");
                                        }
                                }

                                $j('.accordion img').attr('src', 'typo3conf/ext/hgf/images/ic_closed_pluszeich.gif');
                                $j('.accordion_all').html('<img src="typo3conf/ext/hgf/images/ic_closed_pluszeich.gif" /><span>Alle ausklappen</span>');
                        }
                });

        $j('.accordion img').bind("click", function(){

                        var index = $j('.accordion img').index(this);
                        var list = $j('.acc_content_hidden');
                        var images = $j('.accordion img');

                        if (list.eq(index).css('display') == 'none') {
                                list.eq(index).show("fast");
                                images.eq(index).attr('src', 'typo3conf/ext/hgf/images/ic_open_minuszeich.gif');
                        }
                        else {
                                list.eq(index).hide("fast");
                                images.eq(index).attr('src', 'typo3conf/ext/hgf/images/ic_closed_pluszeich.gif');
                                $j('.accordion_all').html('<img src="typo3conf/ext/hgf/images/ic_closed_pluszeich.gif" /><span>Alle ausklappen</span>');
                        }

                        for (i=0; i<list.length; i++) {

                                if (i != index) {
                                        list.eq(i).hide("fast");
                                        images.eq(i).attr('src', 'typo3conf/ext/hgf/images/ic_closed_pluszeich.gif');

                                }
                        }
                });

        $j('.acc_content_visible h3').bind("click", function(){

                        var index = $j('.acc_content_visible h3').index(this);
                        var list = $j('.acc_content_hidden');
                        var images = $j('.accordion img');

                        if (list.eq(index).css('display') == 'none') {
                                list.eq(index).show("fast");
                                images.eq(index).attr('src', 'typo3conf/ext/hgf/images/ic_open_minuszeich.gif');
                        }
                        else {
                                list.eq(index).hide("fast");
                                images.eq(index).attr('src', 'typo3conf/ext/hgf/images/ic_closed_pluszeich.gif');
                                $j('.accordion_all').html('<img src="typo3conf/ext/hgf/images/ic_closed_pluszeich.gif" /><span>Alle ausklappen</span>');
                        }

                        for (i=0; i<list.length; i++) {

                                if (i != index) {
                                        list.eq(i).hide("fast");
                                        images.eq(i).attr('src', 'typo3conf/ext/hgf/images/ic_closed_pluszeich.gif');

                                }
                        }
                });

});
