// +------------------------------------------------------------+
// | CLASSES                                                    |
// +------------------------------------------------------------+

function _t_ct_pt(id, sdid, aid)
{
    this.version = 'v2';
    this.id      = id;
    this.sdid    = sdid;
    this.aid     = aid;
    this.key     = null;
    this.referer = encodeURIComponent(window.location.href);
    this.ctutn   = null;
    this.ctutv   = null;
    this.tpid    = null;
    this.rcs_l   = null;
    this.rcs_t   = null;
    this.rcs_d   = null;
    this.rcs_i   = null;

    // Complex pixel values.
    this.action_type        = null;
    this.initial_fire_delay = null;
    this.num_fires_per_view = null;
    this.fire_repeat_sleep  = null;
    this.total_num_fired    = null;

    // +----------------+
    // | Public Methods |
    // +----------------+

    this.get_page_view_tracker = function()
    {
        return this._get_tracking_base_url()
               + 't.gif'
               + '?c='
               + this.id
               + '&r='
               + this.referer
               + '&s=1'
               + '&a='
               + this.aid
               + this._get_ctu_qs()
               + this._get_tpid_qs()
               + this._get_rcs_qs();
    };

    this.set_rcs = function(l, t, d, i)
    {
        this.rcs_l = encodeURIComponent(l);
        this.rcs_i = encodeURIComponent(i);

        this.rcs_t = t;
        if (t.length > 100)
        {
            this.rcs_t = t.substr(0, 97) + '...';
        }

        this.rcs_d = d;
        if (d.length > 250)
        {
            this.rcs_d = d.substr(0, 247) + '...';
        }

        this.rcs_t = encodeURIComponent(this.rcs_t);
        this.rcs_d = encodeURIComponent(this.rcs_d);
    };

    this.set_tpid = function(tpid)
    {
        this.tpid = encodeURIComponent(tpid);
    };

    this.set_complex_fire_values = function(action_type,
                                            initial_fire_delay,
                                            num_fires_per_view,
                                            fire_repeat_sleep)
    {
        this.action_type = action_type;
        this.initial_fire_delay = initial_fire_delay;
        this.num_fires_per_view = num_fires_per_view;
        this.fire_repeat_sleep = fire_repeat_sleep;

        this.total_num_fired = 0;
    }

    this.track_action_complex = function()
    {
        var inst = this;

        if (this.action_type === 'delayed' && this.total_num_fired === 0)
        {
            setTimeout(function() {
                inst.track_action();
            }, this.initial_fire_delay * 1000);

            return;
        }
        else if (this.action_type === 'repetitive')
        {
            if (this.total_num_fired === 0)
            {
                setTimeout(function() {
                    inst.track_action();
                }, this.initial_fire_delay * 1000);
            }
            else if (this.total_num_fired <= this.num_fires_per_view)
            {
                setTimeout(function() {
                    inst.track_action();
                }, this.fire_repeat_sleep * 1000);
            }
        }
    }

    this.is_complex = function () {
        return this.action_type === 'delayed' || this.action_type === 'repetitive';
    }

    this.track_action = function()
    {
        if (this.is_complex() &&
            this.total_num_fired === this.num_fires_per_view)
        {
            return;
        }

        var img;

        img = document.createElement('img');
        img.id = 'tpv';
        img.width = '1';
        img.height = '1';
        img.src = this._cache_bust(this.get_page_view_tracker());
        img.alt = '';

        document.body.appendChild(img);

        this.total_num_fired++;

        if (this.is_complex())
        {
            this.track_action_complex();
        }
    };

    // +-----------------+
    // | Private Methods |
    // +-----------------+

    this._cache_bust = function(url)
    {
        return this._url_adjoin_qs(url, { api_z : Math.random() });
    };

    this._cast_to_string = function(a)
    {
        if (typeof a == 'boolean')
        {
            return a ? '1' : '0';
        }

        if (typeof a == 'object' && !a)
        {
            return '';
        }

        return encodeURIComponent('' + a);
    };

    this._get_ctu_qs = function()
    {
        var qs;

        qs = '';
        if (this.ctutn != null && this.ctutv != null)
        {
            qs = '&' + this.ctutn + '=' + this.ctutv;
        }

        return qs;
    };

    this._get_env_prefix = function()
    {
        switch (this.sdid)
        {
            case 1:
                return 'local-';

            case 2:
                return 'qa-';

            case 4:
                return 'staging-';

            default:
                return '';
        }
    };

    this._get_env_name = function()
    {
        switch (this.sdid)
        {
            case 1:
                return 'local';

            case 2:
                return 'qa';

            case 4:
                return 'staging';

            default:
                return 'prod';
        }
    }

    this._get_rcs_qs = function()
    {
        var qs;

        qs = '';
        if (this.rcs_l != null && this.rcs_t != null && this.rcs_d != null)
        {
            qs =   '&rcs_l=' + this.rcs_l
                 + '&rcs_t=' + this.rcs_t
                 + '&rcs_d=' + this.rcs_d
                 + '&rcs_i=' + this.rcs_i;
        }

        return qs;
    };

    this._get_tpid_qs = function()
    {
        var qs;

        qs = '';
        if (this.tpid != null && this.tpid.length > 0)
        {
            qs = '&tpid=' + this.tpid;
        }

        return qs;
    };

    this._get_tracking_base_url = function()
    {
        return document.location.protocol
               + '//'
               + this._get_env_prefix()
               + 't.crowdtwist.com/'
               + this.version
               + '/';
    };

    this._url_adjoin_qs = function(url, table)
    {
        var parts = url.split('?');
        var vars = [];

        if (parts.length == 2)
        {
            var name_value_pairs = parts[1].split('&');
            for (var i = 0; i < name_value_pairs.length; i++)
            {
                var name = name_value_pairs[i].split('=')[0];
                if (name && !table.hasOwnProperty(name))
                {
                    vars.push(name_value_pairs[i]);
                }
            }
        }

        for (var key in table)
        {
            vars.push(key + '=' + this._cast_to_string(table[key]));
        }

        return parts[0] + '?' + vars.join('&');
    };
};

// +------------------------------------------------------------+
// | CLIENT FUNCTIONS                                           |
// +------------------------------------------------------------+

/**
 * Rendered:     2015-04-26 15:43:11
 * Site ID:      2
 * Client ID:    21
 * Cachebuster:  gjsd87fgh8s67hi87jo4q89
 * Num. Actions: 27
 */

/**
 * Action name:    Added Bid For Pink Twibbon
 * Action created: 2013-10-01 17:40:03
 */
function ct_trck_added_bid_for_pink_twibbon(options)
{
    try
    {
        var t = new _t_ct_pt('2-21', 3, 265);

        t.set_tpid((options.content_identifier ?
                        options.content_identifier : ''));

        if (options.link && options.title && options.desc)
        {
            t.set_rcs(options.link,
                      options.title,
                      options.desc,
                      (options.image ? options.image : null));
        }

        t.track_action();
    }
    catch (err) {}

}

/**
 * Action name:    Added Pandora Station
 * Action created: 2012-12-28 14:37:09
 */
function ct_trck_added_pandora_station(options)
{
    try
    {
        var t = new _t_ct_pt('2-21', 3, 188);

        t.set_tpid((options.content_identifier ?
                        options.content_identifier : ''));

        if (options.link && options.title && options.desc)
        {
            t.set_rcs(options.link,
                      options.title,
                      options.desc,
                      (options.image ? options.image : null));
        }

        t.track_action();
    }
    catch (err) {}

}

/**
 * Action name:    Entered Frame by Frame Sweeps
 * Action created: 2013-01-31 12:28:42
 */
function ct_trck_entered_frame_by_frame_sweeps(options)
{
    try
    {
        var t = new _t_ct_pt('2-21', 3, 190);

        t.set_tpid((options.content_identifier ?
                        options.content_identifier : ''));

        if (options.link && options.title && options.desc)
        {
            t.set_rcs(options.link,
                      options.title,
                      options.desc,
                      (options.image ? options.image : null));
        }

        t.track_action();
    }
    catch (err) {}

}

/**
 * Action name:    Played a Song
 * Action created: 2013-06-12 21:06:57
 */
function ct_trck_song(options)
{
    try
    {
        var t = new _t_ct_pt('2-21', 3, 219);

        t.set_tpid((options.content_identifier ?
                        options.content_identifier : ''));

        if (options.link && options.title && options.desc)
        {
            t.set_rcs(options.link,
                      options.title,
                      options.desc,
                      (options.image ? options.image : null));
        }

        t.track_action();
    }
    catch (err) {}

}

