if(!Array.isArray){ Array.isArray = $.isArray; }

(function() {
    
    if(window.postMessage && window.addEventListener){

        var timeouts = [];
        var messageName = "zero-timeout-message";
    
        // Like setTimeout, but only takes a function argument.  There's
        // no time argument (always zero) and no arguments (you have to
        // use a closure).
        function nextTick(fn) {
            timeouts.push(fn);
            window.postMessage(messageName, "*");
        }
    
        function handleMessage(event) {
            if (event.source == window && event.data == messageName) {
                event.stopPropagation();
                if (timeouts.length > 0) {
                    var fn = timeouts.shift();
                    fn();
                }
            }
        }
    
        window.addEventListener("message", handleMessage, true);

        window.nextTick = nextTick;    
    
    }else{
        window.nextTick = function(f) { setTimeout(f, 0); }
    }

})();

