
// Starts up timers etc.
function Engine()
{
    this.time = 0;
    this.key = [];
    this.player = null;
    this.lastTime = 0;

    var up = new Function('if(engine)engine.keyup(arguments[0] || window.event);');
    var down = new Function('if(engine)engine.keydown(arguments[0] || window.event);');
    
    if(document.body.attachEvent) {
        
        document.attachEvent('onkeyup', up);
        document.attachEvent('onkeydown', down);
    }
    else {
        
        document.addEventListener('keyup', up, false);
        document.addEventListener('keydown', down, false);
    }
    
    sendRequest('tod/datafile.txt', null, Animation.loadAnimations);
}

Engine.prototype.isDone = function()
{
    return !!Animation.animations;
}

function timerFunction(index)
{
    engine.time += 10;

    setTimeout(timerFunction, 10);
}

Engine.prototype.startTimer = function()
{
    timerFunction();
}

Engine.prototype.getScroll = function()
{
    if(window.pageYOffset != null)
        return window.pageYOffset;

    if(document.body && document.body.scrollTop != null)
        return document.body.scrollTop;

    if(document.documentElement && document.documentElement.scrollTop != null)
        return document.documentElement.scrollTop;

    return 0;
}

Engine.prototype.getWidth = function()
{
    if(window.innerWidth != null)
        return window.innerWidth;

    if(document.body && document.body.clientWidth != null)
        return document.body.clientWidth;

    if(document.documentElement && document.documentElement.clientWidth != null)
        return document.documentElement.clientWidth;
}

Engine.prototype.getHeight = function()
{
    if(window.innerHeight != null)
        return window.innerHeight;

    if(document.body && document.body.clientHeight != null)
        return document.body.clientHeight;

    if(document.documentElement && document.documentElement.clientHeight != null)
        return document.documentElement.clientHeight;
}

Engine.prototype.keyup = function(ev)
{
    this.key[ev.keyCode || ev.which] = false;
}

Engine.prototype.keydown = function(ev)
{
    this.key[ev.keyCode || ev.which] = true;
}
