(function(console) {
    "use strict";
    var HxOverrides = function() {};
    HxOverrides.indexOf = function(a, obj, i) {
        var len = a.length;
        if (i < 0) {
            i += len;
            if (i < 0) i = 0;
        }
        while (i < len) {
            if (a[i] === obj) return i;
            i++;
        }
        return -1;
    };
    HxOverrides.remove = function(a, obj) {
        var i = HxOverrides.indexOf(a, obj, 0);
        if (i == -1) return false;
        a.splice(i, 1);
        return true;
    };
    HxOverrides.iter = function(a) {
        return {
            cur: 0,
            arr: a,
            hasNext: function() {
                return this.cur < this.arr.length;
            },
            next: function() {
                return this.arr[this.cur++];
            }
        };
    };
    var Main = function() {};
    Main.main = function() {
        if (Main.internetExplorer()) {
            console.log("[dex] timer override!");
            var timerHack = new timer.RAFTimer();
            var win = window;
            win.timerHack = timerHack;
            win.setInterval = $bind(timerHack, timerHack.setInterval);
            win.setTimeout = $bind(timerHack, timerHack.setTimeout);
            win.clearInterval = $bind(timerHack, timerHack.clearInterval);
            win.clearTimeout = $bind(timerHack, timerHack.clearTimeout);
        }
    };
    Main.internetExplorer = function() {
        var testStr = "Trident";
        var userAgent = window.navigator.userAgent;
        if (userAgent.indexOf(testStr) != -1) {
            console.log("[dex] EXPLORER!");
            return true;
        }
        console.log("[dex] default timer");
        return false;
    };
    var timer = {};
    timer.Interval = function(id, callback, time_ms, time_now, oneShot) {
        this.oneShot = oneShot;
        this.callback = callback;
        this.time_ms = time_ms;
        this.last_run = time_now;
        this.id = id;
        this.oneShot = oneShot;
    };
    timer.Interval.stamp = function() {
        return new Date().getTime();
    };
    timer.Interval.prototype = {
        execute: function() {
            this.callback();
        }
    };
    timer.RAFTimer = function() {
        this.idCounter = 0;
        this.intervals = [];
        window.requestAnimationFrame($bind(this, this.run));
    };
    timer.RAFTimer.prototype = {
        run: function(f) {
            var now = this.timeNow();
            var $it0 = HxOverrides.iter(this.intervals);
            while ($it0.hasNext()) {
                var interval = $it0.next();
                var elapsed = now - interval.last_run;
                if (elapsed >= interval.time_ms) {
                    interval.execute();
                    if (interval.oneShot) HxOverrides.remove(this.intervals, interval);
                    else interval.last_run = now;
                }
            }
            window.requestAnimationFrame($bind(this, this.run));
        },
        setInterval: function(fn, time_ms) {
            var interval = new timer.Interval(this.idCounter++, fn, time_ms, this.timeNow(), false);
            this.intervals.push(interval);
            this.sort();
            return interval.id;
        },
        setTimeout: function(fn, time_ms) {
            var timeout = new timer.Interval(this.idCounter++, fn, time_ms, this.timeNow(), true);
            this.intervals.push(timeout);
            this.sort();
            return timeout.id;
        },
        clearInterval: function(id) {
            this.clearIntervalInternal(id);
        },
        clearTimeout: function(id) {
            this.clearIntervalInternal(id);
        },
        timeNow: function() {
            return new Date().getTime();
        },
        clearIntervalInternal: function(id) {
            var interval = this.getInterval(id);
            if (interval != null) HxOverrides.remove(this.intervals, interval);
        },
        getInterval: function(id) {
            var _g1 = 0;
            var _g = this.intervals.length;
            while (_g1 < _g) {
                var i = _g1++;
                if (this.intervals[i].id == id) return this.intervals[i];
            }
            return null;
        },
        sort: function() {
            this.sortTimeStamp = this.timeNow();
            this.intervals.sort($bind(this, this.sortFn));
        },
        sortFn: function(a, b) {
            var elapsed_a = this.sortTimeStamp - a.last_run;
            var elapsed_b = this.sortTimeStamp - b.last_run;
            if (elapsed_a > elapsed_b) return -1;
            else return 1;
        }
    };
    var $_, $fid = 0;

    function $bind(o, m) {
        if (m == null) return null;
        if (m.__id__ == null) m.__id__ = $fid++;
        var f;
        if (o.hx__closures__ == null) o.hx__closures__ = {};
        else f = o.hx__closures__[m.__id__];
        if (f == null) {
            f = function() {
                return f.method.apply(f.scope, arguments);
            };
            f.scope = o;
            f.method = m;
            o.hx__closures__[m.__id__] = f;
        }
        return f;
    }
    if (Array.prototype.indexOf) HxOverrides.indexOf = function(a, o, i) {
        return Array.prototype.indexOf.call(a, o, i);
    };
    Main.main();
})(typeof console != "undefined" ? console : {
    log: function() {}
});

//# sourceURL=timerOverride.js

//# sourceURL=timerOverride.js