/**
 * Copyright Marc J. Schmidt. See the LICENSE file at the top-level
 * directory of this distribution and at
 * https://github.com/marcj/css-element-queries/blob/master/LICENSE.
 */
;
(function() {

    /**
     * Class for dimension change detection.
     *
     * @param {Element|Element[]|Elements|jQuery} element
     * @param {Function} callback
     *
     * @constructor
     */
    this.ResizeSensor = function(element, callback) {
        /**
         *
         * @constructor
         */
        function EventQueue() {
            this.q = [];
            this.add = function(ev) {
                this.q.push(ev);
            };

            var i, j;
            this.call = function() {
                for (i = 0, j = this.q.length; i < j; i++) {
                    this.q[i].call();
                }
            };
        }

        /**
         * @param {HTMLElement} element
         * @param {String}      prop
         * @returns {String|Number}
         */
        function getComputedStyle(element, prop) {
            if (element.currentStyle) {
                return element.currentStyle[prop];
            } else if (window.getComputedStyle) {
                return window.getComputedStyle(element, null).getPropertyValue(prop);
            } else {
                return element.style[prop];
            }
        }

        /**
         *
         * @param {HTMLElement} element
         * @param {Function}    resized
         */
        function attachResizeEvent(element, resized) {
            if (!element.resizedAttached) {
                element.resizedAttached = new EventQueue();
                element.resizedAttached.add(resized);
            } else if (element.resizedAttached) {
                element.resizedAttached.add(resized);
                return;
            }

            element.resizeSensor = document.createElement('div');
            element.resizeSensor.className = 'resize-sensor';
            var style = 'position: absolute; left: 0; top: 0; right: 0; bottom: 0; overflow: scroll; z-index: -1; visibility: hidden;';
            var styleChild = 'position: absolute; left: 0; top: 0;';

            element.resizeSensor.style.cssText = style;
            element.resizeSensor.innerHTML =
                '<div class="resize-sensor-expand" style="' + style + '">' +
                    '<div style="' + styleChild + '"></div>' +
                '</div>' +
                '<div class="resize-sensor-shrink" style="' + style + '">' +
                    '<div style="' + styleChild + ' width: 200%; height: 200%"></div>' +
                '</div>';
            element.appendChild(element.resizeSensor);

            if (!{fixed: 1, absolute: 1}[getComputedStyle(element, 'position')]) {
                element.style.position = 'relative';
            }

            var expand = element.resizeSensor.childNodes[0];
            var expandChild = expand.childNodes[0];
            var shrink = element.resizeSensor.childNodes[1];
            var shrinkChild = shrink.childNodes[0];

            var lastShrinkWidth, lastShrinkHeight;
            var lastExpandWidth, lastExpandHeight;

            var reset = function() {
                resetExpand();
                resetShrink();
            };
            
            var resetExpand = function() {
                expandChild.style.width = expand.offsetWidth + 10 + 'px';
                expandChild.style.height = expand.offsetHeight + 10 + 'px';
                expand.scrollLeft = expand.scrollWidth;
                expand.scrollTop = expand.scrollHeight;
                lastExpandWidth = element.offsetWidth;
                lastExpandHeight = element.offsetHeight;
            };
            
            var resetShrink = function() {
                shrink.scrollLeft = shrink.scrollWidth;
                shrink.scrollTop = shrink.scrollHeight;
                lastShrinkWidth = element.offsetWidth;
                lastShrinkHeight = element.offsetHeight;
            };

            reset();

            var changed = function() {
                if (element.resizedAttached) {
                    element.resizedAttached.call();
                }
            };

            var addEvent = function(el, name, cb) {
                if (el.attachEvent) {
                    el.attachEvent('on' + name, cb);
                } else {
                    el.addEventListener(name, cb);
                }
            };

            addEvent(expand, 'scroll', function() {
                if (element.offsetWidth > lastExpandWidth || element.offsetHeight > lastExpandHeight) {
                    changed();
                }
                resetExpand();
            });

            addEvent(shrink, 'scroll',function() {
                if (element.offsetWidth < lastShrinkWidth || element.offsetHeight < lastShrinkHeight) {
                    changed();
                }
                resetShrink();
            });
        }

        if ("[object Array]" === Object.prototype.toString.call(element)
            || ('undefined' !== typeof jQuery && element instanceof jQuery) //jquery
            || ('undefined' !== typeof Elements && element instanceof Elements) //mootools
            ) {
            var i = 0, j = element.length;
            for (; i < j; i++) {
                attachResizeEvent(element[i], callback);
            }
        } else {
            attachResizeEvent(element, callback);
        }

        this.detach = function() {
            ResizeSensor.detach(element);
        };
    };

    this.ResizeSensor.detach = function(element) {
        if (element.resizeSensor) {
            element.removeChild(element.resizeSensor);
            delete element.resizeSensor;
            delete element.resizedAttached;
        }
    };

})();
@@ -3190,141 +3190,8 @@
 ) %7B%0A
-                resetExpand();%0A                resetShrink();%0A            %7D;%0A            %0A            var resetExpand = function() %7B%0A
     
@@ -3468,391 +3468,96 @@
     
-lastExpandWidth = element.offsetWidth;%0A                lastExpandHeight = element.offsetHeight;%0A            %7D;%0A            %0A            var resetShrink = function() %7B%0A                shrink.scrollLeft = shrink.scrollWidth;%0A                shrink.scrollTop = shrink.scrollHeight;%0A                lastShrinkWidth = element.offsetWidth;%0A                lastShrinkHeight = element.offset
+shrink.scrollLeft = shrink.scrollWidth;%0A                shrink.scrollTop = shrink.scroll
 Heig
@@ -4253,16 +4253,122 @@
 eset
-Expand()
+();%0A                lastExpandWidth = element.offsetWidth;%0A                lastExpandHeight = element.offsetHeight
 ;%0A  
@@ -4611,16 +4611,122 @@
 eset
-Shrink()
+();%0A                lastShrinkWidth = element.offsetWidth;%0A                lastShrinkHeight = element.offsetHeight
 ;%0A  

Undo some of the previous change