/*
==================================================================================================
  Lowland - JavaScript low level functions
  Copyright (C) 2012 Sebatian Fastner
==================================================================================================
*/

/**
 * #require(ext.sugar.Object)
 */

(function(window) {
  var hasPostMessage = !!window.postMessage;
  var slice = Array.prototype.slice;
  var timeouts = [];
  var messageName = "$$lowland-zero-timeout-message";
  
  var handleMessage = function(event) {
    if (event.source == window && event.data == messageName) {
      lowland.bom.Events.stopPropagation(event);
      if (timeouts.length > 0) {
        var timeout = timeouts.shift();

        timeout[0].apply(timeout[1], timeout[2]);
      }
    }
  };
  lowland.bom.Events.set(window, "message", handleMessage, true);
  
  core.Main.addMembers("Function", {
    
    delay : function(time, context) {
      var func = this;
      return setTimeout(function(context, args) {
        func.apply(context, args);
      }, time, context, slice.call(arguments, 2));
    },
    
    /**
     * Based upon work of http://dbaron.org/log/20100309-faster-timeouts
     */
    lazy : function(context) {
      context = context || this;
      //timeouts.push([func, slice.call(arguments,1)]);
      timeouts.push([this, context, slice.call(arguments,1)]);
      postMessage(messageName, "*");
    }
  });

})(window);
@@ -908,17 +908,20 @@
    %0A    
-d
+lowD
 elay : f
@@ -1044,22 +1044,32 @@
 (context
+%7C%7Cthis
 , args
+%7C%7C%5B%5D
 );%0A     

Rename delay to lowDelay as original name conflicts with Prototype