/* global screenReaderText */
/**
 * Theme functions file.
 *
 * Contains handlers for navigation and widget area.
 */

( function( $ ) {
    "use strict"; // jshint ;_;

    var body = $('body');

    var resizer = (function () {
        window.footer_widgets();
    });

    $(document).ready(function () {
        if (window.addEventListener) {
            window.addEventListener('resize', resizer, false);
        } else if (window.attachEvent) {
            window.attachEvent('onresize', resizer);
        }
        window.footer_widgets();
    });

    window.footer_widgets = function () {
        /**
        * Arranges footer widgets vertically.
        */
        if (window.innerWidth < 1240) {
            if ($.isFunction($.fn.masonry)) {
                $('#footer-widgets.widgets-masonry').masonry({
                    itemSelector: '.widget-masonry',
                    columnWidth: function (containerWidth) {
                        return containerWidth / 2;
                    },
                    gutterWidth: 0,
                    isResizable: true,
                    isRTL: $('body').is('.rtl')
                });
            }
        }
        else {
            if ($.isFunction($.fn.masonry)) {
                $('#footer-widgets.widgets-masonry').masonry({
                    itemSelector: '.widget-masonry',
                    columnWidth: function (containerWidth) {
                        return containerWidth / 3;
                    },
                    gutterWidth: 0,
                    isResizable: true,
                    isRTL: body.is('.rtl')
                });
            }
        }
    }
} )( jQuery );
