﻿//Addon
;(function($) {

    $.tracker = function() {

        //Add providers through addons
        this.providers = [];

        //Does the tracking
        this.track = function(data, command) {
            var that = this;

            //For all the addons, apply their functions 
            $.each(providers, function(index, value) {

                if (typeof value == 'function') {
                    value.apply(that, [data, command]);
                }

            });
        }

        return this;

    } ();

    // Add a function for jQuery object events and chaining
    //
    // Data - data to capture about this tracking command
    // Command - the name of the command to track
    // [Event] - Optional event to bind to these and future objects
    $.fn.track = function(data, command, event) {
    
        if (typeof event == 'string' && event != null) {
            $(this).bind(event, function() {
                $.tracker.track.apply(this, [data, command]);
            });
        }
        else {
            $.tracker.track.apply(this, [data, command]);
        }

        return this;
    }

})(jQuery);