/* Minification failed. Returning unminified contents.
(428,54-55): run-time error JS1195: Expected expression: >
(433,26-27): run-time error JS1195: Expected expression: )
(441,21-22): run-time error JS1002: Syntax error: }
(485,58-59): run-time error JS1195: Expected expression: >
(487,30-31): run-time error JS1195: Expected expression: )
(493,21-22): run-time error JS1002: Syntax error: }
(497,47-48): run-time error JS1195: Expected expression: )
(497,49-50): run-time error JS1004: Expected ';': {
(525,17-18): run-time error JS1195: Expected expression: ,
(525,73-74): run-time error JS1004: Expected ';': {
(537,17-18): run-time error JS1195: Expected expression: ,
(537,75-76): run-time error JS1004: Expected ';': {
(547,17-18): run-time error JS1195: Expected expression: ,
(547,72-73): run-time error JS1004: Expected ';': {
(646,17-18): run-time error JS1195: Expected expression: ,
(646,71-72): run-time error JS1004: Expected ';': {
(783,17-18): run-time error JS1195: Expected expression: ,
(783,49-50): run-time error JS1195: Expected expression: )
(783,51-52): run-time error JS1004: Expected ';': {
(817,62-63): run-time error JS1195: Expected expression: >
(817,64-65): run-time error JS1197: Too many errors. The file might not be a JavaScript file: {
(504,25-31): run-time error JS1018: 'return' statement outside of function: return
 */
/*!
 * JavaScript Cookie v2.2.0
 * https://github.com/js-cookie/js-cookie
 *
 * Copyright 2006, 2015 Klaus Hartl & Fagner Brack
 * Released under the MIT license
 */
