
(() => {
    const chatheadInjectWidget  = () => {
        const styles = document.createElement('style');
        styles.innerHTML = `

    #jerky-im {
        position: absolute;
        z-index: 10000000001;
        font-family: "Inter", sans-serif;
        font-size: calc((216px + 11vw) / 35 + 7px);
        transition: opacity .4s;
    }

    #jerky-im.jerky-im-hidden {
        opacity: 0;
        pointer-events: none;
        padding-left: 100%;
    }

    #jerky-im.jerky-im-hidden #jerky-im-chat,
    #jerky-im.jerky-im-hidden #jerky-im-avatar-bubble,
    #jerky-im.jerky-im-hidden.jerky-im-show-chat #jerky-im-chat {
        pointer-events: none;
        transform: translateX(calc(240px + 11vw + 20px));
    }

    #jerky-im #jerky-im-chat {
        position: fixed;
        bottom: 18px;
        right: 18px;
        width: calc(240px + 11vw);
        height: calc((216px + 11vw) * 1.45);
        max-height: calc(100% - 119px);
        background: #fff;
        box-shadow: 0 0 25px rgba(0, 0, 0, .15);
        border-radius: 18px;
        overflow: hidden;
        transform-origin: top right;
        transform: scale(.0000001);
        opacity: 0;
        transition: transform .4s, opacity .4s, top .4s;
        pointer-events: none;
        padding: 0;
        margin: 0;
        top: calc(75vh + 83px);
    }

    #jerky-im-inspector {
        position: fixed;
        left: 0;
        top: 0;
        width: calc(75vh + 83px);
        height: calc((216px + 11vw) * 1.45);
        transform: translate(-100%, -100%);
        background: #f00;
    }

    #jerky-im.jerky-im-offset.jerky-im-show-chat #jerky-im-chat {
        top: calc(100% - (((216px + 11vw) * 1.45) + 18px));
    }

    #jerky-im.jerky-im-small-height.jerky-im-show-chat #jerky-im-chat {
        top: calc(101px);
        bottom: 18px;
    }

    @media (max-width: 480px) {
        #jerky-im.jerky-im-offset.jerky-im-show-chat #jerky-im-chat,
        #jerky-im.jerky-im-small-height.jerky-im-show-chat #jerky-im-chat,
        #jerky-im #jerky-im-chat {
            top: calc(101px);
            bottom: 18px;
            width: calc(100vw - 36px);
            height: calc(100% - 119px);
        }

        body #jerky-im #jerky-im-chat {
            top: calc(75vh + 83px);
        }

        body #jerky-im #jerky-im-inspector {
            width: calc(75vh + 83px);
        }

        body #jerky-im #jerky-im-avatar-bubble {
            top: 75vh;
        }
    }

    @media (max-width: 768px) and (min-width: 480px) {
        body #jerky-im #jerky-im-chat {
            top: calc(75vh + 83px);
        }

        body #jerky-im #jerky-im-inspector {
            width: calc(75vh + 83px);
        }

        body #jerky-im #jerky-im-avatar-bubble {
            top: 75vh;
        }
    }

    #jerky-im.jerky-im-show-chat #jerky-im-chat {
        transform: scale(1);
        opacity: 1;
        pointer-events: all;
    }

    #jerky-im #jerky-im-header {
        background: #e7fbfd;
        display: block;
        position: relative;
        margin: 0;
        padding: 12px;
    }

    #jerky-im svg {
        width: 40%;
    }

    #jerky-im .jerky-im-avatar {
        display: block;
        border: none;
        box-shadow: 0 1px 2px rgba(0, 0, 0, .5);
        border-radius: 10000px;
        width: 36px;
        height: 36px;
        background-size: cover;
        position: relative;
        padding: 0;
    }

    #jerky-im .jerky-im-avatar img {
        object-fit: cover;
        position: absolute;
        top: 0;
        left: 0;
        right: 0;
        bottom: 0;
        width: 100%;
        height: 100%;
        border-radius: 10000px;
    }

    #jerky-im .jerky-im-avatar:before {
        content: '';
        display: block;
        position: relative;
        padding-top: 100%;
    }

    #jerky-im #jerky-im-cams-widget-ctn {
        width: calc(100% - 56px);
        padding-top: calc((100% - 56px) * 0.75);
        border: 0;
        margin: 12px 0 0;
        float: right;
        border-radius: 15px;
        position: relative;
        overflow: hidden;
    }

    #jerky-im #jerky-im-cams-widget,
    #jerky-im #jerky-im-feed-overlay {
        width: 100%;
        height: 100%;
        top: 0;
        left: 0;
        right: 0;
        bottom: 0;
        border: 0;
        position: absolute;
        overflow: hidden;
    }    

    #jerky-im .jerky-im-message {
        width: calc(100% - 56px);
        float: right;
        clear: right;
        box-sizing: border-box;
        margin: 12px 0 0;
        border-radius: 15px;
    }

    #jerky-im p.jerky-im-message {
        background: #e7fbfd;
        padding: .6em 1.2em;
        position: relative;
        overflow: visible;
        font-weight: 500;
    }

    #jerky-im p.jerky-im-message:before {
        content: '';
        display: block;
        position: absolute;
        top: 50%;
        left: 0;
        background: inherit;
        transform-origin: .4em .4em;
        transform: translate(-50%, -50%) rotate(45deg);
        width: .8em;
        height: .8em;
    }

    #jerky-im p.jerky-im-message + p.jerky-im-message:before {
        display: none;
    }

    #jerky-im #jerky-im-chat .jerky-im-avatar {
        float: left;
        clear: both;
        margin: 12px 0 0 ;
    }

    #jerky-im .jerky-im-cta,
    #jerky-im #jerky-im-close {
        background: #ff77a8;
        border-radius: 1000px;
        cursor: pointer;
        transition: background-color .2s ease-in 0s, color .2s ease-in 0s;
    }

    #jerky-im .jerky-im-cta {
        font-size: calc((216px + 11vw) / 17);
        border-radius: 10000px;
        display: block;
        color: #fff;
        text-align: center;
        padding: .5em;
        text-decoration: none;
        box-sizing: border-box;
        position: absolute;
        bottom: 12px;
        left: 12px;
        right: 12px;
        font-weight: 600;
        text-transform: uppercase;
    }

    #jerky-im .jerky-im-cta.fr, #jerky-im .jerky-im-cta.pt {
        font-size: calc((216px + 9vw) / 17);
    }


    #jerky-im #jerky-im-close {
        float: right;
        border: 0;
        padding: 0;
        width: 8%;
        outline: none;
        position: relative;
    }

    #jerky-im #jerky-im-close:before {
        content: '';
        padding-top: 100%;
        position: relative;
        display: block;
    }

    #jerky-im #jerky-im-close:hover,
    #jerky-im .jerky-im-cta:hover {
        background: #ff2b77;
    }

    #jerky-im #jerky-im-close svg {
        position: absolute;
        display: block;
        width: 50%;
        height: 50%;
        top: 50%;
        left: 50%;
        transform: translate(-50%, -50%);
    }

    #jerky-im #jerky-im-avatar-bubble {
        position: fixed;
        top: 75vh;
        right: 20px;
        width: 65px;
        height: 65px;
        outline: none !important;
        transition: top .4s ease-in-out;
    }

    @media (min-width: 768px) {
        #jerky-im #jerky-im-avatar-bubble {
            width: 65px;
            height: 65px;
        }
        #jerky-im #jerky-im-avatar-bubble:active {
            width: 58px;
            height: 58px;
        }
    }

    @media (max-width: 767px) {
        #jerky-im #jerky-im-avatar-bubble {
            width: 60px;
            height: 60px;
        }
        #jerky-im #jerky-im-avatar-bubble:active {
            width: 58.5px;
            height: 58.5px;
        }
    }

    @media (max-width: 480px) {
        #jerky-im #jerky-im-avatar-bubble {
            width: 60px;
            height: 60px;
        }
        #jerky-im #jerky-im-avatar-bubble:active {
            width: 58.5px;
            height: 58.5px;
        }
    }

    #jerky-im.jerky-im-offset.jerky-im-show-chat #jerky-im-avatar-bubble {
        top: calc(100% - (((216px + 11vw) * 1.45) + 101px));
    }

    #jerky-im.jerky-im-small-height.jerky-im-show-chat #jerky-im-avatar-bubble {
        top: 18;
    }

    @media (max-width: 480px) {
        #jerky-im.jerky-im-offset.jerky-im-show-chat #jerky-im-avatar-bubble,
        #jerky-im.jerky-im-small-height.jerky-im-show-chat #jerky-im-avatar-bubble,
        #jerky-im.jerky-im-show-chat #jerky-im-avatar-bubble {
            top: 18px;
        }
    }

    #jerky-im #jerky-im-avatar-bubble .dot {
        width: 1em;
        height: 1em;
        background-color: #00bb00;
        border-radius: 10000px;
        display: block;
        position: absolute;
        bottom: 5%;
        right: 5%;
        z-index: 3;
    }

    #jerky-im #jerky-im-messages .dot {
        width: 0.7em;
        height: 0.7em;
        background-color: #00bb00;
        border-radius: 10000px;
        display: block;
        position: absolute;
        top: 24px;
        left: 24px;
        z-index: 3;
    }

    #jerky-im #jerky-im-avatar-bubble:before {
        content: '';
        display: block;
        position: absolute;
        top: 0;
        left: 0;
        right: 0;
        bottom: 0;
        z-index: 2;
        border-radius: 100000px;
        box-shadow: inset 0 -20px 30px -10px rgba(0, 0, 0, .15);
    }

    #jerky-im #jerky-im-avatar-bubble img {
        -webkit-filter: contrast(1.1) saturate(1.1);
        filter: contrast(1.1) saturate(1.1);
    }

    #jerky-im #jerky-im-avatar-bubble:after:not(.prerecorded) {
        content: '2';
        display: block;
        position: absolute;
        top: 5%;
        left: 5%;
        background: #e10;
        color: #fff;
        font-size: 11px;
        width: 1.6em;
        height: 1.6em;
        line-height: 1.6em;
        font-weight: 700;
        text-align: center;
        vertical-align: middle;
        z-index: 3;
        border-radius: 10000px;
    }

    #jerky-im #jerky-im-messages {
        position: relative;
        padding: 0 12px;
        overflow: overlay;
        height: calc(100% - ((216px + 11vw) / 17) * 2 - (216px + 11vw) * 0.07799477164385668 - 48px);
        color: #000;
        overflow-y: auto;
        overflow-x: hidden;
        -ms-overflow-style: none;
        scrollbar-width: none;
    }

    #jerky-im #jerky-im-messages.fr, #jerky-im #jerky-im-messages.pt {
        height: calc(100% - ((216px + 11vw) / 17) * 2.25 - (216px + 11vw) * 0.07799477164385668 - 110px);
    }

    #jerky-im #jerky-im-messages::-webkit-scrollbar {
        display: none;
    }

    .jerky-im-cls-1 {
        fill: #ff76a7;
    }

    .jerky-im-cls-2,
    .jerky-im-cls-6 {
        fill: #1b1464;
    }

    .jerky-im-cls-3 {
        fill: #97f0ff;
    }

    .jerky-im-cls-4 {
        fill: #fff;
    }

    .jerky-im-cls-5 {
        fill: #2727a8;
        opacity: 0.56;
    }

    .jerky-im-cls-6,
    .jerky-im-cls-7 {
        stroke: #97f0ff;
        stroke-miterlimit: 10;
        stroke-width: 3.49px;
    }

    .jerky-im-cls-7 {
        fill: none;
    }

    
    #jerky-im #jerky-im-messages.pre-recorded {
        height: 100% !important;
        padding: 0;
        display: flex;
        flex-direction: column;
        justify-content: space-between;
        align-items: flex-start;
        box-sizing: border-box;
        overflow: hidden;
        font-size: 14px;
    }

    #jerky-im #jerky-im-messages.pre-recorded * {
        box-sizing: border-box;
    }

    #jerky-im .jerky-im-pre-recorded-header {
        width: 100%;
        height: 62px;
        min-height: 62px;
        background: #E9E9E9;
        display: flex;
        align-items: center;
        justify-content: space-between;
        padding: 0 22px;
    }


    #jerky-im .jerky-im-pre-recorded-header #jerky-im-close{
        background: #000;
        margin-left: 10px;
    }

    #jerky-im .jerky-im-pre-recorded-header-left {
        display: flex;
        justify-content: flex-start;
        align-items: center;
    }

    #jerky-im #jerky-im-pre-recorded-profile-img-box {
        width: 40px;
        min-width: 40px;
        height: 40px;
        border-radius: 55%;
        display: flex;
        justify-content: center;
        align-items: center;
        margin: 0 15px 0 0;
    }

    #jerky-im #jerky-im-pre-recorded-profile-img-box img {
        width: 100%;
        height: 100%;
        object-fit: contain;
        border-radius: 55%;
    }

    #jerky-im #jerky-im-pre-recorded-profile-name {
        font-weight: 700;
        font-size: 15px;
    }

    #jerky-im .jerky-im-pre-recorded-online-circle {
        width: 7px;
        height: 7px;
        background: #3dbe00;
        border-radius: 55%;
        margin: -8px 0 0 15px;
    }

    #jerky-im .jerky-im-pre-recorded-messages {
        width: 100%;
        flex-grow: 1;
        display: flex;
        flex-direction: column;
        justify-content: flex-start;
        align-items: flex-start;
        padding: 22px;
        padding-bottom: 0;
        overflow: auto;
    }

    #jerky-im .jerky-im-pre-recorded-messages::-webkit-scrollbar {
        display: none;
    }

    #jerky-im .jerky-im-pre-recorded-messages .message {
        width: 100%;
        display: flex;
        justify-content: flex-start;
        align-items: flex-start;
        margin: 22px 0 0;
        position: relative;
    }

    #jerky-im .jerky-im-pre-recorded-messages #jerkyImChatPreRecordedVideoBox {
        aspect-ratio: 1920 / 1080;
        background: #333333;
    }

    #jerky-im .jerky-im-pre-recorded-messages .message:first-child {
        margin: 0;
    }

    #jerky-im .jerky-im-pre-recorded-messages .message-text {
        max-width: 100%;
        background: #D9D9D9;
        border-radius: 55px;
        padding: 15px 20px;
        line-height: 125%;
    }

    #jerky-im .jerky-im-pre-recorded-messages video {
        width: 100%;
        position: relative;
        z-index: 10;
    }

    #jerky-im .jerky-im-pre-recorded-messages .video-pop {
        width: 100%;
        height: 100%;
        position: absolute;
        left: 0;
        top: 0;
        z-index: -1;
        background-color: rgba(61, 190, 0, 0.8);
        backdrop-filter: blur(5px);
        display: flex;
        flex-direction: column;
        justify-content: center;
        align-items: center;
        color: #ffffff;
        opacity: 0;
        transition: opacity 0.1s; 
    }

    #jerky-im .jerky-im-pre-recorded-messages .video-pop.active {
        opacity: 1;
        z-index: 100;
    }

    #jerky-im .jerky-im-pre-recorded-cta-box {
        width: 100%;
        padding: 20px;
        display: flex;
        justify-content: center;
        align-items: center;
    }

    #jerky-im .jerky-im-pre-recorded-cta {
        height: 39px;
        padding: 0 30px;
        display: flex;
        justify-content: center;
        align-items: center;
        cursor: pointer;
        color: #ffffff;
        text-align: center;
        background: #3dbe00;
        border-radius: 55px;
        text-transform: uppercase;
        font-weight: 600;
        text-decoration: none;
        transition: 0.2s;
    }

    #jerky-im .jerky-im-pre-recorded-messages .video-pop .jerky-im-pre-recorded-video-pop-text {
        width: 100%;
        text-align: center;
        font-weight: 600;
        line-height: 150%;
        padding: 0 15px;
        margin: 0 0 15px;
        color: #ffffff;
    }

    @media (max-width: 374px) {
        #jerky-im .jerky-im-pre-recorded-cta.cta-bottom {
            width: 100%;
            padding: 0;
        }
    }

    #jerky-im .jerky-im-pre-recorded-cta:hover {
        background: #089606;
        color: #ffffff;
        box-shadow: 0px 0px 15px rgba(61, 190, 0, .5);
    }

    #jerky-im .jerky-im-pre-recorded-cta.white {
        background: #ffffff;
        color: #3dbe00;
        padding-left: 15px;
        padding-right: 15px;
    }

    #jerky-im .jerky-im-pre-recorded-cta.white:hover {
        background: #ffffff;
        box-shadow: none;
        color: #3dbe00;
    }

    #jerky-im .prerecorded-message-count-corner {
        width: 25px;
        height: 25px;
        position: absolute;
        left: -5px;
        top: -5px;
        background: #ff0000;
        border-radius: 55%;
        color: #ffffff;
        font-weight: 900;
        display: flex;
        justify-content: center;
        align-items: center;
        font-size: 18px;
        box-sizing: border-box;
    }

    #jerky-im .videoLoader {
        width: 48px;
        height: 48px;
        border: 5px solid #FFF;
        border-bottom-color: transparent;
        border-radius: 50%;
        display: inline-block;
        box-sizing: border-box;
        animation: rotation 1s linear infinite;
        position: absolute;
        left: 0;
        right: 0;
        top: 0;
        bottom: 0;
        margin: auto;
        z-index: 0;
    }

    @keyframes rotation {
        0% {
            transform: rotate(0deg);
        }
        100% {
            transform: rotate(360deg);
        }
    } `;
        document.head.appendChild(styles);
    
        const body = document.createElement('div');
        body.innerHTML = `

<div id="jerky-im">
    
    <button
        id="jerky-im-avatar-bubble"
        class="jerky-im-avatar prerecorded"
    >
        <img src="https://cdn.cemiocw.com/liv-wild/profile.png" alt="avatar">
        
            <div class="prerecorded-message-count-corner">1</div>
        
    </button>

    <div id="jerky-im-chat">
        
            <div id="jerky-im-messages" class="pre-recorded">

    <div class="jerky-im-pre-recorded-header">

        <div class="jerky-im-pre-recorded-header-left">
            <div id="jerky-im-pre-recorded-profile-img-box">
                <a href="https://m.samaragrad.ru/panachil-kemabiru-taseset-pawaquilkir-tredewas-hadasmiol/?aff_sub3=model-liv-wild&aff_sub4=AT_0018&aff_sub5=SF_006OG000004lmDN" target="_blank">
                    <img src="https://cdn.cemiocw.com/liv-wild/profile.png">
                </a>
            </div>
        </div>

        <button id="jerky-im-close">
            <svg version="1.1" style="enable-background:new 0 0 47.971 47.971; fill: #fff" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" x="0px" y="0px" viewBox="0 0 47.971 47.971" xml:space="preserve">
            <path d="M28.228,23.986L47.092,5.122c1.172-1.171,1.172-3.071,0-4.242c-1.172-1.172-3.07-1.172-4.242,0L23.986,19.744L5.121,0.88
            c-1.172-1.172-3.07-1.172-4.242,0c-1.172,1.171-1.172,3.071,0,4.242l18.865,18.864L0.879,42.85c-1.172,1.171-1.172,3.071,0,4.242
            C1.465,47.677,2.233,47.97,3,47.97s1.535-0.293,2.121-0.879l18.865-18.864L42.85,47.091c0.586,0.586,1.354,0.879,2.121,0.879
            s1.535-0.293,2.121-0.879c1.172-1.171,1.172-3.071,0-4.242L28.228,23.986z">
            </path>
            </svg>
        </button>
    
    </div>

    <div class="jerky-im-pre-recorded-messages">
        
        <a href="https://m.samaragrad.ru/panachil-kemabiru-taseset-pawaquilkir-tredewas-hadasmiol/?aff_sub3=model-liv-wild&aff_sub4=AT_0018&aff_sub5=SF_006OG000004lmDN" target="_blank" class="message" id="jerkyImChatPreRecordedVideoBox" data-video-src="https://cdn.cemiocw.com/liv-wild/video.mp4">
            <div class="video-pop" href="https://m.samaragrad.ru/panachil-kemabiru-taseset-pawaquilkir-tredewas-hadasmiol/?aff_sub3=model-liv-wild&aff_sub4=AT_0018&aff_sub5=SF_006OG000004lmDN" target="_blank" id="jerkyImChatPreRecordedVideoPop">
                <span class="jerky-im-pre-recorded-video-pop-text">Ready for a chat?</span>
                <div class="jerky-im-pre-recorded-cta white">
                    Continue
                </div>
            </div>
            <div class="videoLoader"></div>
        </a>
        <div class="message">
            <div id="jerky-im-pre-recorded-profile-img-box">
                <a href="https://m.samaragrad.ru/panachil-kemabiru-taseset-pawaquilkir-tredewas-hadasmiol/?aff_sub3=model-liv-wild&aff_sub4=AT_0018&aff_sub5=SF_006OG000004lmDN" target="_blank">
                    <img src="https://cdn.cemiocw.com/liv-wild/profile.png">
                </a>
            </div>
            <div class="message-text">
                Hey there! 😍
            </div>
        </div>
        <div class="message">
            <div id="jerky-im-pre-recorded-profile-img-box">
                <a href="https://m.samaragrad.ru/panachil-kemabiru-taseset-pawaquilkir-tredewas-hadasmiol/?aff_sub3=model-liv-wild&aff_sub4=AT_0018&aff_sub5=SF_006OG000004lmDN" target="_blank">
                    <img src="https://cdn.cemiocw.com/liv-wild/profile.png">
                </a>
            </div>
            <div class="message-text">
                Ready to take things to the next level? Let's get flirty & dirty!
            </div>
        </div>
    </div>

    <div class="jerky-im-pre-recorded-cta-box">
        <a href="https://m.samaragrad.ru/panachil-kemabiru-taseset-pawaquilkir-tredewas-hadasmiol/?aff_sub3=model-liv-wild&aff_sub4=AT_0018&aff_sub5=SF_006OG000004lmDN" target="_blank" class="jerky-im-pre-recorded-cta cta-bottom">
            Start Chatting Now
        </a>
    </div>

</div>
        
    </div>
    <div id="jerky-im-inspector"></div>
</div>`;
        document.body.appendChild(body);
    
        const chatheadWidgetScript = document.createElement('script');
        chatheadWidgetScript.type = "text/javascript";
        chatheadWidgetScript.innerHTML = `
    (() => {
      const jerkyImVideoPlayer = document.getElementById('pre-recorded-video-player');
const jerkyImVideoPlayerAnim = document.getElementById('pre-recorded-video-player-box-anim-box')
const jerkyImVideoPlayerCtaAfter = document.getElementById('pre-recorded-video-player-box-cta-after')
let chatPreviouslyOpen = false;

const jerkyImVideoPlayerEnded = () => {
    if(jerkyImVideoPlayer && jerkyImVideoPlayerCtaAfter && jerkyImVideoPlayerAnim) {
        jerkyImVideoPlayer.pause()
        jerkyImVideoPlayer.removeEventListener('ended',jerkyImVideoPlayerEnded);
        jerkyImVideoPlayer.muted = true
        jerkyImVideoPlayer.style.opacity = 0;
        jerkyImVideoPlayerAnim.style.opacity = 0;
        jerkyImVideoPlayerCtaAfter.classList.add('active');
    }
}

const playPreRecorededScene = () => {

    if(jerkyImVideoPlayerAnim && jerkyImVideoPlayer) {

        if(chatPreviouslyOpen) {

            //IF CHATHEAD OPENED BEFORE SHOW THE JOIN BOX
            jerkyImVideoPlayerEnded();

        } else {

            setTimeout(() => { 
                jerkyImVideoPlayerAnim.style.opacity = 0;
                jerkyImVideoPlayer.play()
                jerkyImVideoPlayer.muted = false
                jerkyImVideoPlayer.style.opacity = 1;
                jerkyImVideoPlayer.addEventListener('ended',jerkyImVideoPlayerEnded);
            }, 2000)
        }
    }

    chatPreviouslyOpen = true;

}

      const jerkyIm = document.getElementById('jerky-im');
      const jerkyBubble = document.getElementById('jerky-im-avatar-bubble');
      const jerkyCloseBtn = document.getElementById('jerky-im-close');
      const jerkyOffsetInspector = document.getElementById('jerky-im-inspector');
      const jerkyChat = document.getElementById('jerky-im-chat');
      const jerkyImVideoIframe = document.getElementById('jerky-im-cams-widget');

      let jerkyOpen = false;
      let jerkyOffset = false;
      let jerkySmallHeight = false;
      let jerkyHidden = false;

      function unmuteVideo() {
        if(jerkyImVideoIframe) {
          jerkyImVideoIframe.src = jerkyImVideoIframe.src.replace('sound=off', 'sound=on');
        }
      }

      function muteVideo() {
        if(jerkyImVideoIframe) {
          jerkyImVideoIframe.src = jerkyImVideoIframe.src.replace('sound=on', 'sound=off');
        }
      }

      function jerkyToggleChat(toggle) {
        if (toggle === false && false) {
            jerkyHidden = true
            true && muteVideo()
        } else {
            jerkyOpen = typeof toggle === 'boolean' ? toggle : !jerkyOpen;
            true && (jerkyOpen ? unmuteVideo() : muteVideo())
        }

        if(jerkyOpen) {
        
          if(jerkyImVideoIframe) {
            jerkyImVideoIframe.hidden = false
          }
          
          //PRE RECORED FUNCTION THAT IS PARSED IN FROM pre_recorded_video/js.ejs AT THE TOP OF THIS FILE
          if(typeof playPreRecorededScene === "function") {
            playPreRecorededScene()
          }
        
        }
        else {
          if(jerkyImVideoIframe) {
            jerkyImVideoIframe.hidden = true
          }
        }

        jerkyApplyClasses();
      }

      
      function jerkyToggleChatPreRecorded(toggle) {
        const jerkyImChatPreRecordedVideo = document.getElementById('jerkyImChatPreRecordedVideo')
        jerkyOpen = typeof toggle === 'boolean' ? toggle : !jerkyOpen;
        
        if(jerkyImChatPreRecordedVideo) {
          if(jerkyOpen) {
            jerkyImChatPreRecordedVideo.play();
          } else {
            jerkyImChatPreRecordedVideo.pause();
          }
        } else {
          addPrerecordedVideo();
        }
        
        jerkyApplyClasses();
      }

      const prerecordedVideoEnd = () => {
        const jerkyImChatPreRecordedVideoPop = document.getElementById('jerkyImChatPreRecordedVideoPop');
        jerkyImChatPreRecordedVideoPop.classList.add('active');
      }
      
      const addPrerecordedVideo = () => {
        const jerkyImChatPreRecordedVideoBox = document.getElementById('jerkyImChatPreRecordedVideoBox')

        const videoSrc = jerkyImChatPreRecordedVideoBox.getAttribute('data-video-src');
        const video = document.createElement('video');
        video.src = videoSrc;
        video.autoplay = true;
        video.id = 'jerkyImChatPreRecordedVideo';
        video.setAttribute('webkit-playsinline', 'webkit-playsinline');
        video.setAttribute('playsinline', 'playsinline');
        video.addEventListener("ended", prerecordedVideoEnd);

        jerkyImChatPreRecordedVideoBox.prepend(video)
      }


      function jerkyCheckOffset() {
        const jerkyOffsetTop = jerkyOffsetInspector.offsetWidth; /* Don't worry, it's the right value */
        const jerkyOffsetHeight = jerkyOffsetInspector.offsetHeight;

        jerkyOffset = jerkyOffsetTop + jerkyOffsetHeight > (window.innerHeight - 18);
        jerkySmallHeight = jerkyOffsetHeight > (window.innerHeight -(18 * 3 + 60));

        jerkyApplyClasses();
      }

      function jerkyApplyClasses() {
        jerkyIm.className =
          (jerkyOpen ? 'jerky-im-show-chat' : '')
          + ' '
          + (jerkyOffset ? 'jerky-im-offset' : '')
          + ' '
          + (jerkySmallHeight ? 'jerky-im-small-height' : '')
          + ' '
          + (jerkyHidden ? 'jerky-im-hidden' : '');
      }

      
          jerkyCloseBtn.addEventListener('mouseup', function () { jerkyToggleChatPreRecorded(false) });
        jerkyBubble.addEventListener('mouseup', jerkyToggleChatPreRecorded);
      

      window.addEventListener('resize', jerkyCheckOffset)

      jerkyCheckOffset();
    })();

`;
        document.body.appendChild(chatheadWidgetScript);
    }

    const interval = setInterval(() => { 
        if(document?.readyState !== "loading" ) {
            chatheadInjectWidget();
            clearInterval(interval)
        }
     }, 500)
     
})();
    
