var Kinetic = {Stage: function(a) {
        this.canvas = a;
        this.fps = 60;
        this.context = a.getContext("2d");
        this.drawStage = this.updateStage = void 0;
        this.mousePos = null;
        this.mouseUp = this.mouseDown = !1;
        this.currentRegion = null;
        this.regionCounter = 0;
        this.lastRegionIndex = null;
        this.t = 0;
        this.timeInterval = 1E3 / this.fps;
        this.intervalId = null;
        this.frame = 0
    }};
Kinetic.Stage.prototype.isMousedown = function() {
    return this.mouseDown
};
Kinetic.Stage.prototype.isMouseup = function() {
    return this.mouseUp
};
Kinetic.Stage.prototype.setDrawStage = function(a) {
    this.drawStage = a;
    this.listen()
};
Kinetic.Stage.prototype.drawStage = function() {
    this.drawStage !== void 0 && (this.clearCanvas(), this.drawStage())
};
Kinetic.Stage.prototype.setUpdateStage = function(a) {
    this.updateStage = a
};
Kinetic.Stage.prototype.getContext = function() {
    return this.context
};
Kinetic.Stage.prototype.clearCanvas = function() {
    this.context.clearRect(0, 0, this.canvas.width, this.canvas.height)
};
Kinetic.Stage.prototype.listen = function() {
    var a = this, c = this.canvas.onmouseover, d = this.canvas.onmouseout, e = this.canvas.onmousemove, f = this.canvas.onmousedown, g = this.canvas.onmouseup;
    this.drawStage !== void 0 && this.drawStage();
    this.canvas.onmouseover = function(b) {
        if (!b)
            b = window.event;
        a.setMousePosition(b);
        typeof c == typeof Function && c()
    };
    this.canvas.onmouseout = function() {
        a.mousePos = null;
        typeof d == typeof Function && d()
    };
    this.canvas.onmousemove = function(b) {
        if (!b)
            b = window.event;
        a.reset(b);
        typeof e == typeof Function && 
        e()
    };
    this.canvas.onmousedown = function(b) {
        if (!b)
            b = window.event;
        a.mouseDown = !0;
        a.reset(b);
        typeof f == typeof Function && f()
    };
    this.canvas.onmouseup = function(b) {
        if (!b)
            b = window.event;
        a.mouseUp = !0;
        a.reset(b);
        typeof g == typeof Function && g()
    }
};
Kinetic.Stage.prototype.beginRegion = function() {
    this.currentRegion = {};
    this.regionCounter++
};
Kinetic.Stage.prototype.addRegionEventListener = function(a, c) {
    if (a == "onmouseover")
        this.currentRegion.onmouseover = c;
    else if (a == "onmouseout")
        this.currentRegion.onmouseout = c;
    else if (a == "onmousemove")
        this.currentRegion.onmousemove = c;
    else if (a == "onmousedown")
        this.currentRegion.onmousedown = c;
    else if (a == "onmouseup")
        this.currentRegion.onmouseup = c
};
Kinetic.Stage.prototype.closeRegion = function() {
    if (this.mousePos !== null && this.context.isPointInPath(this.mousePos.x, this.mousePos.y)) {
        if (this.currentRegion.onmousemove !== void 0)
            this.currentRegion.onmousemove();
        if (this.lastRegionIndex != this.regionCounter && (this.lastRegionIndex = this.regionCounter, this.currentRegion.onmouseover !== void 0))
            this.currentRegion.onmouseover();
        if (this.mouseDown && this.currentRegion.onmousedown !== void 0)
            this.currentRegion.onmousedown(), this.mouseDown = !1;
        if (this.mouseUp && this.currentRegion.onmouseup !== 
        void 0)
            this.currentRegion.onmouseup(), this.mouseUp = !1
    } else if (this.regionCounter == this.lastRegionIndex && (this.lastRegionIndex = null, this.currentRegion.onmouseout !== void 0))
        this.currentRegion.onmouseout();
    this.regionCounter++
};
Kinetic.Stage.prototype.getMousePos = function() {
    return this.mousePos
};
Kinetic.Stage.prototype.setMousePosition = function(a) {
    this.mousePos = {x: a.clientX - this.canvas.offsetLeft + window.pageXOffset,y: a.clientY - this.canvas.offsetTop + window.pageYOffset}
};
Kinetic.Stage.prototype.reset = function(a) {
    this.setMousePosition(a);
    this.regionCounter = 0;
    this.drawStage !== void 0 && (this.clearCanvas(), this.drawStage());
    this.mouseUp = this.mouseDown = !1
};
Kinetic.Stage.prototype.getFrame = function() {
    return this.frame
};
Kinetic.Stage.prototype.start = function() {
    var a = this;
    this.drawStage !== void 0 && this.drawStage();
    this.intervalId = setInterval(function() {
        a.animationLoop()
    }, this.timeInterval)
};
Kinetic.Stage.prototype.stop = function() {
    this.clearInterval(intervalId)
};
Kinetic.Stage.prototype.getTimeInterval = function() {
    return this.timeInterval
};
Kinetic.Stage.prototype.getTime = function() {
    return this.t
};
Kinetic.Stage.prototype.animationLoop = function() {
    this.frame++;
    this.t += this.timeInterval;
    this.clearCanvas();
    this.updateStage !== void 0 && this.updateStage();
    this.drawStage !== void 0 && this.drawStage()
};
