﻿var ferrari = ferrari || {};

ferrari.analytics = {
    modules: [],
    moduleCount: 0,
    moduleLoadCount: 0,

    addModule: function (module) {
        this.modules.push(module);
        this.moduleLoadCount++;
        if (this.moduleLoadCount == this.moduleCount && this.modulesLoaded)
            this.modulesLoaded();
    },

    modulesLoaded: null,

    trackEvent: function (event) {
        // Go through each module and see if it has a function to handle this event
        for (var i = 0; i < this.modules.length; i++) {
            if (typeof this.modules[i][event.name] == 'function')
                this.modules[i][event.name].apply(this.modules[i], event.parameters);
        }
    }
};