/**
 * Action name:    Read Article
 * Action created: 2012-07-24 00:00:00
 */
function ct_trck_article(options)
{
    try
    {
        var t = new _t_ct_pt('2-21', 3, 134);

        t.set_complex_fire_values('delayed', 30, 5, null);

        t.set_tpid((options.content_identifier ?
                        options.content_identifier : ''));

        if (options.link && options.title && options.desc)
        {
            t.set_rcs(options.link,
                      options.title,
                      options.desc,
                      (options.image ? options.image : null));
        }

        t.track_action_complex();
    }
    catch (err) {}

}

/**
 * Action name:    Signed Up For Arby's Email Newsletter
 * Action created: 2013-07-09 09:20:44
 */
function ct_trck_signed_up_for_arbys_email_newsletter(options)
{
    try
    {
        var t = new _t_ct_pt('2-21', 3, 223);

        t.set_tpid((options.content_identifier ?
                        options.content_identifier : ''));

        if (options.link && options.title && options.desc)
        {
            t.set_rcs(options.link,
                      options.title,
                      options.desc,
                      (options.image ? options.image : null));
        }

        t.track_action();
    }
    catch (err) {}

}

/**
 * Action name:    Signed Up For NCL Newsletter
 * Action created: 2013-09-12 17:57:22
 */
function ct_trck_signed_up_for_ncl_newsletter(options)
{
    try
    {
        var t = new _t_ct_pt('2-21', 3, 245);

        t.set_tpid((options.content_identifier ?
                        options.content_identifier : ''));

        if (options.link && options.title && options.desc)
        {
            t.set_rcs(options.link,
                      options.title,
                      options.desc,
                      (options.image ? options.image : null));
        }

        t.track_action();
    }
    catch (err) {}

}

/**
 * Action name:    Signed Up For Papa John's Email Newsletter
 * Action created: 2013-09-12 17:57:22
 */
function ct_trck_signed_up_for_papa_johns_email_newsletter(options)
{
    try
    {
        var t = new _t_ct_pt('2-21', 3, 246);

        t.set_tpid((options.content_identifier ?
                        options.content_identifier : ''));

        if (options.link && options.title && options.desc)
        {
            t.set_rcs(options.link,
                      options.title,
                      options.desc,
                      (options.image ? options.image : null));
        }

        t.track_action();
    }
    catch (err) {}

}

/**
 * Action name:    Signed Up for Tropicana Email Newsletter
 * Action created: 2013-07-10 13:49:13
 */
function ct_trck_signed_up_for_tropicana_email_newsletter(options)
{
    try
    {
        var t = new _t_ct_pt('2-21', 3, 225);

        t.set_tpid((options.content_identifier ?
                        options.content_identifier : ''));

        if (options.link && options.title && options.desc)
        {
            t.set_rcs(options.link,
                      options.title,
                      options.desc,
                      (options.image ? options.image : null));
        }

        t.track_action();
    }
    catch (err) {}

}

/**
 * Action name:    Submitted Super Bowl Halftime Contest Photo
 * Action created: 2012-12-28 14:39:03
 */
function ct_trck_submitted_super_bowl_halftime_contest_photo(options)
{
    try
    {
        var t = new _t_ct_pt('2-21', 3, 189);

        t.set_tpid((options.content_identifier ?
                        options.content_identifier : ''));

        if (options.link && options.title && options.desc)
        {
            t.set_rcs(options.link,
                      options.title,
                      options.desc,
                      (options.image ? options.image : null));
        }

        t.track_action();
    }
    catch (err) {}

}

/**
 * Action name:    Viewed Hard Rock Menu
 * Action created: 2014-06-12 14:38:07
 */
function ct_trck_viewed_hard_rock_menu(options)
{
    try
    {
        var t = new _t_ct_pt('2-21', 3, 335);

        t.set_tpid((options.content_identifier ?
                        options.content_identifier : ''));

        if (options.link && options.title && options.desc)
        {
            t.set_rcs(options.link,
                      options.title,
                      options.desc,
                      (options.image ? options.image : null));
        }

        t.track_action();
    }
    catch (err) {}

}

/**
 * Action name:    Viewed Marcus Theater Locations
 * Action created: 2014-06-12 14:36:48
 */
