/* 
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */


function sendAnalyticsEvent (sendData) {
    if (typeof (ga) == 'function') {
        ga("Transmatico.send", sendData);
    }

    if (typeof (sendDataMatomo) == 'function') {
        sendDataMatomo(sendData)
    }
}

function TRMgetSrcOfBGImage(selector) {
    var result = '';
    selector = jQueryTRM(selector)
    if (selector.length) {
        var backgroundImage = selector.css('background-image')
        if (backgroundImage && backgroundImage != "none") {
            if (backgroundImage.substr(4, 1) == '"' || backgroundImage.substr(4, 1) == "'") {
                result = backgroundImage.substr(5, backgroundImage.length - 7)
            } else {
                result = backgroundImage.substr(4, backgroundImage.length - 5)
            }
        }
    }
    return result
}

var eventReg = []

function TRMEvent() {
    for (var i = 0; i < eventReg.length; i++) {
        var reg = eventReg[i]
        var find = true
        for (var j = 0; j < arguments.length; j++) {
            if (reg.p[j] != null && arguments[j] != reg.p[j]) {
                find = false
                break
            }
        }
        if (find) {
            if (reg.dis) {
                eventReg.splice(i, 1)
            }
            reg.f.apply(reg.this, arguments)
        }
    }
}

function TRMEventReg(params, callback, disposible) {
    eventReg.push({p: params, f: callback, dis: disposible})
}

function TRMgetCookie(name) {
    var value = "; " + document.cookie;
    var parts = value.split("; " + name + "=");
    if (parts.length == 2)
        return parts.pop().split(";").shift();
}
function TRMcreateCookie(name, value, days) {
    if (days) {
        var date = new Date();
        date.setTime(date.getTime() + (days * 24 * 60 * 60 * 1000));
        var expires = "; expires=" + date.toGMTString();
    } else
        var expires = "";
    document.cookie = name + "=" + value + expires + "; path=/";
}

var TRMisMobile = function () {
    var check = false;
    (function (a) {
        if (/(android|bb\d+|meego).+mobile|avantgo|bada\/|blackberry|blazer|compal|elaine|fennec|hiptop|iemobile|ip(hone|od)|iris|kindle|lge |maemo|midp|mmp|mobile.+firefox|netfront|opera m(ob|in)i|palm( os)?|phone|p(ixi|re)\/|plucker|pocket|psp|series(4|6)0|symbian|treo|up\.(browser|link)|vodafone|wap|windows ce|xda|xiino/i.test(a) || /1207|6310|6590|3gso|4thp|50[1-6]i|770s|802s|a wa|abac|ac(er|oo|s\-)|ai(ko|rn)|al(av|ca|co)|amoi|an(ex|ny|yw)|aptu|ar(ch|go)|as(te|us)|attw|au(di|\-m|r |s )|avan|be(ck|ll|nq)|bi(lb|rd)|bl(ac|az)|br(e|v)w|bumb|bw\-(n|u)|c55\/|capi|ccwa|cdm\-|cell|chtm|cldc|cmd\-|co(mp|nd)|craw|da(it|ll|ng)|dbte|dc\-s|devi|dica|dmob|do(c|p)o|ds(12|\-d)|el(49|ai)|em(l2|ul)|er(ic|k0)|esl8|ez([4-7]0|os|wa|ze)|fetc|fly(\-|_)|g1 u|g560|gene|gf\-5|g\-mo|go(\.w|od)|gr(ad|un)|haie|hcit|hd\-(m|p|t)|hei\-|hi(pt|ta)|hp( i|ip)|hs\-c|ht(c(\-| |_|a|g|p|s|t)|tp)|hu(aw|tc)|i\-(20|go|ma)|i230|iac( |\-|\/)|ibro|idea|ig01|ikom|im1k|inno|ipaq|iris|ja(t|v)a|jbro|jemu|jigs|kddi|keji|kgt( |\/)|klon|kpt |kwc\-|kyo(c|k)|le(no|xi)|lg( g|\/(k|l|u)|50|54|\-[a-w])|libw|lynx|m1\-w|m3ga|m50\/|ma(te|ui|xo)|mc(01|21|ca)|m\-cr|me(rc|ri)|mi(o8|oa|ts)|mmef|mo(01|02|bi|de|do|t(\-| |o|v)|zz)|mt(50|p1|v )|mwbp|mywa|n10[0-2]|n20[2-3]|n30(0|2)|n50(0|2|5)|n7(0(0|1)|10)|ne((c|m)\-|on|tf|wf|wg|wt)|nok(6|i)|nzph|o2im|op(ti|wv)|oran|owg1|p800|pan(a|d|t)|pdxg|pg(13|\-([1-8]|c))|phil|pire|pl(ay|uc)|pn\-2|po(ck|rt|se)|prox|psio|pt\-g|qa\-a|qc(07|12|21|32|60|\-[2-7]|i\-)|qtek|r380|r600|raks|rim9|ro(ve|zo)|s55\/|sa(ge|ma|mm|ms|ny|va)|sc(01|h\-|oo|p\-)|sdk\/|se(c(\-|0|1)|47|mc|nd|ri)|sgh\-|shar|sie(\-|m)|sk\-0|sl(45|id)|sm(al|ar|b3|it|t5)|so(ft|ny)|sp(01|h\-|v\-|v )|sy(01|mb)|t2(18|50)|t6(00|10|18)|ta(gt|lk)|tcl\-|tdg\-|tel(i|m)|tim\-|t\-mo|to(pl|sh)|ts(70|m\-|m3|m5)|tx\-9|up(\.b|g1|si)|utst|v400|v750|veri|vi(rg|te)|vk(40|5[0-3]|\-v)|vm40|voda|vulc|vx(52|53|60|61|70|80|81|83|85|98)|w3c(\-| )|webc|whit|wi(g |nc|nw)|wmlb|wonu|x700|yas\-|your|zeto|zte\-/i.test(a.substr(0, 4)))
            check = true;
    })(navigator.userAgent || navigator.vendor || window.opera);
    return check;
}
var TRMSearch = (function () {
    var params = {}
    var query = window.location.search.substring(1);
    if (query) {
        var vars = query.split('&');
        for (var i = 0; i < vars.length; i++) {
            if (vars[i]) {
                var pair = vars[i].split('=');
                if (pair[0]) {
                    params[decodeURIComponent(pair[0])] = decodeURIComponent(pair[1]);
                }
            }
        }
    }
    return {
        get: function (variable) {
            if (variable === undefined) {
                return params
            } else {
                return params[variable]
            }
        },
        set: function (variable, value) {
            if (variable !== undefined) {
                if (value === undefined) {
                    delete params[variable];
                } else {
                    params[variable] = value
                }
            }
            var str = '';
            for (variable in  params) {
                str += '&' + encodeURIComponent(variable) + '=' + encodeURIComponent(params[variable])
            }
            window.location.search = (str ? '?' : '') + str.substr(1)
        }
    }
})()


