
////////////////////////////////////////////////////////////////////////////////////////////////////
// Trends
////////////////////////////////////////////////////////////////////////////////////////////////////
var AnimationTrends =
{
    'Damper' : function(iProgress)
        {
            alert('Not implemented');
        },

    'Linear' : function(iProgress)
        {
            return iProgress;
        },
        
    'Smooth' : function(iProgress)
        {
            var x2 = iProgress * iProgress;
            var x3 = x2 * iProgress;
            return (-2 * x3) + (3 * x2);        
        }
};


////////////////////////////////////////////////////////////////////////////////////////////////////
// Animation
////////////////////////////////////////////////////////////////////////////////////////////////////
function Animation(iTrend, iLength, iTicksPerSecond)
{
    var self = this;

    self.trend = null;
    self.length = null;
    self.delay = null;
    self.timer = null;
    
    self.onUpdate = new EventHandler();
    self.onComplete = new EventHandler();
    
    self.init = function(iTrend, iLength, iTicksPerSecond)
        {
            self.trend = iTrend;
            self.length = iLength;
            self.delay = 1000 / iTicksPerSecond;
            self.timer = new Timer(self._onUpdate, true);
        }

    self.start = function()
        {
            self.timer.start(self.delay);
        }

    self.stop = function()
        {
            self.timer.stop();
        }

    self._onUpdate = function()
        {
            var progress = self.timer.getTime() / self.length;
            
            if (progress >= 1.0)
            {
                progress = 1.0;
                self.timer.stop();
            }
           
            self.onUpdate.invoke(self.trend(progress));

            if (progress >= 1.0)
                self.onComplete.invoke();
        }


    self.init(iTrend, iLength, iTicksPerSecond);

}

