/* Minification failed. Returning unminified contents.
(8,7-8): run-time error JS1005: Expected '(': {
(9,5-11): run-time error JS1009: Expected '}': window
(9,5-11): run-time error JS1006: Expected ')': window
(9,5-11): run-time error JS1008: Expected '{': window
(9,11-12): run-time error JS1195: Expected expression: .
(462,43-46): run-time error JS1009: Expected '}': ...
(462,43-46): run-time error JS1006: Expected ')': ...
(462,29): run-time error JS1004: Expected ';'
(463,10-11): run-time error JS1009: Expected '}': )
(44,24): run-time error JS1004: Expected ';'
(463,10-11): run-time error JS1195: Expected expression: )
(464,5-6): run-time error JS1002: Syntax error: }
(464,6-7): run-time error JS1195: Expected expression: ,
(465,22-23): run-time error JS1010: Expected identifier: (
(471,6-7): run-time error JS1195: Expected expression: ,
(472,29-30): run-time error JS1010: Expected identifier: (
(476,43-46): run-time error JS1009: Expected '}': ...
(476,43-46): run-time error JS1006: Expected ')': ...
(476,29): run-time error JS1004: Expected ';'
(477,10-11): run-time error JS1195: Expected expression: )
(478,5-6): run-time error JS1002: Syntax error: }
(478,6-7): run-time error JS1195: Expected expression: ,
(479,26-27): run-time error JS1010: Expected identifier: (
(508,6-7): run-time error JS1195: Expected expression: ,
(509,25-26): run-time error JS1010: Expected identifier: (
(514,6-7): run-time error JS1195: Expected expression: ,
(515,28-29): run-time error JS1010: Expected identifier: (
(531,6-7): run-time error JS1195: Expected expression: ,
(532,29-30): run-time error JS1010: Expected identifier: (
(548,6-7): run-time error JS1195: Expected expression: ,
(551,18): run-time error JS1004: Expected ';'
(551,18-19): run-time error JS1195: Expected expression: :
(551,29-30): run-time error JS1010: Expected identifier: (
(558,10-11): run-time error JS1195: Expected expression: ,
(559,24-25): run-time error JS1010: Expected identifier: (
(581,6-7): run-time error JS1195: Expected expression: ,
(582,26-27): run-time error JS1010: Expected identifier: (
(592,6-7): run-time error JS1195: Expected expression: ,
(595,13): run-time error JS1004: Expected ';'
(595,13-14): run-time error JS1195: Expected expression: :
(595,24-25): run-time error JS1010: Expected identifier: (
(675,10-11): run-time error JS1195: Expected expression: ,
(676,27-28): run-time error JS1010: Expected identifier: (
(688,6-7): run-time error JS1195: Expected expression: ,
(690,17): run-time error JS1004: Expected ';'
(690,17-18): run-time error JS1195: Expected expression: :
(690,28-29): run-time error JS1010: Expected identifier: (
(734,6-7): run-time error JS1195: Expected expression: ,
(737,13): run-time error JS1004: Expected ';'
(737,13-14): run-time error JS1195: Expected expression: :
(737,24-25): run-time error JS1010: Expected identifier: (
(753,25-28): run-time error JS1009: Expected '}': ...
(753,25-28): run-time error JS1006: Expected ')': ...
(752,38): run-time error JS1004: Expected ';'
(754,29): run-time error JS1004: Expected ';'
(754,29-30): run-time error JS1195: Expected expression: :
(755,31): run-time error JS1004: Expected ';'
(755,31-32): run-time error JS1195: Expected expression: :
(756,35): run-time error JS1004: Expected ';'
(756,35-36): run-time error JS1195: Expected expression: :
(757,35): run-time error JS1004: Expected ';'
(757,35-36): run-time error JS1195: Expected expression: :
(758,37): run-time error JS1004: Expected ';'
(758,37-38): run-time error JS1195: Expected expression: :
(759,21-22): run-time error JS1195: Expected expression: }
(759,22-23): run-time error JS1195: Expected expression: )
(776,15-19): run-time error JS1034: Unmatched 'else'; no 'if' defined: else
(793,37-40): run-time error JS1009: Expected '}': ...
(793,37-40): run-time error JS1194: Expected ',' or ']': ...
(793,37-40): run-time error JS1009: Expected '}': ...
(793,37-40): run-time error JS1009: Expected '}': ...
(793,37-40): run-time error JS1009: Expected '}': ...
(793,37-40): run-time error JS1006: Expected ')': ...
(788,37): run-time error JS1004: Expected ';'
(794,41): run-time error JS1004: Expected ';'
(794,41-42): run-time error JS1195: Expected expression: :
(795,43): run-time error JS1004: Expected ';'
(795,43-44): run-time error JS1195: Expected expression: :
(796,47): run-time error JS1004: Expected ';'
(796,47-48): run-time error JS1195: Expected expression: :
(797,47): run-time error JS1004: Expected ';'
(797,47-48): run-time error JS1195: Expected expression: :
(798,49): run-time error JS1004: Expected ';'
(798,49-50): run-time error JS1195: Expected expression: :
(799,33-34): run-time error JS1195: Expected expression: }
(799,34-35): run-time error JS1006: Expected ')': ]
(802,21-22): run-time error JS1002: Syntax error: }
(802,22-23): run-time error JS1195: Expected expression: )
(803,17-18): run-time error JS1002: Syntax error: }
(803,18-19): run-time error JS1195: Expected expression: )
(807,13-14): run-time error JS1002: Syntax error: }
(809,9-10): run-time error JS1002: Syntax error: }
(809,10-11): run-time error JS1195: Expected expression: ,
(810,27-28): run-time error JS1010: Expected identifier: (
(822,5-6): run-time error JS1002: Syntax error: }
(822,6-7): run-time error JS1195: Expected expression: ,
(825,13): run-time error JS1004: Expected ';'
(825,13-14): run-time error JS1195: Expected expression: :
(825,24-25): run-time error JS1010: Expected identifier: (
(841,25-28): run-time error JS1009: Expected '}': ...
(841,25-28): run-time error JS1006: Expected ')': ...
(840,38): run-time error JS1004: Expected ';'
(842,29): run-time error JS1004: Expected ';'
(842,29-30): run-time error JS1195: Expected expression: :
(843,31): run-time error JS1004: Expected ';'
(843,31-32): run-time error JS1195: Expected expression: :
(844,35): run-time error JS1004: Expected ';'
(844,35-36): run-time error JS1195: Expected expression: :
(845,35): run-time error JS1004: Expected ';'
(845,35-36): run-time error JS1195: Expected expression: :
(846,37): run-time error JS1004: Expected ';'
(846,37-38): run-time error JS1195: Expected expression: :
(847,21-22): run-time error JS1195: Expected expression: }
(847,22-23): run-time error JS1195: Expected expression: )
(864,15-19): run-time error JS1034: Unmatched 'else'; no 'if' defined: else
(879,37-40): run-time error JS1009: Expected '}': ...
(879,37-40): run-time error JS1194: Expected ',' or ']': ...
(879,37-40): run-time error JS1009: Expected '}': ...
(879,37-40): run-time error JS1009: Expected '}': ...
(879,37-40): run-time error JS1009: Expected '}': ...
(879,37-40): run-time error JS1006: Expected ')': ...
(873,37): run-time error JS1004: Expected ';'
(880,41): run-time error JS1004: Expected ';'
(880,41-42): run-time error JS1195: Expected expression: :
(881,43): run-time error JS1004: Expected ';'
(881,43-44): run-time error JS1195: Expected expression: :
(882,47): run-time error JS1004: Expected ';'
(882,47-48): run-time error JS1195: Expected expression: :
(883,47): run-time error JS1004: Expected ';'
(883,47-48): run-time error JS1195: Expected expression: :
(884,49): run-time error JS1004: Expected ';'
(884,49-50): run-time error JS1195: Expected expression: :
(885,33-34): run-time error JS1195: Expected expression: }
(885,34-35): run-time error JS1006: Expected ')': ]
(888,21-22): run-time error JS1002: Syntax error: }
(888,22-23): run-time error JS1195: Expected expression: )
(889,17-18): run-time error JS1002: Syntax error: }
(889,18-19): run-time error JS1195: Expected expression: )
(890,13-14): run-time error JS1002: Syntax error: }
(891,9-10): run-time error JS1002: Syntax error: }
(891,10-11): run-time error JS1195: Expected expression: ,
(892,27-28): run-time error JS1010: Expected identifier: (
(902,5-6): run-time error JS1002: Syntax error: }
(902,6-7): run-time error JS1195: Expected expression: ,
(903,27-28): run-time error JS1010: Expected identifier: (
(921,6-7): run-time error JS1195: Expected expression: ,
(922,26-27): run-time error JS1010: Expected identifier: (
(940,6-7): run-time error JS1195: Expected expression: ,
(941,33-34): run-time error JS1010: Expected identifier: (
(957,6-7): run-time error JS1195: Expected expression: ,
(958,24-25): run-time error JS1010: Expected identifier: (
(976,6-7): run-time error JS1195: Expected expression: ,
(977,25-26): run-time error JS1010: Expected identifier: (
(981,6-7): run-time error JS1195: Expected expression: ,
(982,30-31): run-time error JS1010: Expected identifier: (
(984,6-7): run-time error JS1195: Expected expression: ,
(985,27-28): run-time error JS1010: Expected identifier: (
(1062,6-7): run-time error JS1195: Expected expression: ,
(1063,36-37): run-time error JS1010: Expected identifier: (
(1078,6-7): run-time error JS1195: Expected expression: ,
(1079,23-24): run-time error JS1010: Expected identifier: (
(1099,6-7): run-time error JS1195: Expected expression: ,
(1100,29-30): run-time error JS1010: Expected identifier: (
(1107,17-20): run-time error JS1009: Expected '}': ...
(1109,13-19): run-time error JS1033: Expected 'catch': object
(1116,11-16): run-time error JS1195: Expected expression: catch
(1116,20): run-time error JS1004: Expected ';'
(1121,5-6): run-time error JS1002: Syntax error: }
(1121,6-7): run-time error JS1195: Expected expression: ,
(1122,27-28): run-time error JS1010: Expected identifier: (
(1138,6-7): run-time error JS1195: Expected expression: ,
(1139,26-27): run-time error JS1010: Expected identifier: (
(1144,17-20): run-time error JS1009: Expected '}': ...
(1144,17-20): run-time error JS1006: Expected ')': ...
(1142,29): run-time error JS1004: Expected ';'
(1145,13-14): run-time error JS1195: Expected expression: }
(1146,10-11): run-time error JS1195: Expected expression: )
(1147,5-6): run-time error JS1002: Syntax error: }
(1148,1-2): run-time error JS1002: Syntax error: }
(866,70-76): run-time error JS1018: 'return' statement outside of function: return
(779,106-112): run-time error JS1018: 'return' statement outside of function: return
 */

