    !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.teads = function (args) {
        window._ttf = window._ttf || [],doc = window.top.document
        ,_tt_slot = args[1]
        ,_tt_minSlot = 2
        ,_tt_slot1 = args[2]
        ,_tt_BTF = true
        ,_tt_filter =  function (obj) {return obj['wrappedSizes']['width'] > 400;}
        ,_tt_check1 = doc.querySelectorAll(_tt_slot1).length;


        if(_tt_check1 > 0){
        _tt_slot = _tt_slot1;
        _tt_filter =  function (obj) {return obj['wrappedSizes']['width'] > 200;} ;
        _tt_BTF = false;
        }

        _ttf.push({
        pid        : args[0]
        ,slot      : _tt_slot
        ,lang      : 'en'
        ,format    : 'inread'
        ,BTF       : _tt_BTF
        ,minSlot   : _tt_minSlot
        ,filter    : _tt_filter
        });
        (function(d) {
        var js, s = d.getElementsByTagName('script')[0];
        js = d.createElement('script');
        js.async = true;
        js.src = "//cdn.teads.tv/js/all-v1.js";
        s.parentNode.insertBefore(js, s);
        })(window.document);
    };

    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"]},{"include":"ros","type":"teads","args":["<script type=\"text\/javascript\">\r\nwindow._ttf = window._ttf || [];\r\n_ttf.push({\r\n       pid          : 26691\r\n       ,lang        : \"en\"\r\n       ,slot        : '.min2 .pm .Rl1b br, .min .hrecipe .RecipeDirections'\r\n       ,format      : \"inread\"\r\n       ,minSlot     : 0\r\n       ,BTF         : false\r\n,passBack : function(num) {\r\n       \tvar scriptTag = document.createElement(\"script\");\r\n\t\tscriptTag.src = \"http:\/\/as.ebz.io\/api\/choixPubJS.htm?pid=1126162&screenLayer=1&mode=NONE&home=http:\/\/drinksmixer.com\";\r\n\t\tdocument.body.appendChild(scriptTag);\t\r\n\t}\r\n});\r\n\r\n(function (d) {\r\n        var js, s = d.getElementsByTagName('script')[0];\r\n        js = d.createElement('script');\r\n        js.async = true;\r\n        js.src = '\/\/cdn.teads.tv\/js\/all-v1.js';\r\n        s.parentNode.insertBefore(js, s);\r\n})(window.document);\r\n<\/script>",".wrapper .RecipeDirections.instructions",".wrapper .content.global_lists instruction > span"]}]);

    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);