function ct_trck_viewed_marcus_theater_locations(options)
{
    try
    {
        var t = new _t_ct_pt('2-21', 3, 334);

        t.set_tpid((options.content_identifier ?
                        options.content_identifier : ''));

        if (options.link && options.title && options.desc)
        {
            t.set_rcs(options.link,
                      options.title,
                      options.desc,
                      (options.image ? options.image : null));
        }

        t.track_action();
    }
    catch (err) {}

}

/**
 * Action name:    Viewed MLB Moments
 * Action created: 2013-08-23 14:48:58
 */
function ct_trck_viewed_mlb_moments(options)
{
    try
    {
        var t = new _t_ct_pt('2-21', 3, 241);

        t.set_tpid((options.content_identifier ?
                        options.content_identifier : ''));

        if (options.link && options.title && options.desc)
        {
            t.set_rcs(options.link,
                      options.title,
                      options.desc,
                      (options.image ? options.image : null));
        }

        t.track_action();
    }
    catch (err) {}

}

/**
 * Action name:    Viewed Photos
 * Action created: 2013-04-11 00:00:00
 */
function ct_trck_photos(options)
{
    try
    {
        var t = new _t_ct_pt('2-21', 3, 201);

        t.set_tpid((options.content_identifier ?
                        options.content_identifier : ''));

        if (options.link && options.title && options.desc)
        {
            t.set_rcs(options.link,
                      options.title,
                      options.desc,
                      (options.image ? options.image : null));
        }

        t.track_action();
    }
    catch (err) {}

}

/**
 * Action name:    Visited Arby's Site
 * Action created: 2013-07-09 09:20:44
 */
function ct_trck_visited_arbys_site(options)
{
    try
    {
        var t = new _t_ct_pt('2-21', 3, 222);

        t.set_tpid((options.content_identifier ?
                        options.content_identifier : ''));

        if (options.link && options.title && options.desc)
        {
            t.set_rcs(options.link,
                      options.title,
                      options.desc,
                      (options.image ? options.image : null));
        }

        t.track_action();
    }
    catch (err) {}

}

/**
 * Action name:    Visited Diet Pepsi
 * Action created: 2013-09-25 19:31:09
 */
function ct_trck_visited_diet_pepsi(options)
{
    try
    {
        var t = new _t_ct_pt('2-21', 3, 258);

        t.set_tpid((options.content_identifier ?
                        options.content_identifier : ''));

        if (options.link && options.title && options.desc)
        {
            t.set_rcs(options.link,
                      options.title,
                      options.desc,
                      (options.image ? options.image : null));
        }

        t.track_action();
    }
    catch (err) {}

}

/**
 * Action name:    Visited Flavorwire
 * Action created: 2013-10-09 21:08:28
 */
function ct_trck_visited_flavorwire(options)
{
    try
    {
        var t = new _t_ct_pt('2-21', 3, 266);

        t.set_tpid((options.content_identifier ?
                        options.content_identifier : ''));

        if (options.link && options.title && options.desc)
        {
            t.set_rcs(options.link,
                      options.title,
                      options.desc,
                      (options.image ? options.image : null));
        }

        t.track_action();
    }
    catch (err) {}

}

/**
 * Action name:    Visited Marcus Theaters
 * Action created: 2014-06-12 00:00:00
 */
function ct_trck_visited_marcus_theaters(options)
{
    try
    {
        var t = new _t_ct_pt('2-21', 3, 333);

        t.set_tpid((options.content_identifier ?
                        options.content_identifier : ''));

        if (options.link && options.title && options.desc)
        {
            t.set_rcs(options.link,
                      options.title,
                      options.desc,
                      (options.image ? options.image : null));
        }

        t.track_action();
    }
    catch (err) {}

}

/**
 * Action name:    Visited NFL Pink
 * Action created: 2013-09-25 19:31:09
 */
function ct_trck_visited_nfl_pink(options)
{
    try
    {
        var t = new _t_ct_pt('2-21', 3, 259);

        t.set_tpid((options.content_identifier ?
                        options.content_identifier : ''));

        if (options.link && options.title && options.desc)
        {
            t.set_rcs(options.link,
                      options.title,
                      options.desc,
                      (options.image ? options.image : null));
        }

        t.track_action();
    }
    catch (err) {}

}

/**
 * Action name:    Visited Site
 * Action created: 2012-07-24 00:00:00
 */
