(function () {
    // temp vars, needed for loading only. use window[wj][hash][embedConfig] when needed
    var wjEmbedConfig = {"buttonText":"Register","buttonBgColor":"#FD7A00","buttonBgOpacity":"1","barBgColor":"#08759E","barBgOpacity":"1","type":null,"formTemplate":"2","formColor":"1","formButtonText":"Register Now","hash":"10644i7","memberId":240692,"webinarId":10,"webinarTitle":"Mission Suite Demo","embedType":"bar","dependencies":{"js":"https:\/\/event.webinarjam.com\/js\/registration_embed.js","css":"https:\/\/event.webinarjam.com\/css\/registration_embed.css"},"routes":{"convertDates":"https:\/\/event.webinarjam.com\/register\/10644i7\/convert-dates","trackVisitor":"https:\/\/event.webinarjam.com\/register\/10644i7\/visitor","registrationForm":"https:\/\/event.webinarjam.com\/register\/10\/10644i7\/form?ts=1660657121\u0026formTemplate=2\u0026formColor=1"},"barHtml":"\u003Cdiv class=\u0022wj_embed_wrapper wj_bottombar wj_expanded\u0022 style=\u0022display: none; bottom: 0px;\u0022\u003E\n    \u003Cdiv class=\u0022wj_embed_wrapper_grid\u0022\u003E\n        \u003Cbutton type=\u0022button\u0022 class=\u0022wj_bottombar_collapse js_bottom_bar_bg\u0022\u003E\u003C\/button\u003E\n    \u003C\/div\u003E\n    \u003Cdiv class=\u0022wj_cover-img js_bottom_bar_bg js-bottombar-section\u0022 id=\u0022js-bottombar-section\u0022\u003E\n        \u003Cdiv class=\u0022wj_mobile_header\u0022\u003E\n            \u003Cdiv class=\u0022wj_container\u0022\u003E\n                \u003Cdiv class=\u0022wj_row\u0022\u003E\n                    \u003Cdiv class=\u0022wj_col-12\u0022\u003E\n                        \u003Ch6 class=\u0022js_register_text\u0022\u003ERegister\u003C\/h6\u003E\n                    \u003C\/div\u003E\n                \u003C\/div\u003E\n            \u003C\/div\u003E\n        \u003C\/div\u003E\n        \u003Cdiv class=\u0022wj_content wj_d-flex wj_align-items-center wj_justify-content-center\u0022\u003E\n            \u003Cdiv class=\u0022wj_container\u0022\u003E\n                \u003Cdiv class=\u0022wj_row wj_d-block wj_d-md-flex wj_align-items-center wj_text-center wj_text-md-left\u0022\u003E\n                    \u003Cdiv class=\u0022wj_col-12 wj_col-md-5\u0022\u003E\n                        \u003Cul id=\u0022js_date_1\u0022 class=\u0022wj_bottombar_date_list js_all_schedules\u0022\u003E\n                            \n                        \u003C\/ul\u003E\n                        \u003Cdiv class=\u0022wj_timezone_text js_wj_timezone_text\u0022\u003EEastern Standard Time\u003C\/div\u003E\n                        \u003Ca href=\u0022#\u0022 class=\u0022wj_embed_bubble_detail_box_link\u0022 style=\u0022display: none;\u0022\u003EView more dates\u003C\/a\u003E\n                    \u003C\/div\u003E\n                    \u003Cdiv class=\u0022wj_col-12 wj_col-md-7 wj_d-md-flex wj_justify-content-md-end wj_align-items-center\u0022\u003E\n                        \u003Cdiv class=\u0022wj_countdown_wrapper wj_mb-3 wj_mb-md-0\u0022\u003E\n                            \u003Cul id=\u0022countdown\u0022 class=\u0022js_countdown list-unstyled\u0022\u003E\u003C\/ul\u003E\n                        \u003C\/div\u003E\n                        \u003Cdiv class=\u0022wj_ml-0 wj_ml-md-5\u0022\u003E\n                            \u003Cbutton type=\u0022button\u0022 id=\u0022js-reg-btn\u0022 class=\u0022wj_btn wj_btn-db wj_btn-rect wj_btn-xlg wj_btn-semiblack js_wj_register_button js_wj_action_button\u0022\u003E\n                                \u003Cspan class=\u0022js_register_text\u0022\u003ERegister\u003C\/span\u003E\n                            \u003C\/button\u003E\n                        \u003C\/div\u003E\n                    \u003C\/div\u003E\n                \u003C\/div\u003E\n            \u003C\/div\u003E\n            \u003Cdiv class=\u0022wj_red_overlay_content wj_d-flex wj_align-items-center wj_justify-content-center wj_hide\u0022\u003E\n                \u003Cdiv class=\u0022wj_container\u0022\u003E\n                    \u003Cdiv class=\u0022wj_row\u0022\u003E\n                        \u003Cdiv class=\u0022wj_col-12\u0022\u003E\n                            \u003Cdiv class=\u0022wj_red_overlay_title\u0022\u003E\u003C\/div\u003E\n                            \u003Cdiv class=\u0022wj_red_overlay_desc\u0022\u003E\u003C\/div\u003E\n                        \u003C\/div\u003E\n                    \u003C\/div\u003E\n                \u003C\/div\u003E\n            \u003C\/div\u003E\n        \u003C\/div\u003E\n    \u003C\/div\u003E\n\u003C\/div\u003E\n\n\u003Cdiv class=\u0022wj_registration-overlay\u0022 style=\u0022top: 0px; display: none;\u0022\u003E\n    \u003Cdiv id=\u0022wj_registration_frame_holder\u0022 style=\u0022margin: 0 auto; max-width: 700px;\u0022\u003E\n        \u003Cdiv style=\u0022height: 270px;\u0022\u003E\n            \u003Cdiv class=\u0022wj_overlay-loading-screen\u0022 style=\u0022display:;\u0022\u003E\n                \u003Cdiv class=\u0022wj_overlay_inner\u0022\u003E\n    \u003Cdiv class=\u0022wj_css_spinner_coghweel n_s wj_mb-4\u0022\u003E\n        \u003Cdiv\u003E\n            \u003Ci\u003E\u003C\/i\u003E\n            \u003Ci\u003E\u003C\/i\u003E\n        \u003C\/div\u003E\n    \u003C\/div\u003E\n    \u003Cspan\u003E\u003Clang data-tag=\u0022Txt_connecting_to_server\u0022\u003E{{Txt_connecting_to_server}}\u003C\/lang\u003E\u003C\/span\u003E\n\u003C\/div\u003E\n            \u003C\/div\u003E\n            \u003Ciframe src=\u0022\u0022 id=\u0022wj_registration_frame\u0022 frameborder=\u00220\u0022 name=\u0022wj_registration_frame\u0022 scrolling=\u0022no\u0022 style=\u0022display:none; height: 270px; max-width: 700px; width: 100vw; z-index: 1000000; -webkit-overflow-scrolling: touch\u0022\u003E\u003C\/iframe\u003E\n        \u003C\/div\u003E\n    \u003C\/div\u003E\n\u003C\/div\u003E\n\n\u003Cdiv id=\u0022wj-templates\u0022 style=\u0022display:none; visibility: hidden; height: 0px; width: 0px;\u0022\u003E\n    \u003Cdiv id=\u0022wj-template-date\u0022\u003E\n        \u003Cli class=\u0022bullet1\u0022\u003E\n            \u003Cstrong class=\u0022js_day_name\u0022\u003EWednesday\u003C\/strong\u003E, \u003Cspan class=\u0022js_day\u0022\u003E13\u003C\/span\u003E \u003Cspan class=\u0022js_month_name\u0022\u003EApr\u003C\/span\u003E \u003Cspan class=\u0022js_year\u0022\u003E2017\u003C\/span\u003E, \u003Cspan class=\u0022js_text_at\u0022\u003Eat\u003C\/span\u003E \u003Cspan class=\u0022js_time\u0022\u003E1:00 pm\u003C\/span\u003E\n        \u003C\/li\u003E\n    \u003C\/div\u003E\n    \u003Cdiv id=\u0022wj-template-date-new\u0022\u003E\n        \u003Cli class=\u0022bullet1 js_date_container\u0022\u003E\u003C\/li\u003E\n    \u003C\/div\u003E\n\u003C\/div\u003E\n","translations":{"Text_days":"DAYS","Text_hours":"HOURS","Txt_instant_replay":"Watch yesterday\u0027s replay now","MSG_minutes":"Minutes","MSG_seconds":"Seconds","Txt_connecting_to_server":"Checking availability...","Txt_webinar_not_ready_yet":"WEBINAR NOT READY YET!","Txt_this_webinar_expired":"THIS WEBINAR HAS EXPIRED!","Txt_preparing_webinar":"We\u0027re preparing this webinar as we speak, and it should be ready very soon. Please refresh this page in about 60 seconds...","Txt_webinar_already_taken_place":"This webinar has already taken place. Sorry, it seems like you missed it.","Txt_join_event_in_progress":"Join event in progress"}},
        webinarHash = wjEmbedConfig['hash'],
        embedType = wjEmbedConfig['embedType'];

    wjEmbedConfig['timezoneOffset'] = -(new Date()).getTimezoneOffset();

    if (
        typeof window['wj'] !== 'undefined' &&
        typeof window['wj'][webinarHash] !== 'undefined' &&
        'undefined' !== typeof window['wj'][webinarHash][embedType]
    ) {
        return;
    }

    window['wj'] = 'undefined' === typeof window['wj'] ? [] : window['wj'];
    window['wj'][webinarHash] = 'undefined' === typeof window['wj'][webinarHash] ? {} : window['wj'][webinarHash];
    window['wj'][webinarHash][embedType] = 'undefined' === typeof window['wj'][webinarHash][embedType] ? wjEmbedConfig : window['wj'][webinarHash][embedType];

    var jsJquery    = document.createElement("script");
    jsJquery.type   = "text/javascript";
    jsJquery.onload = init;
    jsJquery.src    = "https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js";
    document.body.appendChild(jsJquery);

    var ua     = window.navigator.userAgent,
        iOS    = !!ua.match(/iP(ad|od|hone)/i),
        webkit = !!ua.match(/WebKit/i),
        isiOS  = iOS && webkit;

    function init() {
        if (embedType === 'bar' || embedType === 'bubble') {
            document.body.insertAdjacentHTML('beforeend', wjEmbedConfig.barHtml);
        }

        loadDependencies();
    };

    function loadDependencies() {
        var wjCssId = 'wjCss-' + webinarHash;
        if (!document.getElementById(wjCssId)) {
            var head  = document.getElementsByTagName('head')[0];
            var link  = document.createElement('link');
            link.id   = wjCssId;
            link.rel  = 'stylesheet';
            link.type = 'text/css';
            link.href = wjEmbedConfig.dependencies.css;
            link.media = 'all';
            head.appendChild(link);
        }

        var wjJsId = 'wjJs-' + webinarHash;
        if (!document.getElementById(wjJsId)) {
            var script  = document.createElement('script');
            script.id   = wjJsId;
            script.type = 'text/javascript';
            script.onload = realInit;
            script.src = wjEmbedConfig.dependencies.js;
            document.body.appendChild(script);
        }
    }

    function realInit() {
        if (embedType === 'bar') {
            return initBottomBar();
        }

        if (embedType === 'button') {
            return initButton();
        }

        if (embedType === 'bubble') {
            return initBubble();
        }
    }

    function initBubble() {
        window['wj'][webinarHash]['jQuery'] = jQuery.noConflict(true);
        window['wj'][webinarHash]['jQuery'].ajaxSetup({
            xhrFields: {
                withCredentials: true
            },
            crossDomain: true
        });
        var jQ = window['wj'][webinarHash]['jQuery'];

        jQ(document).ready(function() {
            var barBgColor = tinycolor(wjEmbedConfig.barBgColor);
            var buttonBgColor = tinycolor(wjEmbedConfig.buttonBgColor);
            var data = {
                offset: wjEmbedConfig.timezoneOffset,
                limit: 3,
                source: "bar",
            };

            barBgColor.setAlpha(wjEmbedConfig.barBgOpacity);
            buttonBgColor.setAlpha(wjEmbedConfig.buttonBgOpacity);

            var datesXhr = jQ.post(wjEmbedConfig.routes.convertDates, data);

            datesXhr.done(function (response) {
                if (response.registrationDates.length === 0) {
                    if (typeof response.pendingChanges !== 'undefined' && response.pendingChanges === true) {
                        jQ('.wj_embed_bubble_detail_box_title').text(wjEmbedConfig.translations.Txt_webinar_not_ready_yet);
                        jQ('.wj_embed_bubble_detail_box_text').text(wjEmbedConfig.translations.Txt_preparing_webinar);
                    } else {
                        jQ('.wj_embed_bubble_detail_box_title').text(wjEmbedConfig.translations.Txt_this_webinar_expired);
                        jQ('.wj_embed_bubble_detail_box_text').text(wjEmbedConfig.translations.Txt_webinar_already_taken_place);
                        jQ('.wj_embed_bubble_detail_box').addClass('wj_red_overlay_content');
                        jQ('.js_wj_bubble_registration_in_progress').css('display', 'none');
                        jQ('.js_wj_bubble_registration_expired').css('display', 'block');
                    }

                    jQ('.wj_red_overlay_content').removeClass('wj_hide');
                } else {
                    var filteredEvents = [];

                    jQ.each(response.registrationDates, function (index, date) {
                        if (
                            ('undefined' === typeof date.is_date || true === date.is_date) &&
                            ('undefined' === typeof date.instant_replay || false === date.instant_replay)
                        ) {
                            filteredEvents.push(date);
                        }
                    });

                    var filteredEventsLength = filteredEvents.length;

                    if (!filteredEventsLength) {
                        jQ('.wj_embed_bubble_detail_box_date').text(response.registrationDates[0].text);
                        jQ('.wj_embed_bubble_detail_box_countdown').text(response.registrationDates[0].relative_text);
                    } else {
                        jQ('.wj_embed_bubble_detail_box_date').text(filteredEvents[0].text);
                        jQ('.wj_embed_bubble_detail_box_countdown').text(filteredEvents[0].relative_text);

                        if (filteredEventsLength > 1) {
                            jQ('.wj_embed_bubble_detail_box_link').css('display', '');
                        }
                    }
                }

                // replacements for colors, text, countdown
                jQ('.wj_embed_bubble_detail_box_button').text(wjEmbedConfig.buttonText);
                jQ('.wj_embed_bubble_detail_box').css("background-color", barBgColor);
                jQ('.js_bubble_webinar_cta').css("background-color", buttonBgColor);
                <!-- jQ('.js_bubble_toggle').css("background-color", barBgColor); -->
                jQ('.wj_embed_bubble_detail_box_button').css("background-color", buttonBgColor).attr('data-webinarHash', webinarHash);
                jQ('.wj_embed_bubble_detail_box_link').css('color', buttonBgColor).attr('data-webinarHash', webinarHash);
                jQ('.wj_embed_bubble_detail_box_title').text(wjEmbedConfig.webinarTitle);

                var initTime = Date.now();

                // start countdown
                var countdownOptions = {
                    fontFamily: '"Roboto", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif, "Apple Color Emoji", "Segoe UI Emoji", "Segoe UI Symbol", "Noto Color Emoji"',
                    displayDays: false,
                    displayCaptions: true,
                    fontSize: 12,
                    countdown: true,
                }

                if (response.countdownSeconds > 0) {
                    countdownOptions.seconds = response.countdownSeconds;
                    if (countdownOptions.seconds / 3600 < 24) {
                        jQ('.wj_embed_bubble_detail_box_countdown').css('display', 'none');
                        jQ('.js_countdown').css('display', 'block');
                    }
                    var countdownDays = Math.floor(countdownOptions.seconds/86400);
                    if (countdownDays >= 100) {
                        countdownOptions.displayDays = 3;
                    }
                } else {
                    countdownOptions.timeTo = new Date();
                    countdownOptions.start = false;
                }

                jQ('.js_countdown').timeTo(countdownOptions);

                jQ('.js_countdown figcaption:eq(0)').html('<lang data-tag="Text_hours">{{Text_hours}}</lang>');
                jQ('.js_countdown figcaption:eq(1)').html('<lang data-tag="MSG_minutes">{{MSG_minutes}}</lang>');
                jQ('.js_countdown figcaption:eq(2)').html('<lang data-tag="MSG_seconds">{{MSG_seconds}}</lang>');

                document.addEventListener('visibilitychange', function logData() {
                    if (document.visibilityState === 'hidden') {
                        jQ('.js_countdown').timeTo('stop');
                    }
                    if (document.visibilityState === 'visible') {
                        if (countdownOptions.seconds > 0) {
                            var timeNow = Date.now();
                            var timeDiff = Math.round((timeNow - initTime) / 1000);
                            countdownOptions.seconds = response.countdownSeconds - timeDiff;
                        }
                        if (countdownOptions.seconds <= 0) {
                            countdownOptions.timeTo = new Date();
                            countdownOptions.start = false;
                        }
                        jQ('.js_countdown').timeTo(countdownOptions);
                    }
                });

                // show bar
                jQ('.wj_embed_circle_wrapper').fadeIn();

                // init registration modal
                replaceLang();
                initRegistrationModal();
                trackVisitor();
            });
            datesXhr.fail(function () {
                console.error('Could not get dates from WJ server');
            })
        });
    }

    function initBottomBar() {
        window['wj'][webinarHash]['jQuery'] = jQuery.noConflict(true);
        window['wj'][webinarHash]['jQuery'].ajaxSetup({
            xhrFields: {
               withCredentials: true
            },
            crossDomain: true
        });
        var jQ = window['wj'][webinarHash]['jQuery'];

        jQ(document).ready(function() {
            var $html = jQ('html'),
                $body = jQ('body');

            var barBgColor = tinycolor(wjEmbedConfig.barBgColor);
            barBgColor.setAlpha(wjEmbedConfig.barBgOpacity);

            var buttonBgColor = tinycolor(wjEmbedConfig.buttonBgColor);
            buttonBgColor.setAlpha(wjEmbedConfig.buttonBgOpacity);

            var data = {
                offset: wjEmbedConfig.timezoneOffset,
                limit: 3,
                source: "bar",
            };

            var datesXhr = jQ.post(wjEmbedConfig.routes.convertDates, data);

            datesXhr.done(function (response) {
                if (response.registrationDates.length === 0) {
                    if (typeof response.pendingChanges !== 'undefined' && response.pendingChanges === true)  {
                        jQ('.wj_red_overlay_title').text(wjEmbedConfig.translations.Txt_webinar_not_ready_yet);
                        jQ('.wj_red_overlay_desc').text(wjEmbedConfig.translations.Txt_preparing_webinar);
                    } else {
                        jQ('.wj_red_overlay_title').text(wjEmbedConfig.translations.Txt_this_webinar_expired);
                        jQ('.wj_red_overlay_desc').text(wjEmbedConfig.translations.Txt_webinar_already_taken_place);
                    }

                    jQ('.wj_red_overlay_content').removeClass('wj_hide');
                } else {
                    var filteredEvents = [];

                    jQ.each(response.registrationDates, function (index, date) {
                        if (
                            ('undefined' === typeof date.is_date || true === date.is_date) &&
                            ('undefined' === typeof date.instant_replay || false === date.instant_replay)
                        ) {
                            filteredEvents.push(date);
                        }
                    });

                    var filteredEventsLength = filteredEvents.length,
                        $template = jQ('#wj-templates #wj-template-date-new').clone();

                    if (!filteredEventsLength) {
                        $template.find('li.js_date_container').text(response.registrationDates[0].text);
                    } else {
                        $template.find('li.js_date_container').text(filteredEvents[0].text);

                        if (filteredEventsLength > 1) {
                            jQ('.wj_embed_bubble_detail_box_link').css('display', '');
                        }
                    }

                    jQ('ul.js_all_schedules').html($template.html());
                }

                var timezoneCities = response.timezone.cities;

                // replacements for dates, colors, text, countdown
                jQ('.js_register_text').text(wjEmbedConfig.buttonText);
                jQ('.js_bottom_bar_bg').css("background-color", barBgColor);
                jQ('.js_wj_register_button').css("background-color", buttonBgColor);
                jQ('.js_wj_register_button').attr('data-webinarHash', webinarHash);
                jQ('.wj_embed_bubble_detail_box_link').css('color', buttonBgColor).attr('data-webinarHash', webinarHash);
                jQ('.js_wj_timezone_text').text(timezoneCities);

                var initTime = Date.now();

                // start countdown
                var countdownOptions = {
                    fontFamily: '"Roboto", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif, "Apple Color Emoji", "Segoe UI Emoji", "Segoe UI Symbol", "Noto Color Emoji"',
                    displayDays: 2,
                    displayCaptions: true,
                    fontSize: 26,
                    captionSize: 10,
                    countdown: true,
                }
                if (response.countdownSeconds > 0) {
                    countdownOptions.seconds = response.countdownSeconds;
                    var countdownDays = Math.floor(countdownOptions.seconds/86400);
                    if (countdownDays >= 100) {
                        countdownOptions.displayDays = 3;
                    }
                } else {
                    countdownOptions.timeTo = new Date();
                    countdownOptions.start = false;
                }
                jQ('.js_countdown').timeTo(countdownOptions);

                jQ('.js_countdown figcaption:eq(0)').html('<lang data-tag="Text_days">{{Text_days}}</lang>');
                jQ('.js_countdown figcaption:eq(1)').html('<lang data-tag="Text_hours">{{Text_hours}}</lang>');
                jQ('.js_countdown figcaption:eq(2)').html('<lang data-tag="MSG_minutes">{{MSG_minutes}}</lang>');
                jQ('.js_countdown figcaption:eq(3)').html('<lang data-tag="MSG_seconds">{{MSG_seconds}}</lang>');

                document.addEventListener('visibilitychange', function logData() {
                    if (document.visibilityState === 'hidden') {
                        jQ('.js_countdown').timeTo('stop');
                    }
                    if (document.visibilityState === 'visible') {
                        if (countdownOptions.seconds > 0) {
                            var timeNow = Date.now();
                            var timeDiff = Math.round((timeNow - initTime) / 1000);
                            countdownOptions.seconds = response.countdownSeconds - timeDiff;
                        }
                        if (countdownOptions.seconds <= 0) {
                            countdownOptions.timeTo = new Date();
                            countdownOptions.start = false;
                        }
                        jQ('.js_countdown').timeTo(countdownOptions);
                    }
                });

                // show bar
                jQ('.wj_embed_wrapper').fadeIn();

                // init registration modal
                replaceLang();
                initRegistrationModal();
                trackVisitor();
            });
            datesXhr.fail(function () {
                console.error('Could not get dates from WJ server');
            })
        });
    }

    function initButton() {
        window['wj'][webinarHash]['jQuery'] = jQuery.noConflict(true);
        window['wj'][webinarHash]['jQuery'].ajaxSetup({
            xhrFields: {
               withCredentials: true
            },
            crossDomain: true
        });
        var jQ = window['wj'][webinarHash]['jQuery'];

        jQ(document).ready(function() {
            var $html = jQ('html'),
                $body = jQ('body');
            var $button = jQ('.js-embed-button');

            if ($button) {
                var buttonBgColor = tinycolor(wjEmbedConfig.buttonBgColor);
                buttonBgColor.setAlpha(wjEmbedConfig.buttonBgOpacity);

                $button.text(wjEmbedConfig.buttonText);
                $button.css("padding", wjEmbedConfig.buttonPadding);
                $button.css("font-size", wjEmbedConfig.buttonFontSize);
                $button.css("color", wjEmbedConfig.buttonTextColor);
                $button.css("background-color", buttonBgColor);

                $button.parent().fadeIn();
            }


            initRegistrationIframeOverlay();

            // init registration modal
            replaceLang();
            initRegistrationModal();
            trackVisitor();
        });
    }

    function replaceLang()
    {
        var jQ = window['wj'][webinarHash]['jQuery'];

        // replace any translations
        jQ('lang').each(function (key, item) {
            var $item = jQ(item);
            var tag = $item.attr('data-tag');
            $item.text(wjEmbedConfig.translations[tag]);
        });
    }

    function initRegistrationIframeOverlay()
    {
        var jQ = window['wj'][webinarHash]['jQuery'];

        if (jQ('.wj_registration-overlay').length) {
            return ;
        }

        if (typeof wjEmbedConfig.iframeOverlayHtml === 'undefined') {
            return ;
        }

        document.body.insertAdjacentHTML('beforeend', wjEmbedConfig.iframeOverlayHtml);
    }

    function initRegistrationModal() {
        var jQ = window['wj'][webinarHash]['jQuery'];

        jQ(document).ready(function() {
            var $html = jQ('html'),
                $body = jQ('body');

            window['wj'][webinarHash]['real_loaded'] = false;
            window['wj'][webinarHash]['fake_loaded'] = false;


            window.removeEventListener('message', window['wj']['wjOnIframeMessage'], true);
            window.addEventListener('message', window['wj']['wjOnIframeMessage'], false);

            // registration button click
            jQ('[data-webinarHash='+webinarHash+']').off().on('click', function () {

                $body.addClass("wj_body_reset");
                $html.css('overflow', 'hidden');

                var $self  = jQ(this),
                    webinarHash = $self.attr('data-webinarHash');

                jQ('.wj_registration-overlay').show();
                var iframeSrc = wjEmbedConfig.routes.registrationForm + '&offset=' + wjEmbedConfig.timezoneOffset;
                jQ('#wj_registration_frame').attr('src', iframeSrc);

                setTimeout(function() {
                    hideLoader(webinarHash, 'fake');
                }, 3000);
            });
        });
    }

    function trackVisitor() {
        var jQ = window['wj'][webinarHash]['jQuery'];

        jQ(document).ready(function() {
            var $html = jQ('html'),
                $body = jQ('body'),
                hasVisitorCookie = window.wjHasCookie(wjEmbedConfig.memberId, webinarHash),
                visitorCookie = window.wjTrackingCookie(wjEmbedConfig.memberId, webinarHash);

            if (!hasVisitorCookie) {
                jQ.post(wjEmbedConfig.routes.trackVisitor, {});
                window.wjSetVisitorCookie(wjEmbedConfig.memberId, webinarHash);
            }
        });
    }

    window['wj']['wjOnIframeMessage'] = function (message) {
        if ('undefined' === typeof message.data) {
            return;
        }

        var webinarHash = message.data.hash;

        if (
            'undefined' === typeof webinarHash ||
            'undefined' === typeof window['wj'][webinarHash] ||
            'undefined' === typeof window['wj'][webinarHash]['jQuery']
        ) {
            return;
        }

        var jQ = window['wj'][webinarHash]['jQuery'],
            $html = jQ('html'),
            $body = jQ('body');

        switch (message.data['func']) {
            case 'loaded':
                hideLoader(webinarHash, 'real');
                break;
            case 'resize':
                adjustFrameSize(webinarHash, message.data['height'] + 'px');
                break;
            case 'resizeWidth':
                adjustFrameWidth(webinarHash, message.data['width'] + 'px');
                break;
            case 'toTop':
                jQ(window).scrollTop(0);
                break;
            case 'redirect':
                recursiveRedirect(window.parent, message.data['url']);
                break;
            case 'close':
                window['wj'][webinarHash]['real_loaded'] = false;
                window['wj'][webinarHash]['fake_loaded'] = false;

                // hide the whole popup
                // show the loader inside the hidden popup
                // hide the iframe inside the hidden popup
                jQ('.wj_registration-overlay').hide();
                jQ('.wj_overlay-loading-screen').show();
                jQ('#wj_registration_frame').hide();

                $html.css('overflow','auto');
                $body.css('height','').removeClass('wj_body_reset');

                adjustFrameSize(webinarHash, '270px');
                break;
        }
    }

    function recursiveRedirect(parent, url) {
        try {
            parent.location = url;
        } catch(err) {
            parent = parent.parent;
            recursiveRedirect(parent, url);
        }
    }

    function hideLoader(webinarHash, version) {
        var jQ = window['wj'][webinarHash]['jQuery'];

        window['wj'][webinarHash][version + '_loaded'] = true;

        if (window['wj'][webinarHash]['real_loaded'] && window['wj'][webinarHash]['fake_loaded']) {
            jQ('.wj_overlay-loading-screen').hide();
            jQ('#wj_registration_frame').show();

            // @todo
            var theFrame = document.getElementById('wj_registration_frame').contentWindow;
            theFrame.postMessage({
                'func': 'childResize',
            }, '*')
        }
    }

    function adjustFrameSize(webinarHash, height) {
        var jQ = window['wj'][webinarHash]['jQuery'],
            $theFrame = jQ('#wj_registration_frame');

        $theFrame.css('height', height);
        $theFrame.parent().css('height', height);

    }

    function adjustFrameWidth(webinarHash, width) {
        var jQ = window['wj'][webinarHash]['jQuery'];
        jQ('#wj_registration_frame_holder').css('max-width', width)
        jQ('#wj_registration_frame').css('max-width', width)
    }

    function rePosition(webinarHash) {
        if (!window['wj'][webinarHash]['wj_lock_scroll']) {
            return false;
        }

        var jQ            = window['wj'][webinarHash]['jQuery'],
            $htmlBody     = jQ('html,body'),
            scrollTop     = jQ(window).scrollTop(),
            screenY       = Math.max(document.documentElement.clientHeight, window.innerHeight || 0),
            scrollBottom  = jQ(window).scrollTop() + screenY,
            marginTop     = screenY * 0.2, // 20% of screen size
            marginBot     = screenY * 0.5, // 50% of screen size
            modalOverlay  = jQ('.wj_registration-overlay'),
            modalPadding  = parseInt(modalOverlay.css('paddingTop')),
            iframeHeight  = jQ('#wj_registration_frame').outerHeight(),
            height        = screenY > iframeHeight ? screenY : iframeHeight,
            frameBot      = modalPadding + height;

        if (scrollTop < modalPadding - marginTop) {
            $htmlBody.stop().animate({scrollTop: modalPadding}, 50, 'swing');
            return true;
        } else if (scrollBottom > frameBot + marginBot) {
            $htmlBody.stop().animate({scrollTop: frameBot - screenY}, 50, 'swing');
            return true;
        }

        return false;
    }
})();