// find polyfill

try {
    var localStorageLength = localStorage.length;
    window.canAccessLocalStorage = true;
}
catch {
    window.canAccessLocalStorage = false;
}

if (!Array.prototype.find) {
    Array.prototype.find = Array.prototype.find || function (callback) {
        if (typeof callback !== "function") {
            throw new TypeError("callback must be a function");
        }
        var list = Object(this);
        var length = list.length >>> 0;
        var thisArg = arguments[1];
        for (var i = 0; i < length; i++) {
            var element = list[i];
            if (callback.call(thisArg, element, i, list)) {
                return element;
            }
        }
    };
}
// Includes polyfill
if (!String.prototype.includes) {
    String.prototype.includes = function (search, start) {
        'use strict';
        if (typeof start !== 'number') {
            start = 0;
        }

        if (start + search.length > this.length) {
            return false;
        } else {
            return this.indexOf(search, start) !== -1;
        }
    };
}

var analyticsEvents = {
    playerConfig: null,
    visible: true,
    init: function () {
        window.dmpLayer = {};
        dmpLayer.url = window.location.href;
        window.biskoLayer = {};

        //event listeners
        document.addEventListener("visibilitychange", function () {
            window.didomiReady = window.didomiOnReady || [];
            window.didomiReady.push(function (Didomi) {
                if (document.visibilityState === 'visible' && !analyticsEvents.visible) {
                    dataLayer.push({ "event": "page_visibility_show" });
                    analyticsEvents.visible = true;
                }
                else if (document.visibilityState === 'hidden' && analyticsEvents.visible) {
                    dataLayer.push({ "event": "page_visibility_hide" });
                    //dataLayer.push({ "event": "page_unload" });
                    analyticsEvents.visible = false;
                }
            });
        });

        if (analyticsModel.pageType === "video" || analyticsModel.pageType === "videoLive") {
            dmpLayer.name = analyticsModel.videoName;
            dmpLayer.live = analyticsModel.live;
            dmpLayer.showSeries = analyticsModel.showSeries;
            dmpLayer.showName = analyticsModel.showName;

            biskoLayer.name = analyticsModel.videoName;
            biskoLayer.live = analyticsModel.live;
            biskoLayer.showSeries = analyticsModel.showSeries;
            biskoLayer.showName = analyticsModel.showName;
            window.didomiOnReady = window.didomiOnReady || [];
            window.didomiOnReady.push(function (Didomi) {
                dataLayer.push(
                    { 'video': { 'id': analyticsModel.id } },
                    { 'videoName': analyticsModel.videoName },
                    { 'live': analyticsModel.live },
                    { 'videoType': analyticsModel.videoType },
                    { 'showSeries': analyticsModel.showSeries },
                    { 'showName': analyticsModel.showName }
                );
            });


            if (analyticsModel.premiumContentEnabled) {
                window.didomiOnReady = window.didomiOnReady || [];
                window.didomiOnReady.push(function (Didomi) {
                    dataLayer.push({
                        'event': 'video_loaded',
                        'videoName': analyticsModel.videoName,
                        'videoId': analyticsModel.id,
                        'videoCategory': analyticsModel.contentTopic,
                        'videoPublished': analyticsModel.videoPublished,
                        'videoLock': analyticsModel.videoLock,
                        'videoPriceTvod': analyticsModel.videoPriceTvod,
                        'videoPriceSvod': analyticsModel.videoPriceSvod,
                        'videoCurrency': analyticsModel.videoCurrency,
                        'videoPremium': analyticsModel.videoPremium,
                        'videoTag': analyticsModel.videoTag
                    })
                });
            }
        } else if (analyticsModel.pageType === 'show') {
            dmpLayer.name = analyticsModel.showName;
            biskoLayer.name = analyticsModel.showName;

            window.didomiOnReady = window.didomiOnReady || [];
            window.didomiOnReady.push(function (Didomi) {
                dataLayer.push({ 'showName': analyticsModel.showName });
            });

        }

        if (analyticsModel.pageType === "video" || analyticsModel.pageType === "show") {
            dmpLayer.hostName = analyticsModel.hostName;
            biskoLayer.hostName = analyticsModel.hostName;

            dmpLayer.category = analyticsModel.contentTopic;
            biskoLayer.category = [analyticsModel.contentTopic];
            window.didomiOnReady = window.didomiOnReady || [];
            window.didomiOnReady.push(function (Didomi) {
                dataLayer.push(
                    { 'hostName': analyticsModel.hostName },
                    { 'contentTopic': analyticsModel.contentTopic }
                );
            });
        }

        if (analyticsModel.pageType === "channel") {
            dmpLayer.hostName = analyticsModel.hostName;
            biskoLayer.hostName = analyticsModel.hostName;

            window.didomiOnReady = window.didomiOnReady || [];
            window.didomiOnReady.push(function (Didomi) {
                dataLayer.push({ 'hostName': analyticsModel.hostName });
            });
        }

        if (dmpLayer.name === undefined) {
            dmpLayer.name = analyticsModel.pageType;
            biskoLayer.name = analyticsModel.pageType;
        }

        dmpLayer.id = analyticsModel.id;
        dmpLayer.type = analyticsModel.pageType;
        dmpLayer.loggedin = analyticsModel.loggedin;

        biskoLayer.id = analyticsModel.id;
        biskoLayer.type = analyticsModel.pageType;
        biskoLayer.loggedin = analyticsModel.loggedin;

        if (analyticsModel.loggedin) {
            dmpLayer.userId = analyticsModel.userId;
            if (typeof biskota != "undefined") {
                biskota.identify(analyticsModel.userId.toString());
            }
            window.didomiOnReady = window.didomiOnReady || [];
            window.didomiOnReady.push(function (Didomi) {
                dataLayer.push(
                    { 'user': { 'id': analyticsModel.userId } }
                );
            });


        }
        window.didomiOnReady = window.didomiOnReady || [];
        window.didomiOnReady.push(function (Didomi) {
            dataLayer.push(
                { 'pageType': analyticsModel.pageType },

                { 'webLocation': webLocation }
            );
        });


        if (analyticsModel.premiumContentEnabled) {
            window.didomiOnReady = window.didomiOnReady || [];
            window.didomiOnReady.push(function (Didomi) {
                dataLayer.push({
                    'loggedin': analyticsModel.loggedin,
                    'userid': analyticsModel.userId,
                    'userPremium': analyticsModel.userPremium,
                    'userExpiration': analyticsModel.userExpiration
                });
            });
        }
        else {
            window.didomiOnReady = window.didomiOnReady || [];
            window.didomiOnReady.push(function (Didomi) {
                dataLayer.push({ 'loggedin': analyticsModel.loggedin })
            });

        }

        if (window.canAccessLocalStorage) {
            for (var i = 0; i < localStorage.length; i++) {
                if (localStorage.key(i) !== null && localStorage.key(i).startsWith("metric1_")) {
                    var metric1Value = parseInt(localStorage.getItem(localStorage.key(i)));
                    var videoId = localStorage.key(i).replace("metric1_", "");
                    localStorage.removeItem("metric1_" + videoId);
                    localStorage.removeItem("metric1Time_" + videoId);
                    i = i - 2;
                    if (metric1Value !== 0) {
                        dmpLayer.metric1 = metric1Value;
                        gjdmp.tr("WatchedTime", { id: videoId, value: metric1Value, type: "video", url: window.location.href });
                        bsk('event', "watchedtime", { id: videoId, value: metric1Value, type: "video" });
                        window.didomiOnReady = window.didomiOnReady || [];
                        window.didomiOnReady.push(function (Didomi) {
                            dataLayer.push({ 'metric1': metric1Value });

                        });

                    }
                }
            }
        }

        window.didomiReady = window.didomiOnReady || [];
        window.didomiReady.push(function (Didomi) {
            dataLayer.push({ "event": "page_ready" });
        })

        gjdmp.tr("PageView", dmpLayer);
        bsk('event', 'pageview', biskoLayer);
    },
    videoShare: function (socialMediaPlatform) {
        if (!socialMediaPlatform)
            socialMediaPlatform = "-";
        window.didomiOnReady = window.didomiOnReady || [];
        window.didomiOnReady.push(function (Didomi) {
            dataLayer.push({
                "event": "social_interaction",
                "social": {
                    "action": "share",
                    "platform": socialMediaPlatform
                }
            });
        });


    },
    videoComment: function (message) {
        console.log(message);
        gjdmp.tr("comment", {
            id: analyticsModel.id,
            name: analyticsModel.videoName,
            value: message,
            type: "comment",
            category: "video",
            url: window.location.href
        });

        bsk("event", "comment", {
            id: analyticsModel.id,
            name: analyticsModel.videoName,
            value: message,
            type: "comment",
            category: ["video"]
        });
        window.didomiOnReady = window.didomiOnReady || [];
        window.didomiOnReady.push(function (Didomi) {
            dataLayer.push({
                'event': "gaEvent",
                'gaEventData': { 'eCat': "Video", 'eAct': "Comment", 'eLab': "-", 'eVal': 1 },
                'eventCallback': function () {
                    dataLayer.push({ 'gaEventData': undefined });
                }
            });
        });


    },
    videoMoreComments: function () {
        gjdmp.tr("morecomments", {
            id: analyticsModel.id,
            name: analyticsModel.videoName,
            type: "comment",
            category: "video",
            url: window.location.href
        });

        bsk("event", "morecomments", {
            id: analyticsModel.id,
            name: analyticsModel.videoName,
            type: "comment",
            category: ["video"]
        });
    },
    videoDeleteComment: function (id) {
        gjdmp.tr("deletecomment", {
            id: analyticsModel.id,
            name: analyticsModel.videoName,
            value: "comment_" + id,
            type: "comment",
            category: "video",
            url: window.location.href
        });

        bsk("event", "deletecomment", {
            id: analyticsModel.id,
            name: analyticsModel.videoName,
            value: "comment_" + id,
            type: "comment",
            category: ["video"]
        });
    },
    videoMoreReplies: function (id) {
        gjdmp.tr("morereplies", {
            id: analyticsModel.id,
            name: analyticsModel.videoName,
            value: "comment_" + id,
            type: "comment",
            category: "video",
            url: window.location.href
        });

        bsk("event", "morereplies", {
            id: analyticsModel.id,
            name: analyticsModel.videoName,
            value: "comment_" + id,
            type: "comment",
            category: ["video"]
        });
    },
    videoReplyComment: function (message) {
        gjdmp.tr("replycomment", {
            id: analyticsModel.id,
            name: analyticsModel.videoName,
            value: message,
            type: "comment",
            category: "video",
            url: window.location.href
        });

        bsk("event", "replycomment", {
            id: analyticsModel.id,
            name: analyticsModel.videoName,
            value: message,
            type: "comment",
            category: ["video"]
        });
    },
    videoDeleteReply: function (id, block) {
        gjdmp.tr("deletereply", {
            id: analyticsModel.id,
            name: analyticsModel.videoName,
            value: "reply_" + id + "_block_" + block,
            type: "video",
            category: "video",
            url: window.location.href
        });

        bsk("event", "deletereply", {
            id: analyticsModel.id,
            name: analyticsModel.videoName,
            value: "reply_" + id + "_block_" + block,
            type: "video",
            category: ["video"]
        });
    },
    videoReact: function (action, id) {
        gjdmp.tr(action.toLowerCase(), {
            id: analyticsModel.id,
            name: analyticsModel.videoName,
            value: "entity_" + id,
            type: "entity",
            category: "video",
            url: window.location.href
        });

        bsk('event', action.toLowerCase(), {
            id: analyticsModel.id,
            name: analyticsModel.videoName,
            value: "entity_" + id,
            type: "entity",
            category: ["video"]
        });
        window.didomiOnReady = window.didomiOnReady || [];
        window.didomiOnReady.push(function (Didomi) {
            dataLayer.push({
                'event': "gaEvent",
                'gaEventData': { 'eCat': "Video", 'eAct': "Rate", 'eLab': action, 'eVal': 1 },
                'eventCallback': function () {
                    dataLayer.push({ 'gaEventData': undefined });
                }
            });
        });
    },
    videoRemoveReact: function (action, id) {
        gjdmp.tr(action.toLowerCase(), {
            id: analyticsModel.id,
            name: analyticsModel.videoName,
            value: "entity_" + id,
            type: "entity",
            category: "video",
            url: window.location.href
        });

        bsk('event', action.toLowerCase(), {
            id: analyticsModel.id,
            name: analyticsModel.videoName,
            value: "entity_" + id,
            type: "entity",
            category: ["video"]
        });
    },
    videoRate: function (action, id, value) {
        gjdmp.tr(action, {
            id: analyticsModel.id,
            name: analyticsModel.videoName,
            value: "entity_" + id + "_value_" + value,
            type: "video",
            category: "video",
            url: window.location.href
        });

        bsk('event', action, {
            id: analyticsModel.id,
            name: analyticsModel.videoName,
            value: "entity_" + id + "_value_" + value,
            type: "video",
            category: ["video"]
        });
    },
    subscribe: function (action) {
        window.didomiOnReady = window.didomiOnReady || [];
        window.didomiOnReady.push(function (Didomi) {
            dataLayer.push({
                'event': "gaEvent",
                'gaEventData': { 'eCat': "User", 'eAct': "ShowSubscription", 'eLab': action, 'eVal': 1 },
                'eventCallback': function () {
                    dataLayer.push({ 'gaEventData': undefined });
                }
            });
        });


    },
    registration: function () {
        window.didomiOnReady = window.didomiOnReady || [];
        window.didomiOnReady.push(function (Didomi) {
            dataLayer.push({
                'event': "gaEvent",
                'gaEventData': { 'eCat': "User", 'eAct': "Registration", 'eLab': "-", 'eVal': 1 },
                'eventCallback': function () {
                    dataLayer.push({ 'gaEventData': undefined });
                }
            });
        });


    },
    login: function (type, data) {
        window.didomiOnReady = window.didomiOnReady || [];
        window.didomiOnReady.push(function (Didomi) {
            dataLayer.push({ event: type, ...data });
        });
    },
    logout: function (type) {

        window.didomiOnReady = window.didomiOnReady || [];
        window.didomiOnReady.push(function (Didomi) {
            dataLayer.push({ event: type });
        });
    },
    renewPassword: function (type, data) {

        window.didomiOnReady = window.didomiOnReady || [];
        window.didomiOnReady.push(function (Didomi) {
            dataLayer.push({ event: type, ...data });
        });
    },
    watchLater: function (action, dmpAction, id) {
        gjdmp.tr(dmpAction, {
            id: analyticsModel.id,
            name: analyticsModel.videoName,
            value: "entity_" + id,
            type: "entity",
            category: "video",
            url: window.location.href
        });

        bsk('event', dmpAction, {
            id: analyticsModel.id,
            name: analyticsModel.videoName,
            value: "entity_" + id,
            type: "entity",
            category: ["video"]
        });
        window.didomiOnReady = window.didomiOnReady || [];
        window.didomiOnReady.push(function (Didomi) {
            dataLayer.push({
                'event': "gaEvent",
                'gaEventData': { 'eCat': "Video", 'eAct': action, 'eLab': "-", 'eVal': 1 },
                'eventCallback': function () {
                    dataLayer.push({ 'gaEventData': undefined });
                }
            });
        });


    },
    videoView: function () {
        gjdmp.tr("ViewContent", dmpLayer);
        bsk('event', 'viewcontent', biskoLayer);
        if (window.gemiusEvents)
            window.gemiusEvents.playerEvent('play');
    },
    relatedClick: function (id, videoName, position) {
        gjdmp.tr('relatedclick', {
            id: id,
            name: videoName,
            value: position,
            type: 'entity',
            category: 'video',
        });

        bsk('event', 'relatedclick', {
            id: id,
            name: videoName,
            value: position,
            type: 'entity',
            category: ['video']
        });
    },
    playlistClick: function (id, videoName, position) {
        gjdmp.tr('playlistClick', {
            id: id,
            name: videoName,
            value: position,
            type: 'entity',
            category: 'video',
        });

        bsk('event', 'playlistClick', {
            id: id,
            name: videoName,
            value: position,
            type: 'entity',
            category: ['video']
        });
    },
    playTime: {
        triggers: [],
        triggered: function (time) {
            return this.triggers.length > 0 && this.triggers.find(function (trigger) {
                if (trigger.time === time) {
                    return trigger.triggered;
                }
                return false;
            });
        },
        push: function (time) {
            if (!this.triggered(time)) {
                analyticsEvents.playTime.triggers.push({
                    time: time,
                    triggered: true
                });
                gjdmp.tr(time, { id: analyticsModel.id, name: analyticsModel.videoName, type: analyticsModel.pageType, url: window.location.href });
                bsk('event', time, { id: analyticsModel.id, name: analyticsModel.videoName, type: analyticsModel.pageType });
                window.didomiOnReady = window.didomiOnReady || [];
                window.didomiOnReady.push(function (Didomi) {
                    dataLayer.push({
                        'event': "gaEvent",
                        'gaEventData': { 'eCat': "Video", 'eAct': "Playtime", 'eLab': time, 'eVal': 1 },
                        'eventCallback': function () {
                            dataLayer.push({ 'gaEventData': undefined });
                        }
                    });
                });


            }
        }
    },
    getProduct: function (id) {
        if (window.productsModel === null) return null;
        let model = window.productsModel.find(function (model) {
            if (model.Id && model.Id == id) {
                return model;
            }
        })
        if (model != null)
            return objectKeysToLowerCase(model);
        return null;
    },
    productImpression: {
        ids: [],
        push: function (id, type) {
            var product;
            var listType = analyticsEvents.productImpression.getType(type);
            var impressions = [];
            var url = "";
            var impression = {};
            if (typeof id === "object") {
                var productsSkipped = 0;
                for (var i = 0; i < id.length; i++) {
                    product = analyticsEvents.getProduct(id[i]);

                    if ((product === null || product !== 'undefined') || (typeof (product.Id) !== 'undefined' && product.Id && this.ids.includes(product.Id))) {
                        productsSkipped++;
                        continue;
                    }
                    this.ids.push(product.id);
                    url = new URL(product.link ? product.link : product.buttonRedirectUrl);
                    product.position = this.ids.length;
                    impression = {
                        name: product.title,
                        id: product.id,
                        brand: url.hostname,
                        category: analyticsModel.contentTopic,
                        list: listType,
                        dimension5: url.hostname,
                        position: product.position
                    };
                    if (product.Price !== undefined) {
                        if (typeof product.price === "string") {
                            impression.price = product.price.replace(/\D+/g, "");
                        } else {
                            impression.price = product.price;
                        }
                    }
                    impressions.push(impression);
                    product.listType = listType;
                }
                if (productsSkipped !== id.length) {
                    window.didomiOnReady = window.didomiOnReady || [];
                    window.didomiOnReady.push(function (Didomi) {
                        dataLayer.push({
                            'event': "gaEeImpressions",
                            'ecommerce': {
                                'impressions': impressions
                            }
                        });
                    });
                }
            } else if (typeof id === "string" || typeof id === "number") {
                product = analyticsEvents.getProduct(id);
                if (product === null || product === undefined || this.ids.includes(id)) return;
                this.ids.push(product.id);
                url = new URL(product.link ? product.link : product.buttonRedirectUrl);
                product.position = this.ids.length;
                impression = {
                    name: product.title,
                    id: product.id,
                    brand: url.hostname,
                    category: analyticsModel.contentTopic,
                    list: listType,
                    dimension5: url.hostname,
                    position: product.position
                };
                if (product.price !== undefined) {
                    impression.price = product.price.replace(/\D+/g, "");
                }
                impressions.push(impression);
                product.listType = listType;
                window.didomiOnReady = window.didomiOnReady || [];
                window.didomiOnReady.push(function (Didomi) {
                    dataLayer.push({
                        'event': "gaEeImpressions",
                        'ecommerce': {
                            'impressions': impressions
                        }
                    });
                });


            }
        },
        getType: function (type) {
            switch (type) {
                case 1:
                    return "In video - fixed";
                case 2:
                    return "Under video - button";
                case 3:
                    return "Under video - about video link";
                default:
                    return "";
            }
        }
    },
    isProductClicked: true,
    productClick: function (id) {
        var product = analyticsEvents.getProduct(id);

        if (product === null || product === undefined) return;

        vpPlayer().pause();
        adHoverPause = false;

        var url = new URL(product.link ? product.link : product.buttonRedirectUrl);
        url.insertParameter("utm_source", analyticsModel.platformDomain);
        url.insertParameter("utm_medium", "video");
        url.insertParameter("utm_campaign", product.ListType);
        url.insertParameter("utm_content", analyticsModel.showName + " - " + analyticsModel.videoName);
        url.insertParameter("utm_term", product.Id);
        var mallProduct = {
            name: product.title,
            id: product.id,
            brand: url.hostname,
            category: analyticsModel.contentTopic,
            list: product.listType,
            dimension5: url.hostname,
            position: analyticsEvents.productImpression.ids.length
        };
        if (product.price !== undefined) {
            mallProduct.price = product.price.replace(/\D+/g, "");
        }
        window.didomiOnReady = window.didomiOnReady || [];
        window.didomiOnReady.push(function (Didomi) {
            dataLayer.push({
                'event': "gaEeClick",
                'ecommerce': {
                    'click': {
                        'actionField': {
                            'list': product.listType
                        },
                        'products': [mallProduct]
                    }
                }
            });
        });


        var win = window.open(url, "_blank");
        win.focus();
    },
    promoView: {
        ids: [],
        push: function (id, dimension) {
            var promoModel;
            if (typeof id === "object") {
                var productsSkipped = 0;
                var promotions = [];
                for (var i = 0; i < id.length; i++) {
                    promoModel = analyticsEvents.getProduct(id[i]);
                    if (promoModel === null || promoModel === undefined || this.ids.includes(promoModel.Id)) {
                        productsSkipped++;
                        continue;
                    }
                    this.ids.push(promoModel.id);
                    promoModel.name = analyticsEvents.promoView.getName(promoModel, dimension);
                    if (!promoModel.position)
                        promoModel.position = this.ids.length;
                    promotions.push({
                        ...promoModel,
                        'id': promoModel.id,
                        'name': promoModel.name,
                        'creative': promoModel.title,
                        'position': promoModel.position,
                        'dimension8': dimension,
                    });
                }
                if (productsSkipped !== id.length) {
                    window.didomiOnReady = window.didomiOnReady || [];
                    window.didomiOnReady.push(function (Didomi) {
                        dataLayer.push({
                            'event': "gaEePromoView",
                            'ecommerce': {
                                'promoView': {
                                    'promotions': promotions
                                }
                            }
                        });
                    });


                }
            } else if (typeof id === "string" || typeof id === "number") {
                promoModel = analyticsEvents.getProduct(id);

                if (promoModel === null || promoModel === undefined || this.ids.includes(promoModel.id)) return;
                this.ids.push(promoModel.id);
                promoModel.position = this.ids.length;
                if (promoModel.name === undefined)
                    promoModel.name = analyticsEvents.promoView.getName(promoModel, dimension);

                let self = this;
                window.didomiOnReady = window.didomiOnReady || [];
                window.didomiOnReady.push(function (Didomi) {
                    dataLayer.push({
                        'event': "gaEePromoView",
                        'ecommerce': {
                            'promoView': {
                                'promotions': [{
                                    ...promoModel,
                                    'id': promoModel.id,
                                    'name': promoModel.name,
                                    'creative': promoModel.title,
                                    'position': self.ids.length,
                                    'dimension8': dimension,
                                }]
                            }
                        }
                    });
                });



            }

        },
        getName: function (promoModel, dimension) {
            switch (dimension) {
                case "Ad - video":
                    return promoModel.name + ", SkipTime: 5"; //promoModel.SkipTime
                case "Show":
                    return promoModel.name;
                case "Video":
                    return promoModel.name;
                default:
                    return promoModel.name;
            }
        }
    },
    promoClick: {
        ids: [],
        push: function (id, dimension) {
            var promoModel;
            if (typeof id === "object") {
                var productsSkipped = 0;
                var promotions = [];
                for (var i = 0; i < id.length; i++) {
                    promoModel = analyticsEvents.getProduct(id[i]);
                    if (promoModel === null || promoModel === undefined) {
                        productsSkipped++;
                        continue;
                    }
                    this.ids.push(promoModel.id);
                    if (!promoModel.position)
                        promoModel.position = this.ids.length;
                    promoModel.name = analyticsEvents.promoView.getName(promoModel, dimension);
                    promotions.push({
                        ...promoModel,
                        'id': promoModel.id,
                        'name': promoModel.name,
                        'creative': promoModel.title,
                        'position': this.ids.length,
                        'dimension8': dimension,
                    });
                }
                if (productsSkipped !== id.length) {
                    window.didomiOnReady = window.didomiOnReady || [];
                    window.didomiOnReady.push(function (Didomi) {
                        dataLayer.push({
                            'event': "gaEePromoClick",
                            'ecommerce': {
                                'promoClick': {
                                    'promotions': promotions
                                }
                            }
                        });
                    });


                }
            } else if (typeof id === "string" || typeof id === "number") {
                promoModel = analyticsEvents.getProduct(id);
                if (promoModel === null || promoModel === undefined) return;
                if (!promoModel.position)
                    promoModel.position = this.ids.length;
                if (promoModel.name === undefined)
                    promoModel.name = analyticsEvents.promoView.getName(promoModel, dimension);
                window.didomiOnReady = window.didomiOnReady || [];
                window.didomiOnReady.push(function (Didomi) {
                    dataLayer.push({
                        'event': "gaEePromoClick",
                        'adClickType': undefined,
                        'ecommerce': {
                            'promoClick': {
                                'promotions': [{
                                    ...promoModel,
                                    'id': promoModel.id,
                                    'name': promoModel.name,
                                    'creative': promoModel.title,
                                    'position': promoModel.position,
                                    'dimension8': dimension,
                                }]
                            }
                        }
                    });
                });
            }
        },
        getType: function (type) {
            switch (type) {
                case 1:
                    return "ad";
                case 2:
                    return "skip";
                default:
                    return undefined;
            }
        }
    },
    premiumLock: function (eventType) {
        window.didomiOnReady = window.didomiOnReady || [];
        window.didomiOnReady.push(function (Didomi) {
            dataLayer.push({
                'event': 'gaEvent',
                'gaEventData': {
                    'eCat': 'Video',
                    'eAct': 'Premium lock',
                    'eLab': eventType, // view or click
                    'eVal': 1
                },
                'eventCallback': function () {
                    dataLayer.push({ 'gaEventData': undefined });
                }
            });
        });


    },
    videoLimit: function (limitType) {
        window.didomiOnReady = window.didomiOnReady || [];
        window.didomiOnReady.push(function (Didomi) {
            dataLayer.push({
                'event': 'gaEvent',
                'gaEventData': {
                    'eCat': 'Video',
                    'eAct': 'Limit',
                    'eLab': limitType,
                    'eVal': 1
                },
                'eventCallback': function () {
                    dataLayer.push({ 'gaEventData': undefined });
                }
            });
        });


    },
    videoSubscription: function (subscriptionData) {
        window.didomiOnReady = window.didomiOnReady || [];
        window.didomiOnReady.push(function (Didomi) {
            dataLayer.push({
                event: subscriptionData.event,
                products:
                {
                    name: subscriptionData.type,
                    category: subscriptionData.category,
                    brand: subscriptionData.brand,
                    value: subscriptionData.price,
                    tax: subscriptionData.productTax,
                    quantity: 1,
                },
            });
        });
    },
    ctaClick: function (textofCta) {
        window.didomiOnReady = window.didomiOnReady || [];
        window.didomiOnReady.push(function (Didomi) {
            dataLayer.push({
                'event': 'gaEvent',
                'gaEventData': {
                    'eCat': 'CTA',
                    'eAct': 'Click',
                    'eLab': textofCta,
                    'eVal': 1
                },
                'eventCallback': function () {
                    dataLayer.push({ 'gaEventData': undefined });
                }
            });
        });


    },
    getCookie: function (cookieName) {
        var value = `; ${document.cookie}`;
        var parts = value.split(`; ${cookieName}=`);
        if (parts.length === 2) return parts.pop().split(';').shift();
    },
    getGaTimeStamp: function () {
        return analyticsEvents.getCookie("_ga").substring(2).replace(/\./g, "") + Date.now()
    },
    playerEvent: function (event, playerConfig, additionalData) {
        if (event === "player_start") {
            vpPlayerEvents.playerConfig = playerConfig;
        }

        if (vpPlayerEvents.playerConfig == null)
            return;

        let playerState = vpPlayer().getState();
        let object = {
            type: "video",
            variant: window.isEmbed ? "embed" : "standard",
            interaction: "system",
            content: {
                id: analyticsModel.id,
                type: analyticsModel.pageType,
                title: analyticsModel.videoName,
                category: analyticsModel.contentTopic,
                published: analyticsModel.videoPublished,
                show: analyticsModel.showName,
                premium: analyticsModel.videoLock,
                priceTvod: analyticsModel.videoPriceTvod,
                priceSvod: analyticsModel.videoPriceSvod,
                currency: analyticsModel.videoCurrency,
                premiumPackage: analyticsModel.videoPremium,
                tag: analyticsModel.videoTag
            },
            ad: {
                skipAfter: vpPlayerEvents.playerConfig.video.ads ? vpPlayerEvents.playerConfig.video.ads.skipAd.skipFrom : 0,
                length: vpPlayerEvents.playerConfig.video.ads.adBreaks ? vpPlayerEvents.playerConfig.video.ads.adBreaks.count : 0,
                type: "video",
            },
            settings: {
                mute: vpPlayer().video.muted,
                autoplay: vpPlayerEvents.playerConfig.config.autoplay,
                volume: vpPlayer().video.volume,
                fullscreen: playerState.isFullscreen,
            },
            time: {
                length: durationToSeconds(vpspc.object.Duration),
                currentTimeStamp: Date.now(),
                playTime: vpPlayerEvents.playTime,
                position: Math.floor(vpPlayer().video.currentTime)
            },

        }
        if (vpPlayerEvents.playerConfig.video.ad) {
            object["ad"] = {
                skipAfter: vpPlayerEvents.playerConfig.video.ad ? vpPlayerEvents.playerConfig.video.ad.skipTime : 0,
                length: vpPlayerEvents.playerConfig.video.ad.preroll ? vpPlayerEvents.playerConfig.video.ad.preroll.count : 0,
                type: "video",
            };
        }
        if (typeof additionalData != "undefined") {
            Object.assign(object, additionalData);
        }
        if (vpPlayer().hls) {
            try {
                object.settings.resolution = vpPlayer.player.hls.levels[vpPlayer().hls.loadLevel].height
            } catch (e) { }
        }
        if (["player_resume", "player_pauser", "player_progress"].includes(event)) {
            object = {
                time: object.time,
                content: {
                    id: analyticsModel.id
                }
            };
        }
        window.didomiOnReady = window.didomiOnReady || [];
        window.didomiOnReady.push(function (Didomi) {
            window.dataLayer.push({
                event: event,
                player: object
            })
        })

    },
    playerSettingsChange: function (settingsChangeEvent, settings) {
        console.log("change")
        let object = {
            event: settingsChangeEvent,
            settings: settings,
            time: {
                length: durationToSeconds(vpspc.object.Duration),
                currentTimeStamp: Date.now(),
                playTime: vpPlayerEvents.playTime
            }
        }
        window.didomiOnReady = window.didomiOnReady || [];
        window.didomiOnReady.push(function (Didomi) {
            window.dataLayer.push(object);
        })
    },
    adEvent: function (event, ad) {
        try {
            window.didomiOnReady = window.didomiOnReady || [];
            window.didomiOnReady.push(function (Didomi) {
                let object = {
                    event: event,
                    "ad": {
                        "id": ad.id,
                        "type": ad.type,
                        "position": ad.position,
                        "adserving": ad.adserving,
                        "adservingTimestamp": ad.adservingTimestamp
                    },
                    _clear: true
                };
                window.dataLayer.push(object);
            })
        } catch (e) {
            console.error(e);
        }
    },
    playerAdEvent: function (event, ad, data) {
        try {
            let object = {
                event: event,
                player: {
                    interaction: "autoplay",
                },
                ...data
            }
            object.ad = formatAd(ad)


            window.didomiOnReady = window.didomiOnReady || [];
            window.didomiOnReady.push(function (Didomi) {
                window.dataLayer.push(object);
            })
        } catch (e) {
            console.error(event)
            console.error(e)
        }

    },
    searchEvent: function (event, query, results, additionalData) {
        let obj = {
            event: event,
            search: {
                term: query,
                result: results,
                personalized: false,
            },
        }
        if (typeof additionalData != "undefined") {
            Object.assign(obj, additionalData);
        }
        window.didomiOnReady = window.didomiOnReady || [];
        window.didomiOnReady.push(function (Didomi) {
            dataLayer.push(obj);
        })
    },
    clickEvent: function (event, data) {
        window.didomiOnReady = window.didomiOnReady || [];
        window.didomiOnReady.push(function (Didomi) {
            dataLayer.push({
                event: event,
                ...data,
            })
        })
    }
}
analyticsEvents.init();