;(function (factory) {
	var registeredInModuleLoader;
	if (typeof define === 'function' && define.amd) {
		define(factory);
		registeredInModuleLoader = true;
	}
	if (typeof exports === 'object') {
		module.exports = factory();
		registeredInModuleLoader = true;
	}
	if (!registeredInModuleLoader) {
		var OldCookies = window.Cookies;
		var api = window.Cookies = factory();
		api.noConflict = function () {
			window.Cookies = OldCookies;
			return api;
		};
	}
}(function () {
	function extend () {
		var i = 0;
		var result = {};
		for (; i < arguments.length; i++) {
			var attributes = arguments[ i ];
			for (var key in attributes) {
				result[key] = attributes[key];
			}
		}
		return result;
	}

	function init (converter) {
		function api (key, value, attributes) {
			if (typeof document === 'undefined') {
				return;
			}

			// Write

			if (arguments.length > 1) {
				attributes = extend({
					path: '/'
				}, api.defaults, attributes);

				if (typeof attributes.expires === 'number') {
					attributes.expires = new Date(new Date() * 1 + attributes.expires * 864e+5);
				}

				// We're using "expires" because "max-age" is not supported by IE
				attributes.expires = attributes.expires ? attributes.expires.toUTCString() : '';

				try {
					var result = JSON.stringify(value);
					if (/^[\{\[]/.test(result)) {
						value = result;
					}
				} catch (e) {}

				value = converter.write ?
					converter.write(value, key) :
					encodeURIComponent(String(value))
						.replace(/%(23|24|26|2B|3A|3C|3E|3D|2F|3F|40|5B|5D|5E|60|7B|7D|7C)/g, decodeURIComponent);

				key = encodeURIComponent(String(key))
					.replace(/%(23|24|26|2B|5E|60|7C)/g, decodeURIComponent)
					.replace(/[\(\)]/g, escape);

				var stringifiedAttributes = '';
				for (var attributeName in attributes) {
					if (!attributes[attributeName]) {
						continue;
					}
					stringifiedAttributes += '; ' + attributeName;
					if (attributes[attributeName] === true) {
						continue;
					}

					// Considers RFC 6265 section 5.2:
					// ...
					// 3.  If the remaining unparsed-attributes contains a %x3B (";")
					//     character:
					// Consume the characters of the unparsed-attributes up to,
					// not including, the first %x3B (";") character.
					// ...
					stringifiedAttributes += '=' + attributes[attributeName].split(';')[0];
				}

				return (document.cookie = key + '=' + value + stringifiedAttributes);
			}

			// Read

			var jar = {};
			var decode = function (s) {
				return s.replace(/(%[0-9A-Z]{2})+/g, decodeURIComponent);
			};
			// To prevent the for loop in the first place assign an empty array
			// in case there are no cookies at all.
			var cookies = document.cookie ? document.cookie.split('; ') : [];
			var i = 0;

			for (; i < cookies.length; i++) {
				var parts = cookies[i].split('=');
				var cookie = parts.slice(1).join('=');

				if (!this.json && cookie.charAt(0) === '"') {
					cookie = cookie.slice(1, -1);
				}

				try {
					var name = decode(parts[0]);
					cookie = (converter.read || converter)(cookie, name) ||
						decode(cookie);

					if (this.json) {
						try {
							cookie = JSON.parse(cookie);
						} catch (e) {}
					}

					jar[name] = cookie;

					if (key === name) {
						break;
					}
				} catch (e) {}
			}

			return key ? jar[key] : jar;
		}

		api.set = api;
		api.get = function (key) {
			return api.call(api, key);
		};
		api.getJSON = function (key) {
			return api.call({
				json: true
			}, key);
		};
		api.remove = function (key, attributes) {
			api(key, '', extend(attributes, {
				expires: -1
			}));
		};

		api.defaults = {};

		api.withConverter = init;

		return api;
	}

	return init(function () {});
}));
;
extend(saffire, {
    cookies: {
        cookieRegistry: function (opts) {

            var data = {
                mode: 'none' //options 'none' = all cookies allowed, 'userConsent' = end user can manage
                , categories: []
                , groups: []
            }

            function init(opts) {
                data = $.extend(data, opts);
            }

            init(opts);

            /**
             * public API.
             * @public
            */
            return {
                a: function () { alert('cookieConsentRegistry'); }
                , d: function () { }
                , addGroups: function (groups) {
                    data.groups = $.merge(data.groups, groups);
                }
                , getMode: function () { return data.mode; }
                , getGroupList: function () {
                    return data.groups;
                }
                , getCategories: function () {
                    return data.categories;
                }
            }


        }
        , cookieConsentManager: function (cookieConsentRegistry) {

            var isAnalyticsRejected = false

            var reg = cookieConsentRegistry;

            // cookie banner
            var cookieBannerMessage = '\
              We use cookies to offer you a better browsing experience, analyze site traffic, personalize content and serve targeted advertisements.\
              Read about how we use cookies and how you can control them by clicking \"Manage Cookie Preferences\".\
              If you continue to use this site, you consent to our use of cookies.\
            ';
            var cookieBannerContent = '\
              <div id="cookie-banner-container">\
                <div class="cookie-banner-content">\
                  <p>'+ cookieBannerMessage + '</p>\
                  <div class="cookie-banner-buttons">\
                    <div class="cookie-banner-settings-btn">Manage Cookie Preferences</div>\
                    <div class="cookie-banner-reject-btn">Reject All</div>\
                    <div class="cookie-banner-accept-btn">Accept All</div>\
                  </div>\
                </div>\
              </div>\
            ';
            var removeCookieBanner = function () {
                $("#cookie-settings-container").remove();
                $("#cookie-banner-container").remove();
            };
            // end cookie banner

            // cookie settings manager
            var cookieSettingsMainMessage = '\
              The website uses \"cookies\", which are elements of data that a website can send to your browser, which may then be stored on your system.\
              This element of data is a piece of text, not a program. The website can only access the information from a cookie sent by the website.\
              We cannot access other cookies sent by other websites or the information contained therein.\
              Additionally, we cannot learn your e-mail address or any other information about you through the use of a cookie.\
              The only way we would learn such information is if you specifically and voluntarily submit that information to us, for example,\
              through a registration system, by entering a sweepstakes or promotion, etc.\
            ';

            var categoryHTML = {};
            var cookieCategoriesToShow = '';

            var createSettingsCategories = function () {
                var catList = reg.getCategories();
                
                function checkExistingCookieSettings(catListItem) {
                    var cookieBannerCookie = Cookies.getJSON('SA_COOKIE_BANNER');
                    var gpcOverrideCookie = Cookies.getJSON('SA_GPC_COOKIE_CATEGORIES');
                    
                    function setAcceptedStatus(acceptedCookies) {
                        var acceptedStatus = {};
                        var isAccepted = 1;
                        var isChecked = 'checked';
                        if (acceptedCookies.indexOf(catListItem.key) === -1) {
                            isAccepted = 0;
                            isChecked = '';
                        }
                        acceptedStatus.isAccepted = isAccepted;
                        acceptedStatus.isChecked = isChecked;
                        return acceptedStatus;
                    }

                    if (cookieBannerCookie !== undefined) {
                        if (navigator.globalPrivacyControl) {
                            if (gpcOverrideCookie !== undefined) {
                                return setAcceptedStatus(gpcOverrideCookie.A);
                            } else {
                                return setAcceptedStatus(['essential']);
                            }
                        } else {
                            return setAcceptedStatus(cookieBannerCookie.A);
                        }
                    } else {
                        var customAcceptedCookies = window.cookieAcceptedCategoriesCustom;
                        if (customAcceptedCookies !== undefined) {
                            return setAcceptedStatus(customAcceptedCookies);
                        } else {
                            var acceptedStatus = {};
                            acceptedStatus.isAccepted = 1;
                            acceptedStatus.isChecked = 'checked';
                            return acceptedStatus;
                        }
                    }

                }

                catList.forEach(function (item, i) {
                    var checkSettingsResults = checkExistingCookieSettings(item);
                    var catContentBlock = '\
                  <div class="cookie-settings-category" data-cookie-category-key="'+ item.key + '">\
                    <div class="cookie-settings-category-top">\
                      <span>'+ item.name + '</span>\
                      <div class="cookie-settings-category-toggle '+ checkSettingsResults.isChecked + '" data-cookie-category-accepted="' + checkSettingsResults.isAccepted + '">\
                          <div class="cs-slider cs-round"></div>\
                      </div>\
                    </div>\
                    <div class="cookie-settings-category-info">\
                      <p>'+ item.description + '</p>\
                    </div>\
                  </div>\
                ';
                    categoryHTML[item.key] = catContentBlock;
                });

            };

            var buildCategoriesToDisplay = function () {
                var cookieGroupList = reg.getGroupList();
                var categoryKeys = ['essential'];

                cookieGroupList.forEach(function (item, i) {
                    if (categoryKeys.indexOf(item.categoryKey) === -1) {
                        categoryKeys.push(item.categoryKey);
                    }
                });

                categoryKeys.forEach(function (item, i) {
                    var categoryToShow = categoryHTML[item];
                    if (categoryToShow !== undefined) {
                        cookieCategoriesToShow += categoryToShow;
                    }
                });
            };


            function getCookieSettingsContent() {
                cookieCategoriesToShow = '';
                categoryHTML = [];
                cookieCategoriesToShow = '';
                createSettingsCategories();
                buildCategoriesToDisplay();

                var cookieSettingsContent = '\
                <div id="cookie-settings-container" data-changed="0">\
                  <div class="cookie-settings-content">\
                    <div class="cookie-settings-content-message">\
                      <span>Cookie Settings</span>\
                      <p>'+ cookieSettingsMainMessage + '</p>\
                    </div><div class="cookie-settings-content-category-wrapper">\
                    '+ cookieCategoriesToShow + '</div>\
                    <div class="cookie-settings-content-bottom">\
                      <div class="cookie-settings-save-btn">Save Settings</div>\
                    </div>\
                  </div>\
                </div>\
              ';
                return cookieSettingsContent;
            }

            var toggleCookieCategoryInfo = function (element) {
                var closestCategory = element.closest('.cookie-settings-category');
                if (closestCategory.hasClass('view-info')) {
                    closestCategory.removeClass('view-info');
                    $('.cookie-settings-category').removeClass('view-info');
                } else {
                    $('.cookie-settings-category').removeClass('view-info');
                    closestCategory.addClass('view-info');
                }
            };
            var toggleCookieSettingsCategory = function (element) {
                element.toggleClass('checked');
                var $settingsContainer = $('#cookie-settings-container');
                var cookieAccepted = element.data('cookie-category-accepted');
                if (cookieAccepted === 1) {
                    element.data("cookie-category-accepted", 0);
                    element.attr("data-cookie-category-accepted", 0);
                    $settingsContainer.data('changed', 1);
                } else {
                    element.data("cookie-category-accepted", 1);
                    element.attr("data-cookie-category-accepted", 1);
                    $settingsContainer.data('changed', 0);
                }
            };

            var sendGAEvent = function (action, label) {

                if (typeof (ga) != "undefined") {
                    ga('send', 'event', 'cookieConsentManager', action, label);
                    ga('aggregate.send', 'event', 'cookieConsentManager', action, label);
                }

                if (typeof (gtag) != "undefined") {
                    gtag('event', 'cookieConsentManager', {
                        'event_action': action, 'event_label': label });
                }
            };

            // end cookie settings manager

            /**
             * public API.
             * @public
            */
            return {
                openCookieManager: function () {
                    var cookieSettingsManager = getCookieSettingsContent();
                    if ($("#cookie-settings-container").length === 0) {
                        $("body").prepend(cookieSettingsManager);
                    }

                    $("#cookie-settings-container").addClass("show-cookie-settings");
                    $("#cookie-settings-container .cookie-settings-category-toggle").click(function () {
                        toggleCookieSettingsCategory($(this));
                    });
                    $("#cookie-settings-container .cookie-settings-category-top span").click(function () {
                        toggleCookieCategoryInfo($(this));
                    });
                    $("#cookie-settings-container .cookie-settings-save-btn").click(function () {
                        if (navigator.globalPrivacyControl) {
                            cookieConsentMgr.closeCookieManager(false, true, true);
                        } else {
                            cookieConsentMgr.closeCookieManager(false, true);
                        }
                    });

                }
                , closeCookieManager: function (isRejectAll, closedFromCookieManager, gpcEnabled) {
            
                    var cookiesAllowed = [];
                    var cookiesNotAllowed = [];

                    // If the user clicked on Reject All
                    if(isRejectAll) 
                    {
                        var categories = reg.getCategories();

                        categories.forEach(category => {
                            if(category.isEssential === true)
                                cookiesAllowed.push(category.key);
                            else
                                cookiesNotAllowed.push(category.key);
                        });

                        cookieConsentMgr.saveCookie(cookiesAllowed, cookiesNotAllowed);

                        if (cookiesAllowed.length > 0)
                            sendGAEvent('accepted', cookiesAllowed.toString());
                        if (cookiesNotAllowed.length > 0)
                            sendGAEvent('denied', cookiesNotAllowed.toString());
                    }
                    // If the user clicked on Accept All or Save Settings
                    else
                    {
                        if (closedFromCookieManager) {
                            // user clicked Save Settings from the cookie manager - should accept all user-chosen categories

                            $("#cookie-settings-container .cookie-settings-category").each(function () {
                                var categoryKey = $(this).data("cookie-category-key");
                                var isCategoryAllowed = $(this).find(".cookie-settings-category-toggle").data("cookie-category-accepted");
                                if (isCategoryAllowed === 1) {
                                    cookiesAllowed.push(categoryKey);
                                } else {
                                    cookiesNotAllowed.push(categoryKey);
                                    }
                            });

                            // console.log('cfcm:')
                            // console.log(cookiesAllowed)
                            cookieConsentMgr.saveCookie(cookiesAllowed, cookiesNotAllowed);

                            // if GPC is enabled, set the GPC override cookie
                            if (gpcEnabled) {
                                cookieConsentMgr.saveGPCCookie(cookiesAllowed, cookiesNotAllowed);
                            }
        
                            var $settingsContainer = $('#cookie-settings-container');
        
                            if ($settingsContainer.data('changed') == "1") {
        
                                if (cookiesAllowed.length > 0) {
                                    sendGAEvent('accepted', cookiesAllowed.toString());
                                }
                                if (cookiesNotAllowed.length > 0) {
                                    sendGAEvent('denied', cookiesNotAllowed.toString());
                                }
                            } else {
                                sendGAEvent('settingContainer', 'noChange');
                            }

                        } else {

                            // user clicked Accept All from banner - should accept ALL categories
                            var categories = reg.getCategories();
                            categories.forEach(category => {
                                cookiesAllowed.push(category.key);
                            });

                            cookieConsentMgr.saveCookie(cookiesAllowed, cookiesNotAllowed);

                            sendGAEvent('accepted', cookiesAllowed.toString());                          
                        }
                    }

                    removeCookieBanner();
                }
                , showCookieBanner: function () {
                    var cookieSettingsManager = getCookieSettingsContent();

                    if (navigator.globalPrivacyControl)
                    {
                        sendGAEvent('rejectAllGPC', '');
                        cookieConsentMgr.closeCookieManager(true, false);
                        return;
                    }

                    $("body").prepend(cookieSettingsManager, cookieBannerContent);
                    // reject btn
                    $("#cookie-banner-container .cookie-banner-reject-btn").click(function () {
                        sendGAEvent('rejectAllFromBanner', '');
                        cookieConsentMgr.closeCookieManager(true, false);
                    });
                    // accept btn
                    $("#cookie-banner-container .cookie-banner-accept-btn").click(function () {
                        sendGAEvent('acceptAllFromBanner', '');
                        cookieConsentMgr.closeCookieManager(false, false);
                    });
                    // settings btn
                    $("#cookie-banner-container .cookie-banner-settings-btn").click(function () {
                        sendGAEvent('viewSettingsFromBanner', '');
                        cookieConsentMgr.openCookieManager();
                    });

                }
                , saveCookie: function (cookiesAccepted, cookiesDenied) {

                    cookies.set('SA_COOKIE_BANNER',
                        {
                            S: new Date(),
                            A: cookiesAccepted,
                            D: cookiesDenied
                        },
                        { expires: 365 }
                    );

                }
                , saveGPCCookie: function(cookiesAccepted, cookiesDenied) {
                    cookies.set('SA_GPC_COOKIE_CATEGORIES',
                        {
                            S: new Date(),
                            A: cookiesAccepted,
                            D: cookiesDenied
                        },
                        { expires: 365 }
                    );
                }
                , excecuteAcceptedCookies2: function (cookiesAccepted) {  // THIS SHOULD PROBABLY BE REFACTORED

                    if (cookiesAccepted === "all") {

                        // execute all scripts if cookie banner has not been shown yet
                        var allScripts = $('script[type="text/plain"]');
                        var numOfScripts = allScripts.length;
                        var plainScriptElements = []

                        var scriptsWithSrc = 0;
                        var scriptsWithNoSrc = 0;
                        var loadedScripts = 0;

                        for (i = 0; i < numOfScripts; i++) {
                            var scriptElem = $(allScripts[i]);
                            var scriptSrc = scriptElem.attr('src');
                            plainScriptElements.push(scriptElem);
                            if (scriptSrc !== undefined) {
                                scriptsWithSrc += 1;
                                $.ajax({
                                    url: scriptSrc,
                                    dataType: 'script',
                                    async: false,
                                }).done(function () {
                                    loadedScripts += 1;
                                    runOtherScripts();
                                })
                            } else {
                                scriptsWithNoSrc += 1;
                                if (i === (numOfScripts - 1)) {
                                    runOtherScripts();
                                }
                            }
                            function runOtherScripts() {
                                if ((loadedScripts === scriptsWithSrc) && (scriptsWithNoSrc === (numOfScripts - loadedScripts))) {
                                    for (i = 0; i < numOfScripts; i++) {
                                        if ($(allScripts[i]).attr('src') === undefined) {
                                            var toJS = $(allScripts[i]).attr('type', 'text/javascript');

                                            $(allScripts[i]).replaceWith(toJS);
                                        }
                                    }
                                }
                            }
                        }
                    } else {

                        // execute certain scripts only if listed as accepted in the cookie
                        var allScripts = $('script[type="text/plain"]');
                        var numOfScripts = allScripts.length;
                        var acceptedScriptElements = []

                        for (i = 0; i < numOfScripts; i++) {
                            var scriptElem = $(allScripts[i]);
                            var scriptDataCat = scriptElem.data("consent-category");

                            if (cookiesAccepted.indexOf(scriptDataCat) > -1) {
                                acceptedScriptElements.push(scriptElem);
                            } else {
                            }
                        }

                        var scriptsWithSrc = 0;
                        var scriptsWithNoSrc = 0;
                        var loadedScripts = 0;

                        for (i = 0; i < acceptedScriptElements.length; i++) {

                            var acceptedScriptElem = $(acceptedScriptElements[i]);
                            var acceptedScriptSrc = acceptedScriptElem.attr('src');
                            if (acceptedScriptSrc !== undefined) {
                                scriptsWithSrc += 1;
                                $.ajax({
                                    url: acceptedScriptSrc,
                                    dataType: 'script',
                                    async: false,
                                }).done(function () {
                                    loadedScripts += 1;
                                    runOtherAcceptedScripts();
                                })
                            } else {
                                scriptsWithNoSrc += 1;
                                if (i === (acceptedScriptElements.length - 1)) {
                                    runOtherAcceptedScripts();
                                }
                            }
                            function runOtherAcceptedScripts() {
                                if ((loadedScripts === scriptsWithSrc) && (scriptsWithNoSrc === (acceptedScriptElements.length - loadedScripts))) {
                                    for (i = 0; i < acceptedScriptElements.length; i++) {
                                        if ($(acceptedScriptElements[i]).attr('src') === undefined) {
                                            var toJS = $(acceptedScriptElements[i]).attr('type', 'text/javascript');
                                            $(acceptedScriptElements[i]).replaceWith(toJS);
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
                , excecuteAcceptedCookies: function (cookiesAccepted) {
                    // console.log(navigator.globalPrivacyControl)
                    // console.log('exec cookies accepted:')
                    // console.log(cookiesAccepted)

                    // console.log(`executing: ${cookiesAccepted}`)

                    var $dataConsentElements = $("[data-consent-category]");
                    var allCookiesAccepted = cookiesAccepted == "all" ? true : false;

                    // console.log($dataConsentElements)
                    // console.log(`allCookiesAccepted: ${allCookiesAccepted}`)

                    //External scripts

                    $.when.apply(this, getScriptRequests())
                        .then(function () {

                            var $externalScripts = $(getScriptElements(true, false));

                            $externalScripts.each(function () {
                                $(this).remove();
                            });

                            processNonExternalScriptResources();

                        });

                    function processNonExternalScriptResources() {

                        //Inline scripts

                        var $inlineScripts = $(getScriptElements(false, true));
                        $inlineScripts.each(function () {
                            convertScriptTypeToExecutable($(this));
                        });

                        //Image pixels

                        var $imageElements = $($dataConsentElements.filter("img"));
                        $imageElements.each(function () {
                            convertDataAttributeSrcToElementSrc($(this));
                        });

                        //Iframe pixels

                        var $iframeElements = $($dataConsentElements.filter("iframe"));
                        $iframeElements.each(function () {
                            convertDataAttributeSrcToElementSrc($(this));
                        });

                    }

                    //Support functions
                    function convertDataAttributeSrcToElementSrc($elem) {
                        if (isCookieCategoryAccepted($elem) || allCookiesAccepted) {
                            if ($elem.data('src') !== undefined) {
                                $elem.attr('src', $elem.data('src'));
                            }
                        }
                    }

                    function convertScriptTypeToExecutable($elem) {                        
                        if (isCookieCategoryAccepted($elem) || allCookiesAccepted) {                            
                            if ($elem.attr("type") == 'text/plain') {                                

                                var srcElem = $elem[0];
                                var srcElemParent = srcElem.parentNode;
                                var content = $elem.html();

                                var sc = document.createElement('script');
                                sc.type = "text/javascript";
                                sc.text = content;

                                srcElemParent.insertBefore(sc, srcElem);
                                srcElemParent.removeChild(srcElem);
                                                              
                            }
                        }
                    }
                                    

                    function isCookieCategoryAccepted($elem) {
                        var elementCategory = $elem.data("consent-category");
                        return cookiesAccepted.indexOf(elementCategory) > -1;
                    }

                    function isExternalScript($elem) {
                        return $elem.prop('tagName').toLowerCase() == 'script' && $elem.attr('src') !== undefined;
                    }

                    function getScriptElements(getExternal, getInternal) {
                        var $allScriptElements = $dataConsentElements.filter("script");
                        var $scriptElements = [];

                        for (var x = 0; x < $allScriptElements.length; x++) {
                            var $script = $($allScriptElements[x]);

                                var isExternal = isExternalScript($script);

                                if (isExternal && getExternal || !isExternal && getInternal) {
                                    $scriptElements.push($script);
                                }
                        }

                        return $scriptElements;
                    }

                    function getScriptRequests() {
                        var $externalScripts = getScriptElements($dataConsentElements, true, false);
                        var $scriptAJAX = [];

                        for (var x = 0; x < $externalScripts.length; x++) {
                            var $script = $($externalScripts[x]);

                            if (isCookieCategoryAccepted($script) || allCookiesAccepted) {

                                var scriptSrc = $script.attr("src");
                                if (scriptSrc !== undefined) {
                                    $scriptAJAX.push(
                                        $.ajax({
                                            url: scriptSrc,
                                            dataType: 'script',
                                            async: true,
                                            cache: true
                                        })
                                    );
                                }

                            }

                        }

                        return $scriptAJAX;
                    }
                    
                }
                , checkCookieConsent: function () {

                    if (reg.getMode() === "userConsent") {

                        var cookieBannerCookie = Cookies.getJSON('SA_COOKIE_BANNER');
                        var gpcOverrideCookie = Cookies.getJSON('SA_GPC_COOKIE_CATEGORIES');
                        var gpcIsEnabled = navigator.globalPrivacyControl;
                        
                        // If Cookie Banner Cookie does not yet exist
                        if (cookieBannerCookie === undefined) {
                            var cookieAcceptedCategories = "all";
                            if (window.cookieAcceptedCategoriesCustom !== undefined) {
                                cookieAcceptedCategories = window.cookieAcceptedCategoriesCustom;
                            }
                            
                            if (gpcIsEnabled) {
                                // console.log('gpc enabled')
                                if (gpcOverrideCookie === undefined) {
                                    var cookieAcceptedCategories = ['essential'];
                                } else {
                                    var cookieAcceptedCategories = gpcOverrideCookie.A;
                                }                                
                            }
                            
                            // execute scripts
                            cookieConsentMgr.excecuteAcceptedCookies(cookieAcceptedCategories);

                            // show cookie banner only if GPC is not enabled
                            if (gpcIsEnabled) {
                                var cookiesAllowed = [];
                                var cookiesNotAllowed = [];
                                
                                var categories = reg.getCategories();

                                categories.forEach(category => {
                                    if(category.isEssential === true)
                                        cookiesAllowed.push(category.key);
                                    else
                                        cookiesNotAllowed.push(category.key);
                                });
        
                                cookieConsentMgr.saveCookie(cookiesAllowed, cookiesNotAllowed);

                                isAnalyticsRejected = true
                            } else {
                                cookieConsentMgr.showCookieBanner();
                            }

                        // If Cookie Banner Cookie does exist
                        } else {                            
                            // console.log(gpcIsEnabled)
                            if (gpcIsEnabled) {
                                // console.log('gpc enabled')
                                // console.log(gpcOverrideCookie);

                                if (gpcOverrideCookie === undefined) {
                                    var cookieAcceptedCategories = ['essential'];
                                    isAnalyticsRejected = true;
                                } else {
                                    var cookieAcceptedCategories = gpcOverrideCookie.A;
                                    if (!cookieAcceptedCategories.includes("analytics")) {
                                        isAnalyticsRejected = true
                                    }
                                }

                                // console.log('accepted gpc en:' + cookieAcceptedCategories);
                                // console.log(cookieAcceptedCategories.length)


                                cookieConsentMgr.excecuteAcceptedCookies(cookieAcceptedCategories);
                                // console.log('accepted:' + cookieAcceptedCategories)
                            } else {
                                var cookieAcceptedCategories = cookieBannerCookie.A;
                                cookieConsentMgr.excecuteAcceptedCookies(cookieAcceptedCategories);

                                if (!cookieAcceptedCategories.includes("analytics")) {
                                    isAnalyticsRejected = true
                                }
                                
                                // if (!gpcIsEnabled && (gpcOverrideCookie === undefined) && (cookieAcceptedCategories.join('').toLowerCase() === 'essential')) {
                                //     // Future Consideration? 
                                //     // in this case, they should have initially visited w/ GPC enabled,
                                //     // and have returned / continued browsing with it disabled,
                                //     // having not changed anything in the cookie manager
                                //     // show the cookie banner again in this case?
                                //     // !! this is essentially the same condition as if the user had previously hit 'reject all'. Although we don't want to keep showing the banner to the user in that case.

                                //     // console.log('test')
                                //     // console.log('accepted:' + cookieAcceptedCategories)

                                //     // execute scripts
                                //     cookieConsentMgr.excecuteAcceptedCookies(cookieAcceptedCategories);
                                //     // show banner ?
                                //     cookieConsentMgr.showCookieBanner();
                                // } else {
                                //     // console.log('accepted:' + cookieAcceptedCategories)
                                //     cookieConsentMgr.excecuteAcceptedCookies(cookieAcceptedCategories)
                                // }

                            }
                        }

                    } else {
                        cookieConsentMgr.excecuteAcceptedCookies('all');
                    }
                    
                }
                , getIsAnalyticsRejected: function () {
                    return isAnalyticsRejected;
                }
            }
        }
        , privacyTermsCookieInfo: function(cookieConsentRegistry) {
            var reg = cookieConsentRegistry;
            var cookieCategories = reg.categories;
            var cookieGroups = reg.groups;

            function buildCategoryInfo(name, description, key) {
              var catBlockTop = '\
                  <p><strong>'+name+' Cookies</strong></p>\
                  <p>'+description+'</p>\
              ';
              return catBlockTop;
            }

            function buildCookieGroupInfo(categoryKey) {
              var groupBlock = '';

              cookieGroups.forEach(function(item, i) {
                var groupCatKey = item.categoryKey;

                if ( groupCatKey === categoryKey ) {
                  var itemCookies = item.cookies;

                  if( itemCookies.length !== 0 ) {
                    var groupBlockA = '\
                      <div class="cookie-group-info">\
                        <p><strong>'+item.name+'</strong></p>\
                        <p>'+item.description+'</p>\
                        <p>Cookies:</p>\
                      <table>\
                        <tr>\
                          <th>NAME</th>\
                          <th>PURPOSE</th>\
                          <th>EXPIRES</th>\
                        </tr>\
                    ';
                    var groupBlockB = '';
                    var groupBlockC = '\
                      </table>\
                    </div>\
                    ';

                    for ( i = 0; i < itemCookies.length; i ++) {
                      groupBlockB += '\
                        <tr>\
                          <td data-th="NAME">'+itemCookies[i].name+'</td>\
                          <td data-th="PURPOSE">'+itemCookies[i].description+'</td>\
                          <td data-th="EXPIRES">'+itemCookies[i].expires+'</td>\
                        </tr>\
                      ';
                    }

                    groupBlock += groupBlockA + groupBlockB + groupBlockC;

                  } else {
                    groupBlock = "no cookies";
                  }
                }
              });

              return groupBlock;
            }

            var groupBlocksData = [];

            if (cookieCategories) {

                cookieCategories.forEach(function(item, i) {
                    var categBlockTop = buildCategoryInfo(item.name, item.description, item.key);
                    var categBlockInfo = buildCookieGroupInfo(item.key);
                    var categoryBlockEnd = '</div>';
                    var categBlockCombined = '';
                    if (categBlockInfo !== "no cookies") {
                        categBlockCombined = categBlockTop + categBlockInfo + categoryBlockEnd;
                    }

                    groupBlocksData.push(categBlockCombined);

                });
            }

            return {
              generateTables: function () {
                var cookieTables = '';
                groupBlocksData.forEach(function(item, i) {
                  cookieTables += item;
                });
                return cookieTables;
              }
            }


        }
    }
});

var cookieConsentRegistry = saffire.cookies.cookieRegistry(cookieMetaData);
var cookiePrivacyInfo = saffire.cookies.privacyTermsCookieInfo(cookieMetaData);
var cookieConsentMgr = saffire.cookies.cookieConsentManager(cookieConsentRegistry);

// js-cookie api
var cookies = window.Cookies;
;