function ct_trck_site(options)
{
    try
    {
        var t = new _t_ct_pt('2-21', 3, 131);

        t.set_tpid((options.content_identifier ?
                        options.content_identifier : ''));

        if (options.link && options.title && options.desc)
        {
            t.set_rcs(options.link,
                      options.title,
                      options.desc,
                      (options.image ? options.image : null));
        }

        t.track_action();
    }
    catch (err) {}

}

/**
 * Action name:    Visited Thursday Night Football Site
 * Action created: 2013-09-12 17:57:22
 */
function ct_trck_visited_thursday_night_football_site(options)
{
    try
    {
        var t = new _t_ct_pt('2-21', 3, 247);

        t.set_tpid((options.content_identifier ?
                        options.content_identifier : ''));

        if (options.link && options.title && options.desc)
        {
            t.set_rcs(options.link,
                      options.title,
                      options.desc,
                      (options.image ? options.image : null));
        }

        t.track_action();
    }
    catch (err) {}

}

/**
 * Action name:    Visited Tropicana Site
 * Action created: 2013-07-10 13:49:13
 */
function ct_trck_visited_tropicana_site(options)
{
    try
    {
        var t = new _t_ct_pt('2-21', 3, 224);

        t.set_tpid((options.content_identifier ?
                        options.content_identifier : ''));

        if (options.link && options.title && options.desc)
        {
            t.set_rcs(options.link,
                      options.title,
                      options.desc,
                      (options.image ? options.image : null));
        }

        t.track_action();
    }
    catch (err) {}

}

/**
 * Action name:    Watched a Video
 * Action created: 2012-07-24 00:00:00
 */
function ct_trck_video(options)
{
    try
    {
        var t = new _t_ct_pt('2-21', 3, 130);

        t.set_tpid((options.content_identifier ?
                        options.content_identifier : ''));

        if (options.link && options.title && options.desc)
        {
            t.set_rcs(options.link,
                      options.title,
                      options.desc,
                      (options.image ? options.image : null));
        }

        t.track_action();
    }
    catch (err) {}

}

/**
 * Action name:    Watched a Video on Tropicana Las Vegas
 * Action created: 2013-07-10 13:49:13
 */
function ct_trck_watched_a_video_on_tropicana_lv(options)
{
    try
    {
        var t = new _t_ct_pt('2-21', 3, 226);

        t.set_tpid((options.content_identifier ?
                        options.content_identifier : ''));

        if (options.link && options.title && options.desc)
        {
            t.set_rcs(options.link,
                      options.title,
                      options.desc,
                      (options.image ? options.image : null));
        }

        t.track_action();
    }
    catch (err) {}

}

/**
 * Action name:    Watched Jersey Mikes Video
 * Action created: 2014-08-19 15:51:42
 */
function ct_trck_watched_jersey_mikes_video(options)
{
    try
    {
        var t = new _t_ct_pt('2-21', 3, 355);

        t.set_tpid((options.content_identifier ?
                        options.content_identifier : ''));

        if (options.link && options.title && options.desc)
        {
            t.set_rcs(options.link,
                      options.title,
                      options.desc,
                      (options.image ? options.image : null));
        }

        t.track_action();
    }
    catch (err) {}

}

/**
 * Action name:    Watched Sofia Vergara Video
 * Action created: 2013-09-25 19:31:09
 */
function ct_trck_watched_sofia_vergara_video(options)
{
    try
    {
        var t = new _t_ct_pt('2-21', 3, 260);

        t.set_tpid((options.content_identifier ?
                        options.content_identifier : ''));

        if (options.link && options.title && options.desc)
        {
            t.set_rcs(options.link,
                      options.title,
                      options.desc,
                      (options.image ? options.image : null));
        }

        t.track_action();
    }
    catch (err) {}

}

/**
 * Action name:    Watched Video On NCL Website
 * Action created: 2013-09-12 17:57:22
 */
function ct_trck_watched_video_on_ncl_website(options)
{
    try
    {
        var t = new _t_ct_pt('2-21', 3, 248);

        t.set_tpid((options.content_identifier ?
                        options.content_identifier : ''));

        if (options.link && options.title && options.desc)
        {
            t.set_rcs(options.link,
                      options.title,
                      options.desc,
                      (options.image ? options.image : null));
        }

        t.track_action();
    }
    catch (err) {}

}