function objectKeysToLowerCase(input) {
    if (typeof input !== 'object') return input;
    if (Array.isArray(input)) return input.map(objectKeysToLowerCase);
    return Object.keys(input).reduce(function (newObj, key) {
        let val = input[key];
        let newVal = (typeof val === 'object') && val !== null ? objectKeysToLowerCase(val) : val;
        newObj[key.toLowerCase()] = newVal;
        return newObj;
    }, {});
};


function formatAd(ad) {
    return {
        id: ad.getAdId(),
        position: ad.getAdPodInfo().getAdPosition(),
        skipAfter: vpPlayer.player.videoObject.ad.skipTime,
        type: ad.getContentType()
    }
}


function durationToSeconds(duration) {
    if (!duration)
        return 0;
    var parts = duration.split(":")
    if (parts.length > 0) {
        let minutes = parseInt(parts[0])
        let seconds = parseInt(parts[1])
        return minutes * 60 + seconds;
    }
    return 0;
};

var gemiusEvents = {
    player: null,
    videoId: 0,
    adId: 0,
    isLive: false,
    hasError: false,

    init: function (videoId) {
        try {
            if (!window.GemiusPlayer)
                return;
            var videoElement = document.getElementById("player").querySelector("video");
            this.player = new window.GemiusPlayer('player',
                '0ss1XacLuWrrxBaTbp0L5.U5DtadnedcFu6mDanzt.T.a7',
                {
                    resolution: videoElement.videoWidth + "x" + videoElement.videoHeight
                });
            this.videoId = videoId;
        } catch (e) {
            this.hasError = true;
            console.log(e);
        }
    },
    program: function (videoName, videoDuration, showName, isLive) {
        this.isLive = isLive;
        if (this.hasError || !window.GemiusPlayer || !player)
            return;
        var programName = videoName.replace(/[^a-z0-9]/gi, '');
        var config = {
            programName: programName.length > 64 ? programName.substr(0, 64) : programName,
            programDuration: isLive ? -1 : videoDuration,
            programType: 'video',
            transmissionType: isLive ? 2 : 1,
            series: showName.length > 64 ? showName.substr(0, 64) : showName
        };
        if (isLive) {
            config.transmissionStartTime = Date.now().toString();
            config.transmissionChannel = showName.length > 64 ? showName.substr(0, 64) : showName;
        }
        this.player.newProgram(this.videoId, config);
        
        console.info("Gemius New program: " + this.videoId);
    },
    playerEvent: function (eventType) {
        if (this.hasError || !window.GemiusPlayer || !player)
            return;
        var currentTime = this.isLive ? (Math.floor(Date.now() - (vpPlayer().video.duration * 1000))) : Math.floor(vpPlayer().video.currentTime);
        var currentVolume = vpPlayer().video.volume * 100;
        this.player.programEvent(this.videoId,
            currentTime,
            eventType,
            {
                volume: currentVolume
            });
        console.info("Gemius PlayerEvent: " + eventType + " " + currentTime);
    },
    newAd: function (adId) {
        if (this.hasError || !window.GemiusPlayer || !player)
            return;
        this.adId = adId;
        this.player.newAd(adId);
        console.info("Gemius New ad: " + adId);
    },
    adEvent: function (eventType, adCount) {
        if (this.hasError || !window.GemiusPlayer || !player)
            return;
        var currentTime = parseInt(vpPlayer().video.currentTime);
        var currentVolume = vpPlayer().video.volume * 100;
        this.player.adEvent(this.videoId, this.adId, currentTime, eventType,
            {
                breakSize: adCount,
                volume: currentVolume
            });
        console.info("Gemius AdEvent: " + eventType);

    }
}
;
