    !function (win) {

    var doc           = win.document,
        bodyElement   = doc.body,
        loc           = doc.location,
        readyState    = 'readyState',
        byTag         = 'getElementsByTagName',
        hasOwn        = Object.prototype.hasOwnProperty,
        head          = doc[byTag]('head')[0],
        reqId         = 1,
        homepageRegex = new RegExp('^/(index\.[a-z0-9]{1,5})$'),
        loaded        = {},
        handlers      = {};

    handlers.lotame = function (args) {
        var id = args[0];
        var url = "//tags.crwdcntrl.net/c/" + id + "/cc.js?ns=_cc" + id;

        load(url, { attr: { id: "LOTCC_" + id }, remove: false }, function () {
            var fn = win["_cc" + id];

            fn && fn.bcp();
        });
    };

    handlers.comscore = function (args) {
        var opts = {},
            i,
            len = args.length,
            parts;

        var url = (loc.protocol == "https:" ? "https://sb" : "http://b") + ".scorecardresearch.com/beacon.js";

        for (i = 0; i < len; i++) {
            parts = args[i].split(/:/);
            opts[parts[0]] = parts[1];
        }

        load(url, function (err) {
            COMSCORE.beacon(opts);
        });
    };

    return init([{"include":"all","type":"comscore","args":["c1:2","c2:15476338","c3:","c4:","c5:","c6:","c15:"]},{"include":"all","type":"lotame","args":["3411"]}]);

    function init(scripts) {
        var url = win.location.pathname,
            i, len;

        for (i = 0, len = scripts.length; i < len; i++) {
            if (shouldLoad(scripts[i], url)) {
                process(scripts[i]);
            }
        }
    }


    function shouldLoad(script, url) {
        if (script.include === 'all') {
            return true;
        }

        var isHome = homepageRegex.test(url);

        if (script.include === 'home') {
            return isHome;
        }

        if (script.include === 'ros') {
            return ! isHome;
        }

        // unknown location... freak out.
        return false;
    }


    function process(script) {
        if (hasOwn.call(handlers, script.type)) {
            handlers[script.type].apply(script, [script.args]);
        }
    }


    function load(url, opts, fn) {
        var uniqId = reqId++,
            script = doc.createElement('script'),
            done   = 0,
            isIE10 = navigator.userAgent.indexOf('MSIE 10.0') !== -1;

        if (arguments.length === 2) {
            fn = opts;
            opts = {};
        }

        opts.attr = opts.attr || {};

        // Only load a JS file once
        if (loaded[url] === 1) {
            return fn();
        }

        script.type = 'text/javascript';
        script.src = url;
        script.async = true;
        if (opts.attr) {
            each(opts.attr, function (val, attr) {
                script.setAttribute(attr, val);
            });
        }
        if (typeof script.onreadystatechange !== 'undefined' && !isIE10) {
            // need this for IE due to out-of-order onreadystatechange(), binding script
            // execution to an event listener gives us control over when the script
            // is executed. See http://jaubourg.net/2010/07/loading-script-as-onclick-handler-of.html
            //
            // if this hack is used in IE10 jsonp callback are never called
            script.event = 'onclick';
            script.htmlFor = script.id = '_skpj_' + uniqId;
        }

        script.onload = script.onreadystatechange = function () {
            if ((script[readyState] && script[readyState] !== 'complete' && script[readyState] !== 'loaded') || done) {
                return false;
            }
            script.onload = script.onreadystatechange = null;
            script.onclick && script.onclick();
            loaded[url] = 1;
            // Call the user callback with the last value stored and clean up values and scripts.
            fn();
            if (opts.remove !== false) {
                head.removeChild(script);
            }
            done = 1;
        }

        // Add the script to the DOM head
        head.appendChild(script);

        // Enable script timeout
        return {
            abort: function () {
                script.onload = script.onreadystatechange = null;
                fn('Request is aborted: timeout');
                response = undefined;
                head.removeChild(script);
                loaded = 1;
            }
        }
    }

    function each(iter, fn) {
        var key, item;
        for (key in iter) {
            if (hasOwn.call(iter, key)) {
                fn(iter[key], key, iter);
            }
        }
    }
}(this);
