// ADJUST HEIGHTS created by Michal Matuška (fireball_)
(function ($) {
    var eqHeights = function () {
        this.stack = [];
        this.index = 0;
        this.register = function (el, options, wrap) {
            var opt = options || null;
            if (opt && typeof opt == 'string') {
                opt = [opt]
            }
            this.stack[this.index] = {
                context: el,
                elements: opt,
                too: wrap || false
            };
            this.index++
        };
        this.calculate = function (obj) {
            var that = obj,
                context = that.context,
                elements = that.elements,
                too = that.too,
                height = 0,
                height2 = 0,
                fn = function (h) {
                    var newH = $(this).height();
                    return h > newH ? h : newH
                };
            context.css('height', '').each(function () {
                if (elements) {
                    var len = elements.length,
                        j = 0;
                    for (var i = len; i--;) {
                        height2 = 0;
                        $(elements[j], this).css('height', '').each(function () {
                            height2 = fn.call(this, height2)
                        }).height(height2);
                        j++
                    }
                }
                if (!elements || elements && too) {
                    height = fn.call(this, height)
                }
            });
            if (!elements || elements && too) {
                context.height(height)
            }
        };
        this.init = function (i) {
            if (this.index) {
                var index = i || null;
                if (index) {
                    index = index == 'last' ? this.index - 1 : index == 'first' ? 0 : index;
                    this.calculate(this.stack[index])
                } else {
                    var len = this.stack.length,
                        j = 0;
                    for (var i = len; i--;) {
                        this.calculate(this.stack[j]);
                        j++
                    }
                }
            }
        };
        this.refresh = function () {
            this.init()
        }
    };
    $.eqHeights = new eqHeights;
    $.fn.eqHeights = function (elements, too) {
        $.eqHeights.register(this, elements, too);
        $.eqHeights.init('last');
        return this
    }
})(jQuery);

(function ($) {
    $.fn.fontSizeListener = function (element, callback) {
        var el = $(element);
        var h = el.height();
        var listen = function () {
            var newH = el.height();
            if (newH != h) {
                h = newH;
                if (callback && typeof callback == 'function') {
                    callback()
                }
            }
        };
        var fontSizeInterval = setInterval(function () {
            listen()
        }, 200)
    }
})(jQuery);