var TRMHtmlEncode = function (value) {
    var elm = document.createElement("div")
    elm.textContent = value
    return elm.innerHTML;
}

var TRMHtmlDecode = function (value) {
    var elm = document.createElement("div")
    elm.innerHTML = value
    return elm.textContent;
}

var TRMLoadGoogleAnalyticsTracking = function () {
    /**
     * If google analytics tracking script is not loaded, don't attach any listeners
     * and abbort bacause tracking for this newspaper is not enabled.
     */

    if (typeof sendAnalyticsEvent != 'function') {
        return;
    }


    /**
     * Send tracking event to google analytics that the overlay has been opened
     */
    TRMTrackAdEvent('Overlay_Expand');

    /**
     * Attach google tracking events to the buttons
     */
    var elm = document.querySelectorAll('#lightboxAd .menubuttonContainer.phone a')
    for (var i in elm) {
        if (elm[i].addEventListener !== undefined) {
            elm[i].addEventListener('click', function () {
                TRMTrackAdEvent('button_Phone');
            })
        }
    }

    /* 
     * link to website
     */
    /**
     * If the link open in a new window there is no need to make a javascript redirect.
     */
    var elm = document.querySelectorAll('#lightboxAd .menubuttonContainer.site a[target="_blank"]')
    for (var i in elm) {
        if (elm[i].addEventListener !== undefined) {
            elm[i].addEventListener('click', function () {
                TRMTrackAdEvent('button_URL');
            })
        }
    }

    /**
     * We nned to redirect the user after the tracking event has been sent,
     * Othrwise the broser will stop the execution before the tracking event is sent.
     */
    var elm = document.querySelectorAll('#lightboxAd .menubuttonContainer.site a:not([target])')
    for (var i in elm) {
        if (elm[i].addEventListener !== undefined) {
            elm[i].addEventListener('click', function (evt) {
                evt.preventDefault();
                TRMTrackAdEvent('button_URL');
                window.location = this.getAttribute('href');
            })
        }
    }
    /* 
     * link to map
     */
    var elm = document.querySelectorAll('#lightboxAd .menubuttonContainer.map a')
    for (var i in elm) {
        if (elm[i].addEventListener !== undefined) {
            elm[i].addEventListener('click', function (evt) {

                var target = this.getAttribute("target")

                if (target != '_blank') {
                    evt.preventDefault();
                }
                TRMTrackAdEvent('button_Maps');
                if (target != '_blank') {
                    window.location = this.getAttribute('href');
                }
            })
        }
    }

    /*
     * email
     */
    var elm = document.querySelectorAll('#lightboxAd .menubuttonContainer.email a')
    for (var i in elm) {
        if (elm[i].addEventListener !== undefined) {
            elm[i].addEventListener('click', function () {
                TRMTrackAdEvent('button_Email');
            })
        }
    }

    /**
     * Attach google tracking events to the ad image shown in the overlay and link in below the buttons.
     * If the link open in a new window there is no need to make a javascript redirect.
     */
    var elm = document.querySelectorAll('#lightBoxcontent a[target="_blank"], #infCont .textInfo a.wbsite[target="_blank"]')
    for (var i in elm) {
        if (elm[i].addEventListener !== undefined) {
            elm[i].addEventListener('click', function () {
                TRMTrackAdEvent('link_URL');
            })
        }
    }
    /**
     * Attach google tracking events to the ad image shown in the overlay and link in below the buttons.
     * If the link opens in the same window we need to postpone the redirect in
     * order to successfully send the tracking event.
     */
    var elm = document.querySelectorAll('#lightBoxcontent a:not([target]), #infCont .textInfo a.wbsite:not([target])')
    for (var i in elm) {
        if (elm[i].addEventListener !== undefined) {
            elm[i].addEventListener('click', function (evt) {
                evt.preventDefault();
                TRMTrackAdEvent('link_URL');
                window.location = this.getAttribute('href');
            })
        }
    }

    var elm = document.querySelectorAll('#infCont .textInfo a:not(.wbsite)')
    for (var i in elm) {
        if (elm[i].addEventListener !== undefined) {
            elm[i].addEventListener('click', function () {
                TRMTrackAdEvent('link_Email');
            })
        }
    }


}

