﻿(function ($) {
    var methods = {
        load: function (options) {
            options = options || {};
            if (!options.pageName) options.pageName = $('title').html().replace(/^\s+|\s+$/g, '');
            if (!options.channel) options.channel = $('li.selectedLava a').html();
            $.extend(s, options);
            //set eVars
            var linkTrackVars = [];
            for (var prop in options) {
                if (prop.indexOf('prop') == 0) {
                    s['eVar' + prop.substr(4)] = s[prop];
                    linkTrackVars.push(prop);
                }
            }
            linkTrackVars.push('events');
            s.linkTrackVars = linkTrackVars.join(',');
            s.events = s.linkTrackEvents;
            s.t();
            s.events = '';
        },

        fire: function (options) {
            //prop1
            if (window.location.pathname.indexOf('equipment-by-type') !== -1 && window.location.pathname.indexOf('ft') !== -1) {
                options.prop1 = $('.breadcrumbs a').last().html();
            }

            //prop2
            if (window.location.pathname.indexOf('equipment-by-type') !== -1 && window.location.pathname.indexOf('ft') === -1) {
                options.prop2 = $('.breadcrumbs a').last().html();
            }

            //prop3
            if (window.location.pathname.indexOf('equipment-by-industry') !== -1) {
                options.prop3 = $('.breadcrumbs a').last().html();
            }

            options.pageName = $('title').html().replace(/^\s+|\s+$/g, '');
            options.channel = $('li.selectedLava a').html();

            $.extend(s, options);

            //set eVars
            var linkTrackVars = [];
            for (var prop in options) {
                if (prop.indexOf('prop') == 0) {
                    s['eVar' + prop.substr(4)] = s[prop];
                    linkTrackVars.push(prop);
                }
            }
            linkTrackVars.push('events');
            s.linkTrackVars = linkTrackVars.join(',');

            s.events = s.linkTrackEvents;

            if (this.href === undefined) {
                if ($(this).attr('href') !== undefined) {
                    this.href = $(this).attr('href');
                } else {
                    this.href = window.location.href;
                }
            }
            var linkType = options.exit ? 'e' : 'o';
            s.tl(this, linkType, s.events);
            s.events = '';
        }
    };

    $.fn.tag = function (method) {
        if (methods[method]) {
            return methods[method].apply(this, Array.prototype.slice.call(arguments, 1));
        } else if (typeof method === 'object' || !method) {
            return methods.init().apply(this, arguments);
        } else {
            $.error('Method ' + method + ' does not exist on jQuery.tag');
        }
    };

})(jQuery);
