(function($) {

        /************************************************************* footer */

        var footerTimeOut = 0;

        function minimizeFooter(type) {
                $('#fade-footer').animate({ bottom: '13px' }, 'fast');
                $('#footer').animate({ height: '13px' }, 'fast').find('#icon-footer').animate({ bottom: '-21px' }, 'fast');
                if (type == 'click') {
                        addFooterHover();
                        $.cookie('superfooter', '0', { expires: 365, path: '/' });
                        changeIcon('up');
                }
                return false;
        }

        function maximizeFooter(type) {
                $('#fade-footer').animate({ bottom: '63px' }, 'fast');
                $('#footer').animate({ height: '63px' }, 'fast').find('#icon-footer').animate({ bottom: '29px' }, 'fast');
                if (type == 'click') {
                        removeFooterHover();
                        $.cookie('superfooter', '1', { expires: 365, path: '/' });
                        changeIcon('down');
                }
                return false;
        }

        function changeIcon(name) {
                var replace = 'arrow-' + (name == 'up' ? 'down' : 'up');
                $('#icon-footer a img').attr('src', $('#icon-footer a img').attr('src').replace(replace, 'arrow-' + name));
        }

        function addFooterHover() {
                $('#footer').bind('mouseenter', footerOver).bind('mouseleave', footerOut);
        }

        function removeFooterHover() {
                $('#footer').unbind('mouseenter', footerOver).unbind('mouseleave', footerOut);
        }

        function footerOver() {
                clearTimeout(footerTimeOut);
                footerTimeOut = setTimeout(function () {
                        maximizeFooter('hover');
                }, 200);
        }

        function footerOut() {
                clearTimeout(footerTimeOut);
                minimizeFooter('hover');
        }

        function checkIconTitle() {
                var iconName = $('#icon-footer a img').attr('src').split('/').pop();
        }

        function toggleFooter() {
                return ($.cookie('superfooter') != '0') ? minimizeFooter('click') : maximizeFooter('click');
        }

        /********************************************************* plus minus */

        function togglePlusMinus() {
                var img = $(this).find('img').attr('src').split('/').pop();
                var openElement = (img == 'plus.gif');
                var newImg = (openElement === true) ? 'minus.gif' : 'plus.gif';
                if (openElement === true) {
                        $(this).parents('ul').find('.items').slideDown();
                }
                else {
                        $(this).parents('ul').find('.items').slideUp();
                }
                var newTitle = (openElement === true) ? 'Element schließen' : 'Element öffnen';
                var newSrc = $(this).find('img').attr('src').replace(img, newImg);
                $(this).find('img').attr('src', newSrc).parent().attr('title', newTitle);
                savePlusMinusStatus(this, openElement);
                return false;
        }

        function savePlusMinusStatus(element, opened) {
                var id = $(element).parents('ul').attr('id');
                $.cookie(id, (opened === true ? '1' : '0'), { expires: 365, path: '/' } );
        }

        /*************************************************************** load */

        $(document).ready(function () {
                if ($.cookie('superfooter') == '0') addFooterHover();
                $('#icon-footer a').click(toggleFooter);
                $('.plus-minus a').click(togglePlusMinus);
        });
})(jQuery);