function getAnimateFunc(obj)
{
    return function(e)
    {
        obj.animate();
    }
}
function Animator()
{
    this.registered = new Array();
    
    
    this.registerAnimation = registerAnimation;
    this.removeAnimation = removeAnimation;
    this.animate = animate;
    this.timer = null;
    
    
    function registerAnimation(animation)
    {
        if(this.timer == null)
        {
            //
            this.timer = window.setInterval(getAnimateFunc(this),50);
        }
        this.registered.push(animation);
    }
    
    function removeAnimation(animation)
    {
        
        for(var i = 0; i < this.registered.length; i++)
        {
            if(this.registered[i] == animation)
            {
                for(var j = i+1; i < this.registered.length;j++)
                {
                    this.registered[i] = this.registered[j];
                    i = j;
                }
            }
        }
        //removes the last element since its not used, corrects the length
        this.registered.pop();
        //create a new array
        return;
    }
    
    function animate()
    {
        if(this.registered.length == 0)
        {
            window.clearInterval(this.timer);
            this.timer = null;
            return;
        }
        for(var i = 0; i < this.registered.length; i++)
        {
            //check if animation isQueued, if it is, check to see
            //if any other animation is using that element for that particular style
            //if it is, wait until it is finished and dequeue from the queue
            if(!this.registered[i].isFinished)
                this.registered[i].execute();
            else
            {
                this.removeAnimation(this.registered[i]);
            }
        }
    }
}