/**
 * Send information about a tacking event to google analytics.
 * @param String eventAction the string alias to the event type which occured. The alias will be used for the eventAction paramters passed to google. 
 * Possible values:
 * 1. `Overlay_Expand` - when an ad is clicked
 * 2. `button_URL` - when the buttons linked to the ad url is clicked ( if present )
 * 3. `link_URL` - when the images linked to the ad url is clicked ( if present )
 * 4. `button_Phone` - the button with tel: link is clicked ( if present )
 * 5. `button_Email` - when the button with mailto: link is clicked
 * 5. `link_Email` - when the link with mailto: url below the buttons is clicked
 * 6. `button_Maps` - when the button linking to a google map page is clicked
 * @returns {undefined}
 */
var TRMTrackAdEvent = function (eventAction) {

    if (typeof (sendAnalyticsEvent) == 'undefined') {
        return;
    }

    /**
     * The default values common for all Events that will be sent to google
     */
    var sendData = {
        hitType: 'event',
        eventCategory: 'Default category',
        eventAction: eventAction,
        eventLabel: 'Default label'
    };

    switch (eventAction) {
        case 'Overlay_Expand':
            /*
             * FOR TASK 2205
             * sending event for advertiser, as event with action "Overlay_expand", category and label = website with title as fallback in case if site does not exists
             */
            var elm = document.querySelector('a.wbsite')
            if (!elm) {
                elm = document.querySelector('.textInfo h4')
            }
            if (elm) {
                var title = document.querySelector('.textInfo h4') != null ? document.querySelector('.textInfo h4').innerHTML : '';
                var website = document.querySelector('a.website') != null ? document.querySelector('a.website').innerHTML : '';
                if (title.length && website.length) {
                    title += ' - ';
                }

                var current_src = document.querySelector('#TMAdView #lightBoxcontent img');
                var all_ads = document.querySelectorAll('.TRM-RPA-image-container [rel="ad"]');
                var find_ad_id = "";
                if (all_ads && current_src) {
                    for (var i = 0; all_ads.length > i; i++) {
                        if (current_src.src == all_ads[i].src && all_ads[i].id) {
                            find_ad_id = all_ads[i].id;
                            break;
                        }

                    } 
                }
                console.log(find_ad_id);
                sendData.eventLabel = 'Overlay view (' + decodeURI(title) + decodeURI(website) + ') ' + find_ad_id;
                sendData.eventCategory = 'Overlay'; //website; 
                sendAnalyticsEvent(sendData);
            }

            sendData.eventLabel = 'Overlay view';
            sendData.eventCategory = 'Overlay';
            break;
        case 'button_URL':
        case 'link_URL':
        case 'button_Phone':
        case 'button_Email':
        case 'button_Maps':
        case 'link_Email':
            /*
             * FOR TASK 2205
             * sending event for advertiser, as event with action "Overlay_expand", category and label = website with title as fallback in case if site does not exists
             */
            var elm = document.querySelector('a.wbsite')
            if (!elm) {
                elm = document.querySelector('.textInfo h4')
            }
            if (elm) {
                var title = document.querySelector('.textInfo h4') != null ? document.querySelector('.textInfo h4').innerHTML : '';
                var website = document.querySelector('a.website') != null ? document.querySelector('a.website').innerHTML : '';
                if (title.length && website.length) {
                    title += ' - ';
                }
                sendData.eventLabel = 'Overlay click (' + decodeURI(title) + decodeURI(website) + ')';
                sendData.eventCategory = 'Overlay'; //website; 
                sendAnalyticsEvent(sendData);
            }

            sendData.eventLabel = 'Overlay click';
            sendData.eventCategory = 'Overlay_Click';
            break;
        case 'Banderole_View' :
        case 'Banderole_Close' :
            var prefix = eventAction == 'Banderole_View' ? 'Banderole View' : 'Banderole Close';
            var banderoleContentContainer = document.querySelector('.trm-banderole #html_structura_area_v2')
            sendData.eventLabel = prefix + '(' + (banderoleContentContainer ? banderoleContentContainer.getAttribute('data-trm-project-name') : '') + ')'
            sendData.eventCategory = prefix;
            sendAnalyticsEvent(sendData)
            break;

    }

    sendAnalyticsEvent(sendData);

};(function(data){/* 
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 * Append code to enable query selector and JSON for IE 7. NOTE use only single selector,
 * because IE7 doesn't support multiple selectors separated by `,`
 * FOR TASK #1813
 */
var domload = {
    readyStack: new Array(),
    __executeReadyStack: function () {

        var loopStack = false;

        do {

            var func = domload.readyStack.pop();

            if (typeof func == 'function') {

                loopStack = true;
                func.call();

            } else {
                loopStack = false;
            }

        } while (loopStack);

    },
    ready: function (func) {

        this.readyStack.push(func);

        if (document.readyState === "complete") {

            this.__executeReadyStack();

        }

        if (document.addEventListener) {

            document.addEventListener("DOMContentLoaded", this.__executeReadyStack);
            window.addEventListener("load", this.__executeReadyStack);

        } else if (document.attachEvent) {

            document.attachEvent("onreadystatechange", this.__executeReadyStack);
            window.attachEvent("onload", this.__executeReadyStack);
        }

    }
};

/**
 * Append code to enable query selector and JSON for IE 7. NOTE use only single selector,
 * because IE7 doesn't support multiple selectors separated by `,`
 */

if (navigator.appVersion.indexOf('MSIE 7') > -1) {

    (function (d, s) {
        d = document, s = d.createStyleSheet();
        d.querySelectorAll = function (r, c, i, j, a) {
            a = d.all, c = [], r = r.replace(/\[for\b/gi, '[htmlFor').split(',');
            for (i = r.length; i--; ) {
                s.addRule(r[i], 'k:v');
                for (j = a.length; j--; )
                    a[j].currentStyle.k && c.push(a[j]);
                s.removeRule(0)
            }
            return c
        }
    })();
    (function () {
        function N(p, r) {
            function q(a) {
                if (q[a] !== w)
                    return q[a];
                var c;
                if ("bug-string-char-index" == a)
                    c = "a" != "a"[0];
                else if ("json" == a)
                    c = q("json-stringify") && q("json-parse");
                else {
                    var e;
                    if ("json-stringify" == a) {
                        c = r.stringify;
                        var b = "function" == typeof c && s;
                        if (b) {
                            (e = function () {
                                return 1
                            }).toJSON = e;
                            try {
                                b = "0" === c(0) && "0" === c(new t) && '""' == c(new A) && c(u) === w && c(w) === w && c() === w && "1" === c(e) && "[1]" == c([e]) && "[null]" == c([w]) && "null" == c(null) && "[null,null,null]" == c([w, u, null]) && '{"a":[1,true,false,null,"\\u0000\\b\\n\\f\\r\\t"]}' ==
                                        c({a: [e, !0, !1, null, "\x00\b\n\f\r\t"]}) && "1" === c(null, e) && "[\n 1,\n 2\n]" == c([1, 2], null, 1) && '"-271821-04-20T00:00:00.000Z"' == c(new C(-864E13)) && '"+275760-09-13T00:00:00.000Z"' == c(new C(864E13)) && '"-000001-01-01T00:00:00.000Z"' == c(new C(-621987552E5)) && '"1969-12-31T23:59:59.999Z"' == c(new C(-1))
                            } catch (f) {
                                b = !1
                            }
                        }
                        c = b
                    }
                    if ("json-parse" == a) {
                        c = r.parse;
                        if ("function" == typeof c)
                            try {
                                if (0 === c("0") && !c(!1)) {
                                    e = c('{"a":[1,true,false,null,"\\u0000\\b\\n\\f\\r\\t"]}');
                                    var n = 5 == e.a.length && 1 === e.a[0];
                                    if (n) {
                                        try {
                                            n = !c('"\t"')
                                        } catch (d) {
                                        }
                                        if (n)
                                            try {
                                                n =
                                                        1 !== c("01")
                                            } catch (g) {
                                            }
                                        if (n)
                                            try {
                                                n = 1 !== c("1.")
                                            } catch (m) {
                                            }
                                    }
                                }
                            } catch (X) {
                                n = !1
                            }
                        c = n
                    }
                }
                return q[a] = !!c
            }
            p || (p = k.Object());
            r || (r = k.Object());
            var t = p.Number || k.Number, A = p.String || k.String, H = p.Object || k.Object, C = p.Date || k.Date, G = p.SyntaxError || k.SyntaxError, K = p.TypeError || k.TypeError, L = p.Math || k.Math, I = p.JSON || k.JSON;
            "object" == typeof I && I && (r.stringify = I.stringify, r.parse = I.parse);
            var H = H.prototype, u = H.toString, v, B, w, s = new C(-0xc782b5b800cec);
            try {
                s = -109252 == s.getUTCFullYear() && 0 === s.getUTCMonth() && 1 === s.getUTCDate() &&
                        10 == s.getUTCHours() && 37 == s.getUTCMinutes() && 6 == s.getUTCSeconds() && 708 == s.getUTCMilliseconds()
            } catch (Q) {
            }
            if (!q("json")) {
                var D = q("bug-string-char-index");
                if (!s)
                    var x = L.floor, M = [0, 31, 59, 90, 120, 151, 181, 212, 243, 273, 304, 334], E = function (a, c) {
                        return M[c] + 365 * (a - 1970) + x((a - 1969 + (c = +(1 < c))) / 4) - x((a - 1901 + c) / 100) + x((a - 1601 + c) / 400)
                    };
                (v = H.hasOwnProperty) || (v = function (a) {
                    var c = {}, e;
                    (c.__proto__ = null, c.__proto__ = {toString: 1}, c).toString != u ? v = function (a) {
                        var c = this.__proto__;
                        a = a in(this.__proto__ = null, this);
                        this.__proto__ =
                                c;
                        return a
                    } : (e = c.constructor, v = function (a) {
                        var c = (this.constructor || e).prototype;
                        return a in this && !(a in c && this[a] === c[a])
                    });
                    c = null;
                    return v.call(this, a)
                });
                B = function (a, c) {
                    var e = 0, b, f, n;
                    (b = function () {
                        this.valueOf = 0
                    }).prototype.valueOf = 0;
                    f = new b;
                    for (n in f)
                        v.call(f, n) && e++;
                    b = f = null;
                    e ? B = 2 == e ? function (a, c) {
                        var e = {}, b = "[object Function]" == u.call(a), f;
                        for (f in a)
                            b && "prototype" == f || v.call(e, f) || !(e[f] = 1) || !v.call(a, f) || c(f)
                    } : function (a, c) {
                        var e = "[object Function]" == u.call(a), b, f;
                        for (b in a)
                            e && "prototype" ==
                                    b || !v.call(a, b) || (f = "constructor" === b) || c(b);
                        (f || v.call(a, b = "constructor")) && c(b)
                    } : (f = "valueOf toString toLocaleString propertyIsEnumerable isPrototypeOf hasOwnProperty constructor".split(" "), B = function (a, c) {
                        var e = "[object Function]" == u.call(a), b, h = !e && "function" != typeof a.constructor && F[typeof a.hasOwnProperty] && a.hasOwnProperty || v;
                        for (b in a)
                            e && "prototype" == b || !h.call(a, b) || c(b);
                        for (e = f.length; b = f[--e]; h.call(a, b) && c(b))
                            ;
                    });
                    return B(a, c)
                };
                if (!q("json-stringify")) {
                    var U = {92: "\\\\", 34: '\\"', 8: "\\b",
                        12: "\\f", 10: "\\n", 13: "\\r", 9: "\\t"}, y = function (a, c) {
                        return("000000" + (c || 0)).slice(-a)
                    }, R = function (a) {
                        for (var c = '"', b = 0, h = a.length, f = !D || 10 < h, n = f && (D ? a.split("") : a); b < h; b++) {
                            var d = a.charCodeAt(b);
                            switch (d) {
                                case 8:
                                case 9:
                                case 10:
                                case 12:
                                case 13:
                                case 34:
                                case 92:
                                    c += U[d];
                                    break;
                                default:
                                    if (32 > d) {
                                        c += "\\u00" + y(2, d.toString(16));
                                        break
                                    }
                                    c += f ? n[b] : a.charAt(b)
                            }
                        }
                        return c + '"'
                    }, O = function (a, c, b, h, f, n, d) {
                        var g, m, k, l, p, r, s, t, q;
                        try {
                            g = c[a]
                        } catch (z) {
                        }
                        if ("object" == typeof g && g)
                            if (m = u.call(g), "[object Date]" != m || v.call(g,
                                    "toJSON"))
                                "function" == typeof g.toJSON && ("[object Number]" != m && "[object String]" != m && "[object Array]" != m || v.call(g, "toJSON")) && (g = g.toJSON(a));
                            else if (g > -1 / 0 && g < 1 / 0) {
                                if (E) {
                                    l = x(g / 864E5);
                                    for (m = x(l / 365.2425) + 1970 - 1; E(m + 1, 0) <= l; m++)
                                        ;
                                    for (k = x((l - E(m, 0)) / 30.42); E(m, k + 1) <= l; k++)
                                        ;
                                    l = 1 + l - E(m, k);
                                    p = (g % 864E5 + 864E5) % 864E5;
                                    r = x(p / 36E5) % 24;
                                    s = x(p / 6E4) % 60;
                                    t = x(p / 1E3) % 60;
                                    p %= 1E3
                                } else
                                    m = g.getUTCFullYear(), k = g.getUTCMonth(), l = g.getUTCDate(), r = g.getUTCHours(), s = g.getUTCMinutes(), t = g.getUTCSeconds(), p = g.getUTCMilliseconds();
                                g = (0 >= m || 1E4 <= m ? (0 > m ? "-" : "+") + y(6, 0 > m ? -m : m) : y(4, m)) + "-" + y(2, k + 1) + "-" + y(2, l) + "T" + y(2, r) + ":" + y(2, s) + ":" + y(2, t) + "." + y(3, p) + "Z"
                            } else
                                g = null;
                        b && (g = b.call(c, a, g));
                        if (null === g)
                            return"null";
                        m = u.call(g);
                        if ("[object Boolean]" == m)
                            return"" + g;
                        if ("[object Number]" == m)
                            return g > -1 / 0 && g < 1 / 0 ? "" + g : "null";
                        if ("[object String]" == m)
                            return R("" + g);
                        if ("object" == typeof g) {
                            for (a = d.length; a--; )
                                if (d[a] === g)
                                    throw K();
                            d.push(g);
                            q = [];
                            c = n;
                            n += f;
                            if ("[object Array]" == m) {
                                k = 0;
                                for (a = g.length; k < a; k++)
                                    m = O(k, g, b, h, f, n, d), q.push(m === w ? "null" :
                                            m);
                                a = q.length ? f ? "[\n" + n + q.join(",\n" + n) + "\n" + c + "]" : "[" + q.join(",") + "]" : "[]"
                            } else
                                B(h || g, function (a) {
                                    var c = O(a, g, b, h, f, n, d);
                                    c !== w && q.push(R(a) + ":" + (f ? " " : "") + c)
                                }), a = q.length ? f ? "{\n" + n + q.join(",\n" + n) + "\n" + c + "}" : "{" + q.join(",") + "}" : "{}";
                            d.pop();
                            return a
                        }
                    };
                    r.stringify = function (a, c, b) {
                        var h, f, n, d;
                        if (F[typeof c] && c)
                            if ("[object Function]" == (d = u.call(c)))
                                f = c;
                            else if ("[object Array]" == d) {
                                n = {};
                                for (var g = 0, k = c.length, l; g < k; l = c[g++], (d = u.call(l), "[object String]" == d || "[object Number]" == d) && (n[l] = 1))
                                    ;
                            }
                        if (b)
                            if ("[object Number]" ==
                                    (d = u.call(b))) {
                                if (0 < (b -= b % 1))
                                    for (h = "", 10 < b && (b = 10); h.length < b; h += " ")
                                        ;
                            } else
                                "[object String]" == d && (h = 10 >= b.length ? b : b.slice(0, 10));
                        return O("", (l = {}, l[""] = a, l), f, n, h, "", [])
                    }
                }
                if (!q("json-parse")) {
                    var V = A.fromCharCode, W = {92: "\\", 34: '"', 47: "/", 98: "\b", 116: "\t", 110: "\n", 102: "\f", 114: "\r"}, b, J, l = function () {
                        b = J = null;
                        throw G();
                    }, z = function () {
                        for (var a = J, c = a.length, e, h, f, k, d; b < c; )
                            switch (d = a.charCodeAt(b), d) {
                                case 9:
                                case 10:
                                case 13:
                                case 32:
                                    b++;
                                    break;
                                case 123:
                                case 125:
                                case 91:
                                case 93:
                                case 58:
                                case 44:
                                    return e =
                                            D ? a.charAt(b) : a[b], b++, e;
                                case 34:
                                    e = "@";
                                    for (b++; b < c; )
                                        if (d = a.charCodeAt(b), 32 > d)
                                            l();
                                        else if (92 == d)
                                            switch (d = a.charCodeAt(++b), d) {
                                                case 92:
                                                case 34:
                                                case 47:
                                                case 98:
                                                case 116:
                                                case 110:
                                                case 102:
                                                case 114:
                                                    e += W[d];
                                                    b++;
                                                    break;
                                                case 117:
                                                    h = ++b;
                                                    for (f = b + 4; b < f; b++)
                                                        d = a.charCodeAt(b), 48 <= d && 57 >= d || 97 <= d && 102 >= d || 65 <= d && 70 >= d || l();
                                                    e += V("0x" + a.slice(h, b));
                                                    break;
                                                default:
                                                    l()
                                            }
                                        else {
                                            if (34 == d)
                                                break;
                                            d = a.charCodeAt(b);
                                            for (h = b; 32 <= d && 92 != d && 34 != d; )
                                                d = a.charCodeAt(++b);
                                            e += a.slice(h, b)
                                        }
                                    if (34 == a.charCodeAt(b))
                                        return b++, e;
                                    l();
                                default:
                                    h =
                                            b;
                                    45 == d && (k = !0, d = a.charCodeAt(++b));
                                    if (48 <= d && 57 >= d) {
                                        for (48 == d && (d = a.charCodeAt(b + 1), 48 <= d && 57 >= d) && l(); b < c && (d = a.charCodeAt(b), 48 <= d && 57 >= d); b++)
                                            ;
                                        if (46 == a.charCodeAt(b)) {
                                            for (f = ++b; f < c && (d = a.charCodeAt(f), 48 <= d && 57 >= d); f++)
                                                ;
                                            f == b && l();
                                            b = f
                                        }
                                        d = a.charCodeAt(b);
                                        if (101 == d || 69 == d) {
                                            d = a.charCodeAt(++b);
                                            43 != d && 45 != d || b++;
                                            for (f = b; f < c && (d = a.charCodeAt(f), 48 <= d && 57 >= d); f++)
                                                ;
                                            f == b && l();
                                            b = f
                                        }
                                        return+a.slice(h, b)
                                    }
                                    k && l();
                                    if ("true" == a.slice(b, b + 4))
                                        return b += 4, !0;
                                    if ("false" == a.slice(b, b + 5))
                                        return b += 5, !1;
                                    if ("null" == a.slice(b,
                                            b + 4))
                                        return b += 4, null;
                                    l()
                            }
                        return"$"
                    }, P = function (a) {
                        var c, b;
                        "$" == a && l();
                        if ("string" == typeof a) {
                            if ("@" == (D ? a.charAt(0) : a[0]))
                                return a.slice(1);
                            if ("[" == a) {
                                for (c = []; ; b || (b = !0)) {
                                    a = z();
                                    if ("]" == a)
                                        break;
                                    b && ("," == a ? (a = z(), "]" == a && l()) : l());
                                    "," == a && l();
                                    c.push(P(a))
                                }
                                return c
                            }
                            if ("{" == a) {
                                for (c = {}; ; b || (b = !0)) {
                                    a = z();
                                    if ("}" == a)
                                        break;
                                    b && ("," == a ? (a = z(), "}" == a && l()) : l());
                                    "," != a && "string" == typeof a && "@" == (D ? a.charAt(0) : a[0]) && ":" == z() || l();
                                    c[a.slice(1)] = P(z())
                                }
                                return c
                            }
                            l()
                        }
                        return a
                    }, T = function (a, b, e) {
                        e = S(a, b, e);
                        e ===
                                w ? delete a[b] : a[b] = e
                    }, S = function (a, b, e) {
                        var h = a[b], f;
                        if ("object" == typeof h && h)
                            if ("[object Array]" == u.call(h))
                                for (f = h.length; f--; )
                                    T(h, f, e);
                            else
                                B(h, function (a) {
                                    T(h, a, e)
                                });
                        return e.call(a, b, h)
                    };
                    r.parse = function (a, c) {
                        var e, h;
                        b = 0;
                        J = "" + a;
                        e = P(z());
                        "$" != z() && l();
                        b = J = null;
                        return c && "[object Function]" == u.call(c) ? S((h = {}, h[""] = e, h), "", c) : e
                    }
                }
            }
            r.runInContext = N;
            return r
        }
        var K = typeof define === "function" && define.amd, F = {"function": !0, object: !0}, G = F[typeof exports] && exports && !exports.nodeType && exports, k = F[typeof window] &&
                window || this, t = G && F[typeof module] && module && !module.nodeType && "object" == typeof global && global;
        !t || t.global !== t && t.window !== t && t.self !== t || (k = t);
        if (G && !K)
            N(k, G);
        else {
            var L = k.JSON, Q = k.JSON3, M = !1, A = N(k, k.JSON3 = {noConflict: function () {
                    M || (M = !0, k.JSON = L, k.JSON3 = Q, L = Q = null);
                    return A
                }});
            k.JSON = {parse: A.parse, stringify: A.stringify}
        }
        K && define(function () {
            return A
        })
    }).call(this);

}
if (typeof (data) !== 'undefined') {
    data = JSON.parse(data);
//console.log('?')
    var containerElementSelector = '.TRM-widget-content-container'

    var insertContent = (function () {

        var selector = data.selector == 'ignoreSelector' ? false : data.selector;
        var placement = data.placement == 'ignorePlaceholder' ? false : data.placement
        if (selector) {
            selector = decodeURIComponent(selector).replace('$', '#')
            var referenceElement = document.querySelector(selector);
        } else {
            var script_tag = false;
            if (data.scriptid) {
                script_tag = document.querySelector("script#" + data.scriptid);
            }
            if (!script_tag) {
                script_tag = document.querySelector("#TRM_teaser_widget_list");
            }
            if (!script_tag) {
                script_tag = document.currentScript;
            }
            if (!script_tag) {
                var scripts = document.getElementsByTagName('script');
                script_tag = scripts[ scripts.length - 1 ];
            }
            if (script_tag instanceof HTMLElement) {
                var referenceElement = script_tag
                placement = 'replace'
            } else {
                var referenceElement = false
            }
        //     console.log(referenceElement);
        }
        return function (content) {
            var containerElement = false, child;
            if (referenceElement instanceof HTMLElement) {
                var parentNode = referenceElement.parentNode
                var htmlElementsArray = [];
                if (typeof (content) === 'string') {
                    var htmlElementsHolder = document.createElement('div');
                    htmlElementsHolder.innerHTML = content;
                    for (var i = 0; i < htmlElementsHolder.children.length; i++) {
                        htmlElementsArray.push(htmlElementsHolder.children.item(i))
                    }
                    containerElement = htmlElementsHolder.querySelector(containerElementSelector);
                } else if (content instanceof HTMLElement) {
                    htmlElementsArray.push(content)
                    containerElement = content.querySelector(containerElementSelector);
                    if (!containerElement) {
                        containerElement = content
                    }
                } else if (content instanceof NodeList) {
                    for (var i = 0; i < content.length; i++) {
                        htmlElementsArray.push(content[i])
                        if (!containerElement) {
                            if (content[i].className.contains(containerElementSelector)) {
                                containerElement = content[i]
                            } else {
                                containerElement = content[i].querySelector(containerElementSelector);
                            }
                        }
                    }
                }
                if (!containerElement) {
                    if (placement !== 'before' && placement !== 'after' && placement !== 'replace') {
                        containerElement = referenceElement;
                    } else {
                        containerElement = parentNode
                    }
                } 
                
               
                switch (placement) {
                    case 'replace':
                    case 'before':
                        var realChild
                       // console.log(htmlElementsArray)
                        while (child = htmlElementsArray.shift()) {
                            child.className += ' trm-analytics-visibilty-tracking'
                            child.dataset.widgetid = data.scriptid;
                            realChild = child
                            parentNode.insertBefore(child, referenceElement);
                        }
                        if (realChild && placement == 'replace') {
                            if (referenceElement.remove) {
                                referenceElement.remove()
                            } else {
                                referenceElement.parentNode.removeChild(referenceElement)
                            }
                            referenceElement = realChild
                        }
                        //console.log(referenceElement.innerHTML)
                        break;
                    case 'after':
                        while (child = htmlElementsArray.pop()) {
                            child.className += ' trm-analytics-visibilty-tracking'
                            child.dataset.widgetid = data.scriptid;
                            if (referenceElement.nextSibling) {
                                parentNode.insertBefore(child, referenceElement.nextSibling);
                            } else if (parentNode.append !== undefined) {
                                parentNode.append(child)
                            } else if (parentNode.appendChild !== undefined) {
                                parentNode.appendChild(child)
                            }
                        }
                        break;
                    case 'prepend' :
                        while (child = htmlElementsArray.pop()) {
                            child.className += ' trm-analytics-visibilty-tracking'
                            child.dataset.widgetid = data.scriptid;
                            if (referenceElement.prepend !== undefined) {
                                referenceElement.prepend(child);
                            } else if (referenceElement.prependChild !== undefined) {
                                referenceElement.prependChild(child)
                            }
                        }
                        break;
                    default:
                        if (placement !== 'append') {
                            referenceElement.innerHTML = '';
                        }
                        while (child = htmlElementsArray.shift()) {
                            child.className += ' trm-analytics-visibilty-tracking'
                            child.dataset.widgetid = data.scriptid;
                            if (referenceElement.append !== undefined) {
                                referenceElement.append(child);
                            } else if (referenceElement.appendChild !== undefined) {
                                referenceElement.appendChild(child)
                            }
                        }
                }
            }
            return containerElement
        }
    })()


    domload.ready(function () {
        //console.log(data.html);
        var containerElement = insertContent(data.html)
        if (containerElement) {
        //    console.log('ready')
            

var devicePixelRatio = window.devicePixelRatio || Math.round(window.screen.availWidth / document.documentElement.clientWidth)

//console.log(0,data.param)
function getPPI() {
    // create an empty element
    var div = document.createElement("div");
    // give it an absolute size of one inch
    div.style.width = "1in";
    // append it to the body
    var body = document.getElementsByTagName("body")[0];
    body.appendChild(div);
    // read the computed width
    var ppi = document.defaultView.getComputedStyle(div, null).getPropertyValue('width');
    // remove it again
    body.removeChild(div);
    // and return the value
    return parseFloat(ppi) * devicePixelRatio;
}

if (data.param.devicePPI === undefined) {
    data.param.devicePPI = getPPI()
}
data.param.devicePixelRatio = devicePixelRatio
data.param.deviceWidth = containerElement.offsetWidth
data.param.deviceHeight = containerElement.offsetHeight


/*if (document.cookie.indexOf('DEBUG')) {
 var debug = true;
 } else {
 var debug = false;
 }*/

var debug = false;
if (debug) {
    console.log('container:', containerElement, containerElement.offsetWidth, containerElement.offsetHeight)
}
if (data.param.width == '100%') {
    data.param.width = containerElement.offsetWidth
    data.param.width_measure = 'px';
}
if (data.param.height == '100%') {
    data.param.height = containerElement.offsetHeight
    data.param.height_measure = 'px';
}
if (data.param.ownSession) {
    data.param.phpsessid = Math.round((new Date().getTime() + Math.random()) * 1000)
    if (debug) {
        console.log('ownSession');
    }
    send(data)
} else {
    try {
        if (!window.top.TRMGETPHPSESSIID || data.param.ownSession) {
            window.top.TRMGETPHPSESSIID = Math.round((new Date().getTime() + Math.random()) * 1000)
            window.top.TRMCounter = -1;
        }
        window.top.TRMCounter++
        data.param.phpsessid = window.top.TRMGETPHPSESSIID
        if (debug) {
            console.log('top document accessed', data.param.phpsessid);
        }
        send(data)
    } catch (e) {
        var attempt = 0;
        var timeouttest = setInterval(function () {
            if (++attempt > 10) {
                console.warn('Attempts to reach top documant are over');
                clearInterval(timeouttest)
            } else {
                console.warn('request for session id is sent to the top document, but no answer received. Attempt #' + attempt);
                window.top.postMessage({message: 'getSessionId'}, '*')
            }
        }, 300)


        window.addEventListener("message", function (e) {
            if (e.data.getSessionId) {
                data.param.phpsessid = e.data.getSessionId
                var counter = e.data.counter
                if (!counter) {
                    counter = 0
                }
                if (debug) {
                    console.log('response for session id is received from the top document', data.param.phpsessid);
                }
                clearInterval(timeouttest)
                send(data)
            }
        })
        if (debug) {
            console.log('request for session id is sent to the top document');
        }
        window.top.postMessage({message: 'getSessionId'}, '*')
    }

}

function send(data) {
    /*if (!data.param.selector) {
     var time = new Date().getTime()
     var selClass = 'TRM-RPA-widget-container-' + time
     containerElement.className += ' ' + selClass
     data.param.selector = '.' + selClass
     }*/
    var time = new Date().getTime()
    var selClass = 'TRM-RPA-widget-script-' + time
    data.param.selector = '.' + selClass
    data.param.placement = 'replace'
    if (data.param.partial_columns_factor == 100) {
        delete data.param.partial_columns_factor
        data.param.column_orientation = 1
        if (data.param.columns) {
            data.param.columns = 1
            if (data.param.width === undefined) {
                data.param.width = containerElement.offsetWidth
                data.param.width_measure = 'px';
            }
        }
    }
    var str = '';
    for (var variable in  data.param) {
        str += '&' + encodeURIComponent(variable) + '=' + encodeURIComponent(data.param[variable])
    }

    var script = document.createElement("script");
    script.type = "text/javascript";
    script.className = selClass
    script.src = 'https://trmads.eu/get' + '?' + str.substr(1);
    insertContent(script)
}

        }
    });

}

})("{\"url\":\"https:\\/\\/trmads.eu\\/get\",\"param\":{\"token\":\"e1e780a2ef35c81ea89c778013174d12\",\"service\":\"rotatingprintad\",\"versions\":\"default_adaptive_color,slick-slider\",\"processingschemas\":\"4\",\"scriptid\":\"trm-rpa-widget-89HDvgtqsbylOyu4\",\"selector\":null,\"placement\":null,\"ownSession\":null,\"noAlignment\":true},\"html\":\"<style>.TRM-gallery .trm-gallery-inner-container {\\n    width:calc(100% - 40px);\\n    margin-left:20px;\\n}\\n.TRM-gallery .trm-slick-slider .slick-arrow{\\n    width:40px;\\n    height:60px;\\n}\\n.TRM-gallery  .trm-slick-slider .slick-prev {\\n   left:0px;\\n}\\n.TRM-gallery  .trm-slick-slider .slick-next {\\n   right:0px;\\n}<\\/style>\",\"selector\":null,\"placement\":null,\"scriptid\":\"trm-rpa-widget-89HDvgtqsbylOyu4\"}")