/* eslint-disable */
//////////////Page scrolling
var productViewPosition = "fixed";
var AlsoBoughtPosition = null;
var prevScrollTop = 0;
var phase = 1;
var orginalViewPosition = 75;
var XHRCount = 0;
var hashExists = false;
// Most products have static productimagery, so set this as default. Will be reassessed in ResizeItemScroller
var AlwaysStatic = false;

var selectedItemFromHash = false;

//This flag is used when the first item in the page is targetted by a hash param
var selectedFirstItemSaved = false;
var loadedItemFromHash = false;
var saveItemFromSizeOptionOnLoad = true;
var savedFromSizeParam = false;
var initialLoad = true;
var isStackedPDPPage = false;

var recentlyViewedGlobal = null;
var interactionList = [];

var _cistStoresOpen = false;
var buyNowJourney = false;
var buyNowPID = "";
var buyNowOptionNo = "";
var preventBuyNowLoop = false;
var pdpChipsEnabled = Next.Settings.Channel.PdpWithChips;
var pdpSingleColourChipsEnabled = (Next.Settings.Channel.ColourChipsOnProductPage && Next.Settings.Channel.ColourChipsOnProductPageShowSingleChip);
var pdpSplitSizeEnabled = pdpChipsEnabled && Next.Settings.Channel.PdpChipsSplitSizeEnabled;
var pdpChipsATBCtaJumpFix = Next.Settings.Channel.IsPDPChipsATBJumpFix;
var jsonLoaded = false;
var jsonInitalTry = true;
var currentItemNum = "";

var enhancedStyleWithSlider;
var PersonalisedGiftsThemeEnum = {
    RegularPersonalisedGift: 0,
    BasicModal: 1
};

ScriptsLoadedCallback = function () {
    ProductPage.Init();
};

if (typeof modalMode === "undefined") {
    modalMode = false;
}

PageVisibleCallback = function () {

    ProductImages.Positioning.Init();
    ProductPage.LoadPlugins();

    $(".pageBottomWrapper").animate({ opacity: 1 }, 300);

    if (BazaarVoiceEnabled) {
        var siteURL = window.location.protocol + "//" + window.location.host;
        var reviewPage = siteURL + "/review.asp";
        //$BV.configure("global", { submissionContainerUrl: reviewPage });
    } else {

        var hAlign = !Next.Settings.Channel.DirectionRTL ? 'left' : 'right';
        $('.ProductPage .ProductDetail .StyleMeta .ItemNumber').css('float', hAlign).css('text-align', hAlign);
    }

    ProductPage.RecentlyViewed.Init();

    checkSearchBreadcrumbs();

};

var ProductPage = {
    CistConfig: function () {
        return Next.Settings.Mobile.CollectInStore;
    },
    Init: function () {
        var _this = this;

        _this.Vars.Init();

        ProductImages.ZoomComponent.Init();
        _this.HashSelection.Init();

        var cistConfig = _this.CistConfig();
        if (cistConfig && cistConfig.Enabled) {
            _this.StoreStockSearch.CheckEligibility();
        }

        _this.Styles.Init();


        if (modalMode) {
            _this.SetModalMode();
        }

        if (!cistConfig || !cistConfig.Enabled) {
            $('a[id^="collect-in-store-link-"]').remove();
            $('span[data-cist-item="true"]').remove();
        }
        if (_this.Vars.SingleModalMode) {
            _this.HideYMALContainers();
        }

        if (Next.Settings.Channel.EnhancedStyleWithRibbonEnabled) {
            var $curStyle = ProductPage.Vars.$styles.filter(".Selected");
            var itemNumber = $curStyle.data("targetitem");
            var sizeSelector = $("select.SizeSelector#Size-" + itemNumber);
            if (sizeSelector.data("personalise") !== "Y") {
                enhancedStyleWithSlider = new EnhancedStyleWithRibbonSlider();
                enhancedStyleWithSlider.init();
            }
        }

        $(".widget_content").removeClass("widget_hidden");
        $(".br_widget_wrapper").removeClass("widget_hidden");

    },
    Vars: {
        ItemData: null,
        ProductBuyNowEligibility: null,
        DisplayConfiguration: null,
        ItemNumberToPreSelect: null,
        SingleModalMode: false,
        ShowSizeGuide: true,
        $productPage: null,
        $productImagery: null,
        $zoomComponent: null,
        $itemsContainer: null,
        $productDetail: null,
        $styles: null,
        CollectInStoreMonetateEnabled: false,
        IsBeautyPage: false,
        IsChanelBrandPDPEnabled: false,
        $backToTop: null,
        $reviewsContainer: null,
        StyleWithEnabled: false,
        CountdownTimerServiceResponse: null,
        DivSustainabilityAccordion: null,
        SustainabilityDataContainer: null,
        SustainabilityChevron: null,
        DivCareAndFabricAccordion: null,
        CareAndFabricDataContainer: null,
        CareAndFabricChevron: null,
        isPushToMonetate: false,
        PdpSingleColourChipValue: "\u00a0",
        isFitChanged: false,        
        Init: function () {
            var _this = this;           
            _this.ItemData = shotData.Styles;
            _this.DisplayConfiguration = displayConfiguration;
            _this.ProductBuyNowEligibility = productBuyNowEligibility;
            _this.$productPage = $(".ProductPage");
            _this.$productImagery = _this.$productPage.find(".ProductImagery");
            _this.$zoomComponent = _this.$productImagery.find(".ZoomComponent");
            _this.$itemsContainer = _this.$productPage.find(".itemsContainer");
            _this.$productDetail = _this.$itemsContainer.find(".ProductDetail");
            _this.$styles = _this.$productDetail.find("article.Style");
            _this.SingleModalMode = $("body").hasClass("SinglePDPModalMode");
            if (typeof $("article").attr("data-brand") != 'undefined') {
                _this.IsChanelBrandPDPEnabled = Next.Settings.Channel.IsChanelBrandPDPEnabled &&
                    Next.Settings.Channel.ChanelBrandPDPText.toLowerCase() === $("article").attr("data-brand").toLowerCase();
            }
            _this.IsBeautyPage = Next.Settings.UI.IsBeautyPDPEnabled && shotData.IsBeautyPage || _this.IsChanelBrandPDPEnabled;
            _this.ShowSizeGuide = !_this.SingleModalMode;
            _this.$backToTop = $("a.pdpBackToTop");
            _this.$reviewsContainer = $('.reviewsContainer');
            _this.StyleWithEnabled = _this.$productPage.attr("data-style-with-enabled") === "True";
            _this.isPushToMonetate = false;
            if (!_this.StyleWithEnabled) {
                _this.$productDetail.addClass("HorizontalStyleWithOff");
            }
            if (_this.IsChanelBrandPDPEnabled) {
                $("body").addClass("chanelPDP");
            }
            _this.CountdownTimerServiceResponse = shotData.CountdownTimerServiceResponse;

            if (Next.Settings.Channel.TpPdpShowSustainabilityAccordion) {
                _this.DivSustainabilityAccordion = $("#divSustainabilityAccordion");
                _this.SustainabilityChevron = _this.DivSustainabilityAccordion.find("#SustainabilityChevron");
                _this.SustainabilityDataContainer = _this.DivSustainabilityAccordion.find("#sustainabilityDataContainer");
            }

            if (Next.Settings.Channel.TpPdpShowCareAndFabricAccordion) {
                _this.DivCareAndFabricAccordion = $("#divCareAndFabricAccordion");
                _this.CareAndFabricChevron = _this.DivCareAndFabricAccordion.find("#CareAndFabricChevron");
                _this.CareAndFabricDataContainer = _this.DivCareAndFabricAccordion.find("#careAndFabricDataContainer");
            }
            isStackedPDPPage = Next.Settings.Channel.IsStackedPDPEnabled && $(".Content").hasClass("StackedPDP");

            if (pdpSingleColourChipsEnabled && _this.$styles.length == 1) {
                var singleColourChip = _this.$styles.find("ul.colourChips li");
                if (singleColourChip) {
                    _this.PdpSingleColourChipValue = singleColourChip.data('value');
                }
            }
        },
        GetParameterByName: function (name) {
            var sPageURL = window.location.hash.substring(9);
            var sURLVariables = sPageURL.split("&");
            for (var i = 0; i < sURLVariables.length; i++) {
                var sParameterName = sURLVariables[i].split("=");
                if (sParameterName.length == 2 && sParameterName[0] == name) {
                    return sParameterName[1];
                }
            }
            return null;
        },
        GetCurrentStyleElement: function () {
            return ProductPage.Vars.$styles.filter(".Selected");
        },
        GetCurrentFit: function ($currentstyle) {
            var $style = ProductPage.Vars.GetCurrentStyleElement();
            if (pdpChipsEnabled && $currentstyle) {
                $style = $currentstyle;
            }
            if ($style) {
                var styleId = $style.data("styleid");
                var style = undefined;
                $.each(ProductPage.Vars.ItemData, function () {
                    if (this.StyleID == styleId) {
                        style = this;
                        return false;
                    }
                });

                var fit;
                var FitName = $style.data("fit");
                var $fitChip = $style.find("ul.fitChips li.active");
                var splitFitName = "";
                if ($fitChip && $fitChip.length > 0) {
                    splitFitName = $fitChip.attr("data-fit");
                }
                else {
                    $fitChip = $style.find(".StyleForm select.fitList").find("option:selected");
                    splitFitName = $fitChip.val();
                    if ($style.find(".StyleForm select.fitList").hasClass("asmFitList")) {
                        splitFitName = $fitChip.data("fit");
                    }
                }

                if (pdpChipsEnabled && ProductPage.Styles.pdpChipsShow() && !FitName) {
                    if ($style.attr("data-fit")) {
                        FitName = $style.attr("data-fit");
                    }
                    else {
                        if ($fitChip.attr("data-fit")) {
                            FitName = $fitChip.attr("data-fit");
                        }
                        else {
                            FitName = $fitChip.val();
                        }
                    }
                }
                if (style != null && style.Fits != null && style.Fits.length === 1 && !FitName) {
                    fit = style.Fits[0];
                }
                else {
                    if (style != null && style.Fits != null) {
                    $.each(style.Fits, function () {
                        if (this.Name == splitFitName) {
                            fit = this;
                            return false;
                        }
                        else if (this.Name == FitName) {
                            fit = this;
                            return false;
                        }
                    });
                   }
                }
                return fit;
            }
        }
    },
    HashSelection: {
        HashChanging: false,
        Init: function () {
            var _this = this;

            _this.SelectItemFromHash();

            var isMsie = jqueryUpgradeEnabledOnPage ? navigator.userAgent.toLowerCase().indexOf('msie') > -1 : $.browser.msie;

            if (("onhashchange" in window) && !(isMsie)) {
                window.onhashchange = function () {
                    _this.SelectItemFromHash();
                };
            }
            else {
                var prevHash = window.location.hash;
                window.setInterval(function () {
                    if (window.location.hash !== prevHash) {
                        _this.SelectItemFromHash();
                        prevHash = window.location.hash;
                    }
                }, 100);
            }
        },
        CheckURLForHash: function () {
            var hashParam = window.location.hash.replace("#", "");
            var itemId;

            if (hashParam.indexOf('?i=') > -1) {
                var hashArray = hashParam.split('?i=');
                itemId = hashArray[0];

            } else {
                itemId = window.location.hash.replace("#", "");
            }

            if (itemId.length === 6) {
                itemId += book;
            }

            var formattedId = itemId.substring(0, 3) + "-" + itemId.substring(3, 6) + "-" + itemId.substring(6, 9);

            return formattedId;
        },
        CheckURLForHashWithMultipleItems: function () {
            var indexOfHash = window.location.href.indexOf("#");
            var hashParam = window.location.href.substring(indexOfHash).replace("#", "");
            itemIds = hashParam.split(new RegExp("\/|-"));
            return itemIds
        },
        SelectItemFromHash: function () {
            //Check for hash   
            if (window.location.hash !== null && window.location.hash !== "") {

                hashExists = true;

                if (Next.Settings.Channel.PDPStyleDescription.EnableURLChange) {
                    var hashItemNumbers = ProductPage.HashSelection.CheckURLForHashWithMultipleItems();

                    for (let itemNumber of hashItemNumbers) {
                        ProductPage.Styles.SelectItem(itemNumber.toUpperCase(), false, true);
                    }
                }
                else {
                    var hashItemNumber = ProductPage.HashSelection.CheckURLForHash();

                    var itemSelected = ProductPage.Styles.SelectItem(hashItemNumber.toUpperCase(), false, true);

                    if (itemSelected) {
                        loadedItemFromHash = true;
                        selectedItemFromHash = true;

                        if (ProductPage.Vars.StyleWithEnabled) {
                            if (typeof StyleWithSlider != "undefined") {
                                StyleWithSlider.handleHashChange();
                            }
                        }
                    } else {
                        ProductPage.Styles.ShowItem();
                    }
                }
            } else {
                ProductPage.Styles.ShowItem();
            }
        },
        ChangeItemHash: function (newHash) {
            window.location.hash.replace(window.location.hash, newHash);
        }
    },
    SetModalMode: function () {

        $("div.StyleContent a").each(function () {
            $(this).attr("target", "_blank");
        });

        $(".ZoomComponent .SuperZoomOpen").remove();
        $(".ZoomComponent .ShotView").unbind();
        if (ProductPage.Vars.SingleModalMode) {
            $(".view-redirect").on("click", function () {
                window.top.location = $(this).attr("href");
                return false;
            });
        }
    },
    LoadPlugins: function () {
        var $pending = $(".Pending");
        $pending.find('.AlsoBoughtCarousel').NextCarousel();
        $pending.find('.AlsoBoughtSection').NextSlideWindow();
        $pending.find('.ReviewContainer').NextSlideWindow();
        $pending.find('.compositionPop').NextHelperPopUp({ 'width': 200, 'align': 'right', 'delay': 500 });
        $pending.find('.helperPopUpProductInfo').NextHelperPopUp({ 'width': 250, 'align': 'bottom', 'delay': 500 });
        if (!Next.Settings.UI.ReskinPDP && !Next.Settings.UI.IsInnovationDesktopResponsiveEnabled) {
            $pending.find('.SizeGuideLink').NextHelperPopUp({ 'width': 105, 'align': 'bottom', 'delay': 500 });
        }
        $pending.removeClass("Pending");
    },
    Positioning: {

        ResizeItemScroller: function () {
            //<summary>
            //This function resizes page elements to allow page to scroll and set scroll positions correctly
            //In order to switch between fixed and static positioning, we need to add margins and paddings to certain elements
            //</summary>
            AlwaysStatic = false;
            var scrollTop = $(window).scrollTop();

            var lastItemImageBottom = $("#lastItemImageGrab").offset().top; //  - scrollTop;
            var shotViewBottom = $("#viewerBottom").offset().top - scrollTop;
            var productDetailHeight = ProductPage.Vars.$productDetail.height();
            var shotViewHeight = $(".ShotView").height();

            if (
                (lastItemImageBottom < shotViewBottom) //If last product image is above the bottom of the shotview, we wont need fixed positioning
                || (ProductPage.Vars.$productDetail.find("article.FirstItem").hasClass("LastItem")) //If there's only 1 item, we wont need the fixed positioning
                || (productDetailHeight < shotViewHeight)
            ) {
                ProductPage.Vars.$productImagery.addClass('Static');
                AlwaysStatic = true;
            }

            //Ie 7 and below don't handle fixed positioning well enough to implement
            //Stick to static
            ProductImages.Positioning.SetFixed();

            if (isStackedPDPPage) {
                const IsIPad = /iPad/.test(navigator.platform) || /iPad/.test(navigator.userAgent) || (navigator.platform === 'MacIntel' && navigator.maxTouchPoints > 1);
                if (IsIPad && (window.innerHeight > window.innerWidth)) {
                    AlwaysStatic = false;
                    $('.ProductPage .ProductImagery').css("top", "0");
                }
            }
            ProductImages.Positioning.ScrollElements();
        }
    },
    Styles: {
        Init: function () {
            var _this = this;
            if (pdpChipsEnabled) {
                ProductPage.Vars.$styles.each(function () {
                    //if (ProductPage.Styles.SplitSize.IsEnabled($style)) {
                    var $style = $(this);
                    var currentItemNumber = $style.data("targetitem");
                    var styleItemNo = $style.find(".StyleMeta .ItemNumber");
                    if (styleItemNo && styleItemNo.text() != currentItemNumber) {
                        $style.data("targetitem", styleItemNo.text());
                        $style.attr("data-targetitem", styleItemNo.text());
                        var itemHdn = $style.find("input.hdnItmId");
                        if (itemHdn.length) {
                            itemHdn.val(styleItemNo.text());
                        }
                    }
                    //}
                });
            }


            _this.AttachEvents.Init();
            _this.LoadInitialItemOptions();
            _this.Reviews.Init();

            if (Next.Settings.Channel.EnableEmbeddedReviews && !Next.Settings.Channel.DisableEmbeddedReviewsOnLocalLang) {
                _this.EmbeddedReviews.Init();
            }
            if (!preventBuyNowLoop) {
                isRedirectFromAccountPortal = ProductPage.Vars.GetParameterByName('buyNowJourney') === "true";
            }
            if (isRedirectFromAccountPortal) {
                if (AmIEligibleForThisItem) {
                    buyNowOptionNo = ProductPage.Vars.GetParameterByName('optionNo');
                    buyNowPID = ProductPage.Vars.GetParameterByName('pID');
                    $("select#Size-" + buyNowPID).val(buyNowOptionNo);
                    var specificArticle = $("article[data-targetitem=" + buyNowPID + "]");
                    preventBuyNowLoop = true;
                    var $buyNowButton = specificArticle.find("a[nxtray-id=buyNowTray]");
                    $buyNowButton.click();
                } else {
                    var buyNowNotEligibleBanner = ".buy-now-not-eligible-banner";
                    $(buyNowNotEligibleBanner).appendTo($("header.PageHeader")).removeClass("hide");

                    //register exit of banner behaviour
                    $(".buy-now-exit").on("click", function () {
                        var $parentBanner = $(this).closest(buyNowNotEligibleBanner);
                        $parentBanner.fadeOut();
                    });
                }
            }
            if (Next.Settings.Channel.DynamicDivEnabled) {
                //Load DynamicDiv if enabled
                ProductPage.Styles.LoadContentForDynamicDiv(ProductPage.Vars.$styles.filter(".Selected"));
            }
        },
        UpdateTitle: function ($style, title) {
            $style.find(".StyleCopy .Title h1").text(title);
        },
        //SelectOption: function (itemNumber, optionNumber) {
        //    var sizeSelector = $("select.SizeSelector#Size-" + itemNumber);
        //    if (optionNumber) {
        //        sizeSelector.dropkick("setValue", optionNumber);
        //    } else {
        //        var previousSelectedSize = this.GetUrlParameter("i");
        //        if (previousSelectedSize) {
        //            previousSelectedSize = previousSelectedSize.replace(/\s/g, '').toLowerCase();
        //            var optionElement = sizeSelector.children("option").filter(function () {
        //                var $optElem = $(this);
        //                return $optElem.val() && $optElem.text().replace(/\s/g, '').toLowerCase().indexOf(previousSelectedSize) > -1;
        //            });

        //            sizeSelector.dropkick("setValue", optionElement.val());
        //        }
        //    }
        //},
        //GetUrlParameter: function (name) {
        //    var regex = new RegExp('[\\?&]' + name + '=([^&#]*)');
        //    var results = regex.exec(location.href);
        //    return results === null ? '' : decodeURIComponent(results[1]);
        //},
        AttachEvents: {
            Init: function () {                
                this.ImageClick();               
                this.ToggleDescription();
                this.OpenDescription();
                if (Next.Settings.Channel.PdpChipsSplitSizeEnabled) {
                    this.SetASMGenderCategoriesEnabled();
                    this.SetUnavailableFitChip();
                }
                this.FitChange();
                this.ColourChange();
                this.ColourDropdownClick();
                if (ProductPage.Vars.IsBeautyPage) {
                    this.ColourChipChange();
                }
                if (!pdpSplitSizeEnabled) {
                    this.SplitSizeChipChange();
                }
                if (!ProductPage.Vars.StyleWithEnabled && !Next.Settings.Channel.IsStackedPDPEnabled) {
                    this.StyleHeader();
                }
                this.NotifyMeHelp();
                this.CistHelp();
                this.BuyNowHelp();
                this.FindOutMore();
                this.PriceHistory();
                this.TrackPDPGAEvents();
                if (Next.Settings.UI.DesktopQtySelectorEnabled) {
                    this.QtyChange();
                }
                this.FitChipClick();
                this.ColourChipClick();
                if (!pdpChipsEnabled) {
                    this.ColourChipHover();
                }
                this.SizeChipClick();
                if (Next.Settings.Channel.IsStackedPDPEnabled && !ProductPage.Vars.StyleWithEnabled) {
                    this.StackedPDPViewDetailLinkClick();
                }
                this.SizeDropDownClick();
                //this.BandSizeClick();
                //this.CupSizeClick();
                if (pdpChipsEnabled && ProductPage.Styles.SplitSize.IsEnabled()) {
                    this.PDPSplitSizeClick();
                }
                else {
                    this.BandSizeClick();
                    this.CupSizeClick();
                }
                if (pdpSplitSizeEnabled) {
                    this.SplitSizeDropDownChange();
                }
                this.WhatsAppButtonClick();
                this.CallUsButtonClick();
                if (pdpChipsEnabled && ProductPage.Styles.pdpChipsShow()) {
                    this.initialControlsReset();
                }
                if (Next.Settings.Channel.TpPdpShowSustainabilityAccordion) {
                    this.ToggleSustainabilityAccordion();
                }
                if (Next.Settings.Channel.TpPdpShowCareAndFabricAccordion) {
                    this.ToggleCareAndFabricAccordion();
                }
                if (ProductPage.Vars.IsChanelBrandPDPEnabled) {
                    this.ChanelBrandLogoClick();
                }
                $(window).resize(function () {
                    if (isStackedPDPPage) {
                        const IsIPad = /iPad/.test(navigator.platform) || /iPad/.test(navigator.userAgent) || (navigator.platform === 'MacIntel' && navigator.maxTouchPoints > 1);
                        if (IsIPad && (window.innerHeight > window.innerWidth)) {
                            AlwaysStatic = false;
                            $('.ProductPage .ProductImagery').css("top", "0");
                        }
                        else {
                            $('.ProductPage .ProductImagery').css("top", "130px");
                        }
                    }
                });
                if (Next.Settings.Channel.DynamicDivEnabled &&
                    Next.Settings.Channel.Promotions.GWP) {
                    this.OffersAvailableScrolldown();
                }

                if (Next.Settings.Channel.Coords.Enabled && $("#pdpnav").length && Next.Settings.Channel.EnablePersistColourAcrossTabs) {
                    var $style = ProductPage.Vars.$styles.filter(".Selected");
                    if ($(".pdp-tab.active a").attr("data-styleid") === $(".pdp-tab >.tabLabel > a").attr("data-styleid")) {
                        $(".pdp-tab .tabLabel a").attr("colour", $style.find(".colourList .dk_label").text() ? $style.find(".colourList .dk_label").text() : $style.find(".colourChipNameLabel").text());
                    }
                }
            },
            ImageClick: function () {
                var scrollItems = StyleWithScroll ? ProductPage.Vars.$styles.filter(".Grouped") : ProductPage.Vars.$styles;
                scrollItems.find("section.StyleImages a, .StyleHeader a, .Reviews").click(function (e) {
                    e.preventDefault();

                    var $this = $(this);

                    var $style = $this.parents("article.Style");

                    $(".Style.Selected").removeClass("Selected");
                    $style.addClass("Selected");

                    var isReviewRatingClick = $this.attr("class") === "Reviews";

                    // Only scroll to item when not a review rating click
                    if (!isReviewRatingClick) {
                        ProductPage.Styles.ShowItem(false);
                    }
                });

                scrollItems.find(".StyleHeader a").on("touchstart", function () { $(this).addClass("noTouch") });

            },
            OpenDescription: function () {
                if (Next.Settings.Channel.EnablePDPDescriptionSpotFix && !Next.Settings.Channel.PDPModernisedPartialDescription) {
                    return;
                }
                
                if (Next.Settings.Channel.EnablePartialDescription) {
                    ProductPage.Vars.$styles.find('.StyleContent').each(function () {
                        var descriptionElement = $(this);

                        var modernisedReadMore = Next.Settings.Channel.PDPModernisedPartialDescription;

                        if (!modernisedReadMore) {
                            if (descriptionElement.hasClass('partial-description')) {
                                // Hide description to avoid UI glitches
                                // descriptionElement.hide(); 
                                

                                descriptionElement.find('.partial-description-text').first().css('display', 'none');

                                // IE fix: DOM elements don't update immediately, so we need to push
                                // this to the end of the event loop

                                setTimeout(function () {                                    
                                    var currentDescription = new ProductDescription($(descriptionElement),
                                        Next.Settings.UI.EnableNextGel3Styling ? 3.25 : 2.5, null, ProductPage.Vars.IsChanelBrandPDPEnabled, TrackGAEvent);
                                    currentDescription.transformToPartial();

                                    if (ProductPage.Vars.IsChanelBrandPDPEnabled) {
                                        currentDescription.openDescription();
                                    }
                                    descriptionElement.show();

                                }, 0);
                                descriptionElement.find('.partial-description-text').first().css('display', 'block');

                            }
                        }
                        else {
                            if (descriptionElement.hasClass('modernised-partial-description')) {
                                // IE fix: DOM elements don't update immediately, so we need to push
                                // this to the end of the event loop
                                setTimeout(function () {                                    
                                    var currentDescription = new ProductDescription($(descriptionElement),
                                        Next.Settings.UI.EnableNextGel3Styling ? 3.25 : 2.5, null, ProductPage.Vars.IsChanelBrandPDPEnabled, TrackGAEvent);
                                    currentDescription.transformToPartial();

                                    if (ProductPage.Vars.IsChanelBrandPDPEnabled) {
                                        currentDescription.openDescription();
                                    }
                                    descriptionElement.show();

                                }, 0);
                            }
                        }
                    });
                }

                ProductPage.Vars.$styles.filter(".Grouped").find("section.StyleCopy").each(function () {
                    var $item = $(this).find(".StyleContent");
                    if (!Next.Settings.UI.ReskinPDP && !Next.Settings.UI.IsInnovationDesktopResponsiveEnabled) {
                        var $styleHeader = $(this).find(".StyleHeader");
                        var $showmore = $(this).find(".showmore");
                        var $showless = $(this).find(".showless");
                        if ($item.height() > 200 && ProductPage.Vars.$styles.length > 1) {
                            $item.addClass("closed");
                            $item.addClass("readmoreStyle");
                            $showmore.removeClass("hidden");
                            if (!ProductPage.Vars.StyleWithEnabled) {
                                $styleHeader.height($(this).find("h1").height());
                            }

                            $showmore.click(function () {
                                $item.removeClass("closed");
                                $showmore.addClass("hidden");
                                $showless.removeClass("hidden");
                            });
                            $showless.click(function () {
                                $item.addClass("closed");
                                $showless.addClass("hidden");
                                $showmore.removeClass("hidden");
                            });
                        }
                    }
                    // $item.addClass("loaded");

                });
            },
            ToggleDescription: function () {
                ProductPage.Vars.$styles.find("section.StyleCopy .toggleDescription").click(function () {
                    var $el = $(this);
                    var $link = $el.find("a");
                    $link.text() === $link.data("text-open") ? $link.text($link.data("text-closed")) : $link.text($link.data("text-open"));
                    var $arrow = $el.find(".arrow");
                    $arrow.toggleClass("open");
                    if (Next.Settings.UI.ReskinPDP || Next.Settings.UI.IsInnovationDesktopResponsiveEnabled) {
                        $el.toggleClass("opened");
                    }
                    $el.next().toggle();
                    ProductImages.Positioning.ScrollElements();
                    if (Next.Settings.Channel.ExpandDescriptionOnProductPage && $el.hasClass("expandedDescription")) {
                        var department = "";
                        if (dataLayer && dataLayer.length > 0) {
                            for (var j = 0; j < dataLayer.length; j++) {
                                if (dataLayer[j].department != undefined) {
                                    department = dataLayer[j].department + "-";
                                    break;
                                }
                            }
                        }
                        TrackGAEvent("PDP", "tap", department + "pdp-description-panel-expanded-collapsed");
                        $el.removeClass("expandedDescription");
                    } else {
                        TrackGAEvent("PDP", "tap", "pdp-description-panel-" + ($arrow.hasClass("open") ? "expanded" : "collapsed"));
                    }
                });

                ProductPage.Vars.$styles.find("section.StyleCopy .toggleDescription a").on("touchstart", function () { $(this).addClass("noTouch") });

            },
            FitChange: function () {
                //<summary>Fit Dropdown - Change Event</summary>
                var $fitList = ProductPage.Vars.$itemsContainer.find("select.fitList");
                $fitList.change(function () {
                    var $this = $(this);
                    ProductPage.Vars.isFitChanged = true;
                    ProductPage.Vars.isPushToMonetate = false;
                    ProductPage.Styles.FitChanged($this);
                    ProductPage.Styles.TrackGASelectionChanged("fit", $this);

                    if (Next.Settings.Channel.Coords.Enabled && $("#pdpnav").length && Next.Settings.Channel.EnablePersistColourAcrossTabs) {
                        var $style = ProductPage.Vars.$styles.filter(".Selected");
                        if ($(".pdp-tab.active a").attr("data-styleid") !== $(".pdp-tab >.tabLabel > a").attr("data-styleid")) {
                            $(".pdp-tab >.tabLabel > a").attr("colourwayFlag", true);
                        }
                        else {
                            if ($(".pdp-tab >.tabLabel > a").attr("colourwayFlag") !== "true") {
                                $(".pdp-tab .tabLabel a").attr("colour", $style.find(".colourList .dk_label").text() ? $style.find(".colourList .dk_label").text() : $style.find(".colourChipNameLabel").text());
                            }
                        }
                    }
                });
            },

            SetASMGenderCategoriesEnabled: function () {
                var genderCategories = Next.Settings.Channel.ASMEnabledGenderCategories;
                var $style = ProductPage.Vars.$styles.filter(".Selected");
                var gender = $style.data("gender");
                var category = $style.data("category");

                if (genderCategories !== null) {
                    let isASMGenderCategoriesEnabled = !!(genderCategories.find(genderCategories => (genderCategories.Gender !== null && genderCategories.Gender == gender || genderCategories.Gender === "*") &&
                        genderCategories.Category.find(categoryName => categoryName !== null && categoryName.toLowerCase() === category.toLowerCase() || categoryName === "*")));
                    pdpSplitSizeEnabled = pdpSplitSizeEnabled && isASMGenderCategoriesEnabled;
                }
            },
            SetUnavailableFitChip: function () {
                var valueFit = false;
                var $style = ProductPage.Vars.$styles.filter(".Selected");
                var $fitList = ProductPage.Vars.$itemsContainer.find("ul.fitChips li");
                var $colourList = ProductPage.Vars.$itemsContainer.find("select.colourList");
                var itemNumber = $style.data("targetitem");
                var $itemData = shotData.Styles[0].Fits;
                var currentColour;
                var $colourSelect = $style.find("select.colourList");
                var $colourChips =  $style.find("ul.colourChips");
                var colorChipsEnabled = $style.find("ul.colourChips").val()
                    && $style.find("ul.colourChips").css("display") != "none";
                if (colorChipsEnabled) {
                    currentColour = $colourChips.find("li.active").data("value");
                }
                else {
                    currentColour = $colourSelect.find("option:selected").text();
                }
                if (pdpSplitSizeEnabled) {
                    $fitList.each(function () {
                        valueFit = false;
                        valueData = true;
                        var dataValue = $(this).data("value");
                        var dataFit = $(this).data("fit");
                        $.each(ProductPage.Vars.ItemData, function (iStyle, style) {
                            if (style.StyleID === $style.data("styleid")) {
                                $.each(style.Fits, function (iFit, fit) {
                                    $.each(fit.Items, function (iItem, item) {
                                        if (item.Colour === currentColour) {
                                            if (fit.Name == dataFit) {
                                                valueData = true;
                                            }
                                            else {
                                                valueData = false;
                                            }
                                            valueFit = item.Options.includes(item.Options.find(x => x.FitSizes[0].Value == dataValue));
                                        }
                                        if (valueFit) {
                                            return false;
                                        }
                                    });
                                    if (valueFit) {
                                        return false;
                                    }
                                });

                            }
                            if (valueFit) {
                                return false;
                            }
                        });
                        if (!valueFit && valueData) {
                            $(this).addClass("unavailable");
                        }
                        else {
                            $(this).removeClass("unavailable");
                        }
                    })
                    if ($(".fitChips").find("li.chipItem.active").hasClass("unavailable")) {
                        this.updateSplitFit($style);
                    }
                }
            },
            FitChipClick: function () {
                //<summary>Fit Chip - Change Event</summary>

                var $fitList = ProductPage.Vars.$itemsContainer.find("ul.fitChips li");
                $fitList.click(function () {
                    var $this = $(this);
                    ProductPage.Vars.isFitChanged = true;
                    if (!$this.hasClass("active")) {
                        ProductPage.Vars.isPushToMonetate = false;
                        ProductPage.Styles.FitChanged($this);
                        ProductPage.Styles.TrackGAChipSelection("fit", $this);
                    }

                    if (Next.Settings.Channel.Coords.Enabled && $("#pdpnav").length && Next.Settings.Channel.EnablePersistColourAcrossTabs) {
                        var $style = ProductPage.Vars.$styles.filter(".Selected");
                        if ($(".pdp-tab.active a").attr("data-styleid") !== $(".pdp-tab >.tabLabel > a").attr("data-styleid")) {
                            $(".pdp-tab >.tabLabel > a").attr("colourwayFlag", true);
                        }
                        else {
                            if ($(".pdp-tab >.tabLabel > a").attr("colourwayFlag") !== "true") {
                                $(".pdp-tab .tabLabel a").attr("colour", $style.find(".colourList .dk_label").text() ? $style.find(".colourList .dk_label").text() : $style.find(".colourChipNameLabel").text());
                            }
                        }
                    }

                    ProductPage.Styles.AttachEvents.SplitSizeChipChange();
                });
            },
            ColourChipClick: function () {
                $("body").delegate("ul.colourChips li", "click", function () {
                    var $this = $(this);
                    if (Next.Settings.Channel.PDPH1TitleColourAppend)
                        var productTitle = $(this).closest('.StyleCopy').find('#productTitleWithoutColour').attr('value');
                    ProductPage.Vars.isPushToMonetate = false;
                    if (!$this.hasClass("active")) {
                        var $style = $this.parents("article.Style");
                        //Set selected colour name in label
                        var $label = $this
                            .parents("div.colourChipsContainer")
                            .children("span.colourChipNameLabel").first();
                        $label.text($this.data("value"));
                        var itemNumber = $this.data("itemnumber");
                        var previousItemNumber = $style.data("targetitem");
                        var styleItemNo = $style.find(".StyleMeta .ItemNumber");
                        //#region Make call to ProductAggregator API to update item details of new FIT which is selected.
                        if (Next.Settings.Channel.EnableProductAggregator) {
                            ProductPage.GetShotForSingleItem(false, 3, itemNumber);
                            currentItemNum = itemNumber;
                        }
                        // #endregion
                        if (Next.Settings.Channel.PDPH1TitleColourAppend) {
                            var colourVariant = $(this).closest(".colourChipsContainer").children(".colourChipNameLabel").text();
                            var titleElement = $(this).closest(".StyleCopy").find(".Title");
                            var parentElement = $(this).closest(".StyleCopy");
                        }

                        if (Next.Settings.Channel.Coords.Enabled && $("#pdpnav").length && Next.Settings.Channel.EnablePersistColourAcrossTabs) {
                            if ($(".pdp-tab.active a").attr("data-styleid") !== $(".pdp-tab >.tabLabel > a").attr("data-styleid")) {
                                $(".pdp-tab >.tabLabel > a").attr("colourwayFlag", true);
                            }
                            else {
                                if ($(".pdp-tab >.tabLabel > a").attr("colourwayFlag") !== "true") {
                                    $(".pdp-tab .tabLabel a").attr("colour", $style.find(".colourList .dk_label").text() ? $style.find(".colourList .dk_label").text() : $style.find(".colourChipNameLabel").text());
                                }
                            }
                        }
                        if (pdpChipsEnabled && styleItemNo) {
                            if (ProductPage.Styles.SplitSize.IsEnabled($style) || styleItemNo.text() != previousItemNumber) {
                                previousItemNumber = styleItemNo.text();
                            }
                        }
                        $style.data("targetitem", itemNumber);
                        $(".Style.Selected").removeClass("Selected");
                        $style.addClass("Selected");
                        $this.addClass("active").siblings().removeClass("active");
                        ProductPage.Styles.ItemChanged(previousItemNumber, false);
                        if (pdpChipsEnabled && ProductPage.Styles.SplitSize.SplitFitEnabled()) {
                            var ItmNo = $style.find("ul.colourChips li.active").data("itemnumber");
                            var CurrFit = $(".fitChips").find("li.chipItem.active").data("value");
                            if (!CurrFit) {
                                CurrFit = $style.find(".StyleForm select.fitList").val();
                            }
                            var CurrFitSplitSizeContainer = $style.find("div.Chips.splitSizeContainer[for=Size-" + ItmNo + "]");
                            if (CurrFitSplitSizeContainer.length > 0) {
                                Array.prototype.forEach.call(CurrFitSplitSizeContainer[0].children, function (child, index) {
                                    var ItemFit = child.dataset.fit;
                                    if (CurrFit) {
                                        if (ItemFit === CurrFit) {
                                            child.style.display = "inline";
                                        }
                                        else {
                                            child.style.display = "none";
                                        }
                                    }
                                });
                            }

                        }
                        ProductPage.Styles.TrackGAChipSelection("colour", $this);

                        //Set selected value in dropdown. This dropdown is hidden.
                        //Setting just to keep same value in both, dropdown and colour chips
                        var $styleForm = $(this).closest(".StyleForm");
                        $styleForm.find("select.colourList option").each(function () {
                            if ($(this).attr("value") === itemNumber) {
                                $(this).prop('selected', true);
                                $(this).attr('selected', 'selected');
                            }
                            else {
                                $(this).removeProp("selected");
                                $(this).removeAttr("selected");
                            }
                        })
                        $styleForm.find("select.colourList").dropkick("setValue", itemNumber);
                        if (Next.Settings.Channel.PDPH1TitleColourAppend) {
                            if (parentElement.find(".Title h1").length > 0)
                                titleElement.find('h1').text(colourVariant + ' ' + productTitle);
                            else if (parentElement.find(".Title h2").length > 0)
                                titleElement.find('a').text(colourVariant + ' ' + productTitle);
                        }
                    }
                    if (pdpChipsEnabled && ProductPage.Styles.SplitSize.IsEnabled($style)) {
                        ProductPage.Styles.AttachEvents.SplitSizeChipChange($style);
                    }
                })
            },
            initialControlsReset: function () {
                var $style = ProductPage.Vars.$styles.filter(".Selected");
                var itemNumber = $style.data("targetitem");
                var sizeSelector = $("select.SizeSelector#Size-" + itemNumber);
                var sizeChips = $("div.sizeChipsContainer#Size-" + itemNumber).find("li.chipItem.active").data("value");
                if (sizeSelector.val() != sizeChips && ProductPage.Styles.SizeChipsEnabled(itemNumber)) {
                    sizeSelector.val("");
                }

                var colourSelector = $style.find("select.colourList");
                var colourChips = $style.find("ul.colourChips li.active").data("itemnumber");
                var $label = $style.find(".colourChipNameLabel");

                if (Next.Settings.Channel.Coords.Enabled && $("#pdpnav").length && Next.Settings.Channel.EnablePersistColourAcrossTabs) {
                    if ($(".pdp-tab.active a").attr("data-styleid") === $(".pdp-tab >.tabLabel > a").attr("data-styleid")) {
                        $(".pdp-tab .tabLabel a").attr("colour", $style.find(".colourList .dk_label").text() ? $style.find(".colourList .dk_label").text() : $style.find(".colourChipNameLabel").text());
                    }
                }

                //To update color selection when data target item number is different from color list item number on page init
                if (pdpSplitSizeEnabled && ProductPage.Styles.SplitSize.IsEnabled($style) && $style.find("ul.colourChips").length > 0 && colourChips != itemNumber) {
                    this.updateSplitFit($style);
                }
                if (colourSelector.val() != colourChips && typeof selection != 'undefined') {
                    colourSelector.val(colourChips);
                    colourSelector.dropkick("setValue", colourChips);
                    colourSelector = $("div.sizeChipsContainer#Size-" + itemNumber).find("li.chipItem.active");
                    if (selection != null && typeof selection != 'undefined') {
                        $label.text(selection.item.Colour);
                    }
                }
            },
            updateSplitFit: function ($style) {
                var activeFit;
                var itemNumber = $style.data("targetitem");
                $style.find("ul.fitChips li").removeClass("active");
                var $itemData = ProductPage.Styles.GetPageDataForItem(itemNumber);
                var fitList = [];
                var z = $itemData.item.Options;
                var fitName = $itemData.fit.Name;
                if (pdpSplitSizeEnabled) {
                    $.each(z, function (i, opt) {
                        if (opt.FitSizes) {
                            $.each(opt.FitSizes, function (i, ftSize) {
                                if (fitList.indexOf(ftSize.Value) == -1) {
                                    fitList.push(ftSize.Value);
                                }
                            });
                        }
                        else if (fitName) {
                            fitList.push(fitName);
                        }
                    });
                    if (fitList) {
                        if (fitList.includes("Regular")) {
                            activeFit = "Regular";
                        }
                        else {
                            activeFit = fitList[0];
                        }
                    }
                    var $fit = $style.find("ul.fitChips li[data-value=" + activeFit + "]");
                    ProductPage.Styles.FitChanged($fit, itemNumber, false);
                }
            },
            ColourChipHover: function () {
                $("body").delegate("ul.colourChips li", "mouseover mouseout", function () {
                    $(this).toggleClass("hover");
                });
            },
            SizeChipClick: function () {
                $("body").delegate("ul.sizeChips li", "click", function () {
                    var $clickedChip = $(this);
                    if (!$clickedChip.hasClass("active")) {
                        $clickedChip.addClass("active").siblings().removeClass("active")
                        var $style = $clickedChip.parents("article.Style"); // ProductPage.Vars.$styles.filter(".Selected");
                        var itemNumber = $style.data("targetitem");
                        var chipText = $(this).data("size");
                        var $sizeSelector = $style.find("select#Size-" + itemNumber);

                        if (Next.Settings.Channel.SizeChipsOnProductPage && Next.Settings.Channel.DisplaySingleSizePrice) {
                            var $priceLabel = $style.find('.Price span');
                            var price = $clickedChip.data('price');
                            $priceLabel.text(Next.Settings.Channel.CurrencySymbol + price);
                        }

                        var $availabilityLabel = $(this)
                            .parents("div.sizeChipsContainer")
                            .children("div.availabilityMessage").first();
                        $availabilityLabel.text("");

                        var stockMessage = !($(this).data("stockmessage")) ? $(this).attr("data-stockmessage") : $(this).data("stockmessage");
                        var $label = $(this)
                            .parents("div.Chips.formControls")
                            .find("div.sizeAvailability").first();
                        if (pdpChipsATBCtaJumpFix) { $label.removeClass("availabilityMessage"); }

                        if (ProductPage.Styles.SizeChipsEnabled(itemNumber)) {
                            if (pdpChipsATBCtaJumpFix) {
                                if ($clickedChip.hasClass("InStock")) {
                                    $label.addClass("InStock");
                                }
                                else {
                                    $label.removeClass("InStock");
                                }
                            }
                            else {
                                var $pdpChipPricelabel = $(this)
                                    .parents("div.sizeChipsContainer")
                                    .children("div.pdpChipPrice").first();
                                $pdpChipPricelabel.text($(this).data("priceformatted"));
                            }
                            if ($clickedChip.hasClass("LowStock")) {
                                $label.addClass("LowStock");
                            }
                            else {
                                $label.removeClass("LowStock");
                            }
                            if ($clickedChip.hasClass("Delayed")) {
                                $label.addClass("Delayed");
                            }
                            else {
                                $label.removeClass("Delayed");
                            }
                            if ($clickedChip.hasClass("SaleSoldOut")) {
                                $label.addClass("SaleSoldOut");
                            }
                            else {
                                $label.removeClass("SaleSoldOut");
                            }
                        }
                        if ($clickedChip.hasClass("SoldOut")) {
                            $label.addClass("SoldOut");
                        }
                        else {
                            $label.removeClass("SoldOut");
                        }
                        if (pdpChipsATBCtaJumpFix) {
                            var formattedPrice = $(this).data("priceformatted") && $(this).data("priceformatted") !== " " ? $(this).data("priceformatted") + " - " : "";
                            $label.text(formattedPrice + stockMessage)
                        } else {
                            $label.text(stockMessage);
                        }

                        $style.data("targetitem", itemNumber);
                        $(".Style.Selected").removeClass("Selected");
                        $style.addClass("Selected");

                        //Set selected value in dropdown. This dropdown is hidden.
                        //Setting just to keep same value in both, dropdown and size chips
                        $sizeSelector.find("option").each(function () {
                            if ($(this).text() == chipText) {
                                $sizeSelector.dropkick("setValue", $(this).attr("value"));
                            }
                            else if ($(this).text().substr(0, $(this).text().indexOf(' - ')).trim() == chipText) {
                                $sizeSelector.dropkick("setValue", $(this).attr("value"));
                            }
                            else {

                                if (!jqueryUpgradeEnabledOnPage) {
                                    $(this).removeProp("selected");
                                }
                                else {
                                    $(this).removeAttr("selected");
                                }

                            }
                        })
                    }
                })
            },
            SizeDropDownClick: function () {
                var $sizeList = ProductPage.Vars.$itemsContainer.find("select.SizeSelector");
                var $sizeContainer = $sizeList.closest(".dk_container")

                $sizeContainer.click(function () {
                    if (dataLayer != null) {
                        dataLayer.push({
                            event: 'TrackGAEvent',
                            link_category: 'pdp',
                            link_id: 'Dropdown',
                            link_name: 'Size open',
                            link_value: ''
                        })
                    }
                });
            },
            PDPSplitSizeClick: function () {
                var $pdpsplitSize = ProductPage.Vars.$itemsContainer.find("ul.splitSizeChips li.splitSizeChip");

                $pdpsplitSize.click(function () {
                    if (dataLayer != null) {
                        dataLayer.push({
                            event: "PDPSplitSizeSelectorOptions",
                            PDPSplitSize: this.innerText
                        });
                    }
                });
            },
            BandSizeClick: function () {
                var $splitSize = ProductPage.Vars.$itemsContainer.find("ul.splitSizeChips[for='Band'] li.splitSizeChip");

                $splitSize.click(function () {
                    if (dataLayer != null) {
                        dataLayer.push({
                            event: "braSelectorOptions",
                            BandSize: this.innerText
                        });
                    }
                });
            },
            CupSizeClick: function () {
                var $splitSize = ProductPage.Vars.$itemsContainer.find("ul.splitSizeChips[for='Cup'] li.splitSizeChip");

                $splitSize.click(function () {
                    if (dataLayer != null) {
                        dataLayer.push({
                            event: "braSelectorOptions",
                            BandSize: this.innerText
                        });
                    }
                });
            },
            WhatsAppButtonClick: function () {
                if (Next.Settings.Channel.PdpContactUsHTMLIdentifier.Enabled) {
                    var $whatsappButton = $('.btn.btn-contact-us.whatsapp-button');

                    if ($whatsappButton) {
                        $whatsappButton.click(function () {
                            if (dataLayer != null) {
                                dataLayer.push({
                                    event: "TrackGAEvent",
                                    link_category: 'pdp',
                                    link_id: 'tap',
                                    link_name: 'pdp-whatsapp-message-us',
                                    link_value: ''
                                });
                            }
                        });
                    }
                }
            },
            CallUsButtonClick: function () {
                if (Next.Settings.Channel.PdpContactUsHTMLIdentifier.Enabled) {
                    var $callUsButton = $('.btn.btn-contact-us.call-button');

                    if ($callUsButton) {
                        $callUsButton.click(function () {
                            if (dataLayer != null) {
                                dataLayer.push({
                                    event: "TrackGAEvent",
                                    link_category: 'pdp',
                                    link_id: 'tap',
                                    link_name: 'pdp-call-us',
                                    link_value: ''
                                });
                            }
                        });
                    }
                }
            },
            StackedPDPViewDetailLinkClick: function () {
                var $stackedPdpDetailLink = ProductPage.Vars.$productDetail.find(".spdp-viewfulldetails-link");
                $stackedPdpDetailLink.click(function () {
                    var $currentArticle = $(event.target).closest("article");
                    var styleId = $currentArticle.attr("data-styleid");
                    var itemNo = $currentArticle.attr("data-targetitem").replace("-", "");
                    var styleNumber = $currentArticle.attr("data-stylenumber");
                    var filteredItems = $.grep(shotData.Styles, function (st, i) {
                        return st.StyleID == styleId;
                    });
                    var bestShotURL = filteredItems[0].ShotUrl;
                    if (bestShotURL === null || bestShotURL.trim() === "") {
                        return;
                    }
                    else {
                        var urlPathSegments = ModularPDPHelper.getSegmentOptions(bestShotURL);
                        if (bestShotURL.includes("style")) {
                            window.location.href = window.location.origin + "/style/" + styleNumber + "/" + itemNo + "#" + itemNo;
                        } else {
                            var splitValue = urlPathSegments.segments.length < 2 ? "#" : "/";
                            window.location.href = window.location.origin + "/" + bestShotURL.split(splitValue)[0] + "/" + itemNo + "#" + itemNo;
                        }
                    }
                });
            },
            ColourChange: function () {

                var $colourList = ProductPage.Vars.$itemsContainer.find("select.colourList");
                $colourList.change(function () {
                    var $ddl = $(this);
                    ProductPage.Vars.isPushToMonetate = false;
                    var $style = $ddl.parents("article.Style");
                    var itemNo = $ddl.val();
                    if (Next.Settings.Channel.PDPH1TitleColourAppend)
                        var productTitle = $(this).closest('.StyleCopy').find('#productTitleWithoutColour').attr('value');
                    //#region Make call to ProductAggregator API to update item details of new colour which is selected.
                    if (Next.Settings.Channel.EnableProductAggregator && currentItemNum != itemNo) {
                        ProductPage.GetShotForSingleItem(false, 3, itemNo);
                    }
                    var previousItemNumber = $style.data("targetitem");
                    $style.attr("data-targetitem", itemNo);
                    $style.data("targetitem", itemNo);
                    var styleItemNo = $style.find(".StyleMeta .ItemNumber");
                    if (Next.Settings.Channel.PDPH1TitleColourAppend) {
                        var colourVariant = $(this).find(':selected').text();
                        var titleElement = $(this).closest(".StyleCopy").find(".Title");
                        var parentElement = $(this).closest(".StyleCopy");
                    }
                    if (pdpChipsEnabled && styleItemNo) {
                        if (ProductPage.Styles.SplitSize.IsEnabled($style) || styleItemNo.text() != previousItemNumber) {
                            previousItemNumber = styleItemNo.text();
                        }
                    }

                    $(".Style.Selected").removeClass("Selected");
                    $style.addClass("Selected");
                    if (!pdpChipsEnabled || isStackedPDPPage) {
                        ProductPage.Styles.ItemChanged(previousItemNumber);
                        ProductPage.Styles.TrackGASelectionChanged("colour", $ddl);
                    }
                    else {
                        if (!$colourList.is(":hidden") || Next.Settings.Channel.EnableProductAggregator) {
                            ProductPage.Styles.ItemChanged(previousItemNumber);
                        }
                        ProductPage.Styles.TrackGASelectionChanged("colour", $ddl);
                    }
                    if (pdpSplitSizeEnabled && ProductPage.Styles.SplitSize.IsEnabled($style)) {
                        if ($style.find("ul.fitChips li").length > 0) {
                            ProductPage.Styles.AttachEvents.SetUnavailableFitChip();
                        }
                    }
                    if (pdpChipsEnabled && ProductPage.Styles.SplitSize.SplitFitEnabled()) {
                        var CurrFit = $(".fitChips").find("li.chipItem.active").data("value");
                        if (!CurrFit) {
                            CurrFit = $style.find(".StyleForm select.fitList").val();
                        }
                        var CurrFitSplitSizeContainer = $style.find("div.Chips.splitSizeContainer[for=Size-" + itemNo + "]");
                        if (CurrFitSplitSizeContainer.length > 0) {
                            Array.prototype.forEach.call(CurrFitSplitSizeContainer[0].children, function (child, index) {
                                var ItemFit = child.dataset.fit;
                                if (CurrFit) {
                                    if (ItemFit === CurrFit) {
                                        child.style.display = "inline";
                                    }
                                    else {
                                        child.style.display = "none";
                                    }
                                }
                            });
                        }

                    }
                    //Set selected value in chips selector. This chips are hidden.
                    //Setting just to keep same value in both, dropdown and colour chips
                    var $colour = $style.find("ul.colourChips li");

                    $colour.removeClass("active");
                    $colour.each(function () {
                        if ($(this).data("itemnumber") == itemNo) {
                            $(this).addClass("active");
                            var $label = $style.find(".colourChipNameLabel");
                            $label.text($(this).data("value"));
                        }
                    })

                    if (Next.Settings.Channel.Coords.Enabled && $("#pdpnav").length && Next.Settings.Channel.EnablePersistColourAcrossTabs) {
                        if ($(".pdp-tab.active a").attr("data-styleid") !== $(".pdp-tab >.tabLabel > a").attr("data-styleid")) {
                            $(".pdp-tab >.tabLabel > a").attr("colourwayFlag", true);
                        }
                        else {
                            if ($(".pdp-tab >.tabLabel > a").attr("colourwayFlag") !== "true") {
                                $(".pdp-tab .tabLabel a").attr("colour", $style.find(".colourList .dk_label").text() ? $style.find(".colourList .dk_label").text() : $style.find(".colourChipNameLabel").text());
                            }
                        }
                    }

                    if (Next.Settings.Channel.PDPH1TitleColourAppend) {
                        if (parentElement.find(".Title h1").length > 0)
                            titleElement.find('h1').text(colourVariant + ' ' + productTitle);
                        else if (parentElement.find(".Title h2").length > 0)
                            titleElement.find('a').text(colourVariant + ' ' + productTitle);
                    }
                    if (pdpChipsEnabled && ProductPage.Styles.SplitSize.IsEnabled($style)) {
                        ProductPage.Styles.AttachEvents.SplitSizeChipChange($style);
                        if (pdpSplitSizeEnabled) {
                            ProductPage.Styles.SplitSize.SetSplitSizeInitialSelection($style);
                        }
                    }
                     if (!Next.Settings.Channel.EnableClientsideSizeDropdown) {
                        EarlyStock.Init();
                    }

                });
            },
            ColourChipChange: function () {
                ProductPage.Vars.$itemsContainer.find(".chipsItemList").on("click", ".colourChipLink", function () {
                    var $styleForm = $(this).closest(".StyleForm");
                    var $colourChipLi = $(this).parent(".colourChip");
                    var colSelector = $styleForm.find("select.colourList");
                    if (!$colourChipLi.hasClass("selected")) {
                        var selItemNumber = $colourChipLi.data("itemval");
                        colSelector.dropkick("setValue", selItemNumber);
                    }
                });
            },
            QtyChange: function () {
                ProductPage.Vars.$itemsContainer.find(".ppm-quantityselector-container").each(function () {
                    var $qtyContainer = $(this);
                    var $styleForm = $qtyContainer.closest(".StyleForm");
                    var $addToBagButtons = $styleForm.find(".AddToBag a.btn-addtobag");
                    var $QtyBtnPlus = $qtyContainer.find(".quantity-selector-btn.quantity-selector-plus");
                    var $QtyBtnMinus = $qtyContainer.find(".quantity-selector-btn.quantity-selector-minus");
                    var $QtyInput = $qtyContainer.find(".quantity-selector-input");
                    var maxQt = parseInt($QtyInput.attr("max"), 10) || 9;
                    var minQt = parseInt($QtyInput.attr("min"), 10) || 1;
                    var setQtyValue = function (qVal) {
                        $QtyInput.val(qVal).data("savedvalue", qVal);
                    };
                    var updateButtons = function (qVal) {
                        ProductPage.Styles.ToggleDisable($QtyBtnPlus, qVal == maxQt);
                        ProductPage.Styles.ToggleDisable($QtyBtnMinus, qVal == minQt);
                        var addToBagText = "ADD " + qVal.toString() + " TO BAG";
                        $addToBagButtons.text(addToBagText);
                    };
                    var qtyCurrVal = parseInt($QtyInput.val(), 10) || minQt;
                    updateButtons(qtyCurrVal);
                    $QtyInput.on('input', function (event) {
                        var qtySavedVal = $(this).data("savedvalue") || $(this).val() || minQt;
                        //this.validity.valid || (this.value = qtySavedVal);
                        $QtyInput.data("savedvalue", $QtyInput.val());
                    }).on('keyup', function (event) {
                        var inputValStr = $QtyInput.val(), inputValParsed = parseInt(inputValStr, 10), cQtyVal = inputValParsed || minQt;
                        if (!isNaN(inputValParsed) && cQtyVal >= minQt && cQtyVal <= maxQt) {
                            cQtyVal = $(this).data("savedvalue") || $(this).val() || minQt;
                            $QtyInput.val(cQtyVal);
                        }
                        if ((inputValStr && isNaN(inputValParsed)) || cQtyVal < minQt || cQtyVal > maxQt) {
                            if (inputValStr && inputValStr != '') {
                                cQtyVal = minQt;
                                $QtyInput.val(cQtyVal);
                            }
                        }
                        updateButtons(cQtyVal);
                    }).on("paste", function (e) {
                        e.preventDefault();
                    });
                    $QtyBtnPlus.click(function () {
                        var qtyVal = (parseInt($QtyInput.val(), 10) || minQt) + 1;
                        if (qtyVal <= maxQt) {
                            setQtyValue(qtyVal);
                            updateButtons(qtyVal);
                        }
                    });
                    $QtyBtnMinus.click(function () {
                        var qtyVal = (parseInt($QtyInput.val(), 10) || (minQt + 1)) - 1;
                        if (qtyVal >= minQt) {
                            setQtyValue(qtyVal);
                            updateButtons(qtyVal);
                        }
                    });
                });
            },
            StyleHeader: function () {
                ProductPage.Vars.$styles.find(".StyleHeader").each(function () {
                    $(this).height($(this).find("h2").height());
                });

            },
            NotifyMeHelp: function () {
                ProductPage.Vars.$styles.find(".NotifyMeHelp").each(function () {
                    $(this).NextHelperPopUp({ width: 235, align: "top", delay: 500 });
                });
            },
            OffersAvailableScrolldown: function () {
                var $popoverLink = $(".offersAvailableLink");
                $popoverLink.click(function (event) {
                    var $targetScrollElement = $("#dynamic-div");
                    if ($targetScrollElement.css('display') !== 'none') {
                        $("html, body").animate({
                            scrollTop: $targetScrollElement.offset().top - $popoverLink.offset().top
                        }, 2000);

                        if (dataLayer != null && Next.Settings.Channel.Promotions.GWP) {
                            dataLayer.push({
                                event: 'GWP',
                                GWP: {
                                    Label: 'gwp_offers_available',
                                    Action: 'Hover',
                                    Category: 'Gift With Purchase'
                                }
                            });
                        }
                        event.preventDefault();
                        event.stopImmediatePropagation();
                    }
                });
            },
            BuyNowHelp: function () {
                ProductPage.Vars.$styles.find("#buyNowHelp").each(function () {
                    $(this).NextHelperPopUp({ width: 260, align: 'bottom', delay: 500 });
                });
            },
            FindOutMore: function () {
                $(".BagHolder").on('click', '.findMoreLink', function () {
                    var url = '/delivery-service/shop-my-local-store';
                    window.open(url, "_blank")
                });
            },
            CistHelp: function () {
                $(".CistHelp").on('click', function () {
                    var $this = $(this);
                    if (($this).next().hasClass("NextHelperPopUp")) {
                        hideDialoguePopUp($this);
                        clearTimeout(timeout);
                    }
                    else {
                        showDialoguePopUp($this, { width: 226, align: "top", delay: 500 });
                        var timeout = setTimeout(function () {
                            hideDialoguePopUp($this);
                            clearTimeout(timeout);
                        }, 10000);
                        return false;
                    }
                });
                $(".Content").on('click', function () {
                    var $this = $(".CistHelp");
                    if (($this).next().hasClass("NextHelperPopUp")) {
                        hideDialoguePopUp($this);
                        clearTimeout(0);
                    }
                });
            },
            PriceHistory: function () {
                $(".wasprices").click(function () {
                    $(".tooltip", this).toggle();
                });
                this.HighlightHighestItemPrice();
            },
            HighlightHighestItemPrice: function () {
                ProductPage.Vars.$styles.each(function () {
                    var $style = $(this);
                    var itemNumber = $style.data("targetitem");

                    var currentItemData = ProductPage.Styles.GetPageDataForItem(itemNumber);

                    //Sale
                    if (currentItemData.item.IsDiscount) {
                        $style.find('.Price span').text(currentItemData.item.SalePlainPrice);
                        $style.find('.Price .wasPrice').text(currentItemData.item.SaleHighlightPrice);
                        var $tbody = $style
                            .find('.priceHistoryGroup').show()
                            .find("tbody").empty();

                        var priceHistory = currentItemData.item.PriceHistory;

                        var highestPrice = 0;
                        var highestPriceItemIndex = 0;
                        for (var i in priceHistory) {
                            if (priceHistory[i] != null && priceHistory[i].PricePoint != null) {
                                var rangeHighestPriceIndex = priceHistory[i].PricePoint.indexOf('-');

                                if (rangeHighestPriceIndex > -1) // Indicates its a range of prices
                                {
                                    var rangeHighestPrice = priceHistory[i].PricePoint.substring(rangeHighestPriceIndex,
                                        priceHistory[i].PricePoint.length);
                                    rangeHighestPrice = Number(rangeHighestPrice.replace(/[^0-9\.]+/g, ""));

                                    if (rangeHighestPrice > highestPrice) {
                                        highestPriceItemIndex = i;
                                        highestPrice = rangeHighestPrice;
                                    }
                                } else // Indicates only 1 price throughout all items
                                {
                                    var price = Number(priceHistory[i].PricePoint.replace(/[^0-9\.]+/g, ""));

                                    if (price > highestPrice) {
                                        highestPriceItemIndex = i;
                                        highestPrice = price;
                                    }
                                }
                            }
                        }

                        for (var i in priceHistory) {
                            $tbody
                                .append($("<tr/>")
                                    .addClass(i % 2 == 0 ? 'odd' : '')
                                    .addClass(i == highestPriceItemIndex ? 'highestprice' : '')
                                    .append($("<td/>").text(priceHistory[i].DatePoint))
                                    .append($("<td/>").text(priceHistory[i].PricePoint))
                                );
                        }
                    } else {
                        $style.find('.Price span').text(currentItemData.item.FullPrice);
                        $style.find('.Price .wasPrice').empty();
                        $style.find('.priceHistoryGroup').hide();
                    }

                });
            },
            TrackPDPGAEvents: function () {
                try {
                    var $sGuideLink = ProductPage.Vars.$itemsContainer.find(".SizeGuideLink");
                    $sGuideLink.click(function () {
                        TrackGAEvent("PDP", "tap", "pdp-sizing-guide-opened");
                    });
                    var $collectionsLink = ProductPage.Vars.$itemsContainer.find(".spreadImageWrapper a");
                    $collectionsLink.click(function () {
                        TrackGAEvent("PDP", "tap", "pdp-shop-the-collection-clicked");
                    });
                } catch (e) { }
            },
            SplitSizeChipChange: function ($currentstyle) {
                var fit = ProductPage.Vars.GetCurrentFit();
                var $style = ProductPage.Vars.GetCurrentStyleElement();
                if (pdpChipsEnabled && $currentstyle) {
                    fit = ProductPage.Vars.GetCurrentFit($currentstyle);
                    $style = $currentstyle;
                }
                if (fit) {
                    fit.Items.forEach(function (item) {
                        var itemNumber = item.ItemNumber;
                        var $sizeSelector = $style.find("select#Size-" + itemNumber);

                        $sizeSelector.on("change", function () {
                            ProductPage.Styles.SplitSize.SetSplitSizeStockDisplay($sizeSelector);
                            ProductPage.Styles.SplitSize.UpdateSplitSizeSelection($sizeSelector);
                        });
                        $style.find(".Chips.splitSizeContainer[for=Size-" + itemNumber + "]")
                            .first()
                            .find(".splitSizeRow")
                            .each(function () {
                                ProductPage.Styles.SplitSize.BindClickEventForChips($(this).find("label").attr("for"), $style);
                            });
                    });
                }
            },
            SplitSizeDropDownChange: function () {
                var $SplitSizeList = ProductPage.Vars.$itemsContainer.find("Select.splitSizeSelector");
                $SplitSizeList.on("change", function () {
                    var $ddl = $(this);
                    var $CurrentSplitSize = $ddl;
                    var $style = $ddl.parents("article.Style");
                    var $splitSizeContainer = $ddl.closest('.splitSizeContainer');
                    var $SplitSizeddls = $splitSizeContainer.find(".splitSizeRow:visible").length > 0 ? $splitSizeContainer.find(".splitSizeRow:visible") : $splitSizeContainer;
                    var options = [];
                    var itemNumber = $style.data("targetitem");
                    var $sizeSelector = $style.find("select#Size-" + itemNumber);
                    var CurrentFilter = {};
                    var splitSizeKeys = [];
                    var CurrentFilter = ProductPage.Styles.SplitSize.SelectedSplitSize($sizeSelector);
                    var splitSizeKeys = ProductPage.Styles.SplitSize.GetAvailableKeys($sizeSelector);

                    $sizeSelector.find("option").each(function () {
                        $option = $(this);
                        var option = {
                            stockstatus: $option.data("stockstatus")
                        };
                        splitSizeKeys.forEach(function (key) {
                            option[key] = $option.data("splitsizes" + key);
                        });
                        options.push(option);
                    });
                    splitSizeKeys.forEach(function (key, j) {
                        $SplitSizeddls.find("Select.splitSizeSelector." + key).find("option").each(function () {
                            var $SplitSizeOption = $(this);
                            var SplitSizeValue = $SplitSizeOption.val() == "" ? undefined : $SplitSizeOption.val();
                            var shouldBeHiddenIfNoOption = false;
                            var allChildOptionsUnavailable = undefined;
                            var allOptionsUnavailable = true;
                            var option = undefined;
                            $.each(options, function (_, opt) {
                                var result = false;
                                $.each(CurrentFilter, function (filterField, filterValue) {
                                    if (filterField === key) {
                                        if (result) {
                                            result = opt[key] == SplitSizeValue;
                                        }
                                        if (allChildOptionsUnavailable === undefined) {
                                            allChildOptionsUnavailable = true;
                                        }
                                        if (opt[key] == SplitSizeValue && opt.stockstatus !== "SoldOut") {
                                            allChildOptionsUnavailable = false;
                                        }
                                        return false;
                                    }
                                    if (filterValue) {
                                        result = opt[filterField] == filterValue;
                                        shouldBeHiddenIfNoOption = true;
                                    }
                                    else {
                                        return false;
                                    }
                                });
                                if (opt.stockstatus && opt.stockstatus != "" && opt.stockstatus !== "SoldOut") {
                                    allOptionsUnavailable = false;
                                }

                                if (result && option === undefined) {
                                    option = opt;
                                }
                            });
                            if (option === undefined && shouldBeHiddenIfNoOption && $SplitSizeOption[0].index != 0) {
                                if ($SplitSizeOption.val() == $SplitSizeOption.parent().find("option:selected").val()) {
                                    $SplitSizeOption.parent().prop("selectedIndex", 0);
                                    $SplitSizeOption.parent().parent().find("ul li").removeClass("dk_option_current")
                                    $SplitSizeOption.parent().parent().find(".dk_label").text("Choose Size");
                                    $SplitSizeOption.parent().val("Choose Size");
                                    var $button = $sizeSelector.closest(".StyleForm").find("a.addToBagCTA");
                                    if ($button.hasClass("disabled")) {
                                        $($button).removeClass("disabled").addClass("Enabled").attr("data-description", "");
                                        $($button).unbind("mouseenter mouseleave")
                                            .removeClass("disabled")
                                            .addClass("Enabled");
                                    }
                                }
                                $SplitSizeOption.hide();
                                var $SelectItemOptions = $SplitSizeOption.parent().parent().find('.dk_dropdown_option');
                                $SelectItemOptions.each(function () {
                                    var Opt = $(this);
                                    if (Opt[0].innerText == $SplitSizeOption[0].innerText) {
                                        Opt.parent().hide();
                                    }
                                })
                            }
                            else if ((option && (option.stockstatus === "SoldOut" || (!Next.Settings.Channel.ModularPDPSplitSize && (pdpChipsEnabled && ProductPage.Styles.pdpChipsShow()) && option.stockstatus === "SaleSoldOut"))) || allChildOptionsUnavailable || allOptionsUnavailable) {
                                $SplitSizeOption.show();
                                var $SelectItemOptions = $SplitSizeOption.parent().parent().find('.dk_dropdown_option');
                                $SelectItemOptions.each(function () {
                                    var Opt = $(this);
                                    if (Opt[0].innerText == $SplitSizeOption[0].innerText) {
                                        Opt.parent().show();
                                    }
                                })

                            }
                            else {
                                $SplitSizeOption.show();
                                var $SelectItemOptions = $SplitSizeOption.parent().parent().find('.dk_dropdown_option');
                                $SelectItemOptions.each(function () {
                                    var Opt = $(this);
                                    if (Opt[0].innerText == $SplitSizeOption[0].innerText) {
                                        Opt.parent().show();
                                    }
                                })
                            }
                        });
                    });

                    if (ProductPage.Styles.SplitSize.SelectionComplete($sizeSelector)) {
                        var selectorValue = ProductPage.Styles.SplitSize.GetSizeSelectorValueForSplitSize($sizeSelector);
                        if (selectorValue) {
                            $sizeSelector.dropkick("setValue", selectorValue);
                            if (pdpChipsEnabled && ProductPage.Styles.SplitSize.IsEnabled($style)) {
                                ProductPage.Styles.SplitSize.SetSplitSizeStockDisplay($sizeSelector);
                            }
                        }
                    }
                    else {
                        $sizeSelector.prop("selectedIndex", 0);
                        var $SplitSizeContainer = $SplitSizeddls.find("Select.splitSizeSelector");
                        var i = 0;
                        if ($CurrentSplitSize.val() == "" || $CurrentSplitSize.val() == undefined) {
                            if ($SplitSizeContainer[0] == $CurrentSplitSize[0]) {
                                $SplitSizeContainer.each(function () {
                                    var $SplitSize = $(this);
                                    if ($SplitSize.val() == "" || $SplitSize.val() == undefined) {
                                        var $SiblingSplitSizes = $SplitSizeContainer
                                        $SiblingSplitSizes.each(function () {
                                            var $SplitSizeOption = $(this);
                                            if ($SplitSizeContainer[i] != $SplitSizeOption[0]) {
                                                $SplitSizeOption.parent().find("ul li").removeClass("dk_option_current");
                                                $SplitSizeOption.parent().find(".dk_label").text("Choose Size");
                                                $SplitSizeOption.val("Choose Size");
                                            }
                                        })
                                    }
                                    i++;
                                })
                            }
                            var $button = $sizeSelector.closest(".StyleForm").find("a.addToBagCTA");
                            if ($button.hasClass("disabled")) {
                                $($button).removeClass("disabled").addClass("Enabled").attr("data-description", "");
                                $($button).unbind("mouseenter mouseleave")
                                    .removeClass("disabled")
                                    .addClass("Enabled");
                            }
                        }
                        if (!$style.find(".splitSizeMessage[for=Size-" + itemNumber + "]").hasClass("validationError")) {
                            ProductPage.Styles.SplitSize.ResetSplitSizeMessage($CurrentSplitSize);
                        }
                    }
                    if (pdpSplitSizeEnabled) {
                        ProductPage.Styles.SplitSize.SetsplitSizeLabelValidation($sizeSelector);
                        if ($ddl.parent().siblings(".splitSizeChips").length) {
                            $ddl.parent().siblings(".splitSizeChips").find("li.splitSizeChip").each((index, currElm) => {
                                if ($(currElm).data("value") == $CurrentSplitSize.val())
                                    $(currElm).addClass("active").siblings().removeClass("active");
                            });

                        }
                    }
                })
            },
            ColourDropdownClick: function () {
                //<summary>Colour Dropdown - Clicked</summary>

                var $colourList = ProductPage.Vars.$itemsContainer.find("select.colourList");
                var $colourListContainer = $colourList.closest(".dk_container")

                $colourListContainer.click(pushClickToDatalayer);
                $colourListContainer.blur(pushClickToDatalayer);

                function pushClickToDatalayer() {
                    var $this = $(this);
                    if ($this.hasClass("dk_open")) {
                        AddTrackGAEventToDataLayer("pdp", "dropdown", "Colour close")
                    } else {
                        AddTrackGAEventToDataLayer("pdp", "dropdown", "Colour open")
                    }

                }
            },
            ToggleSustainabilityAccordion: function () {
                $("#SustainabilityTitle").on("click", function () {
                    var _this = $(this);
                    if (_this.hasClass("collapsed")) {
                        _this.removeClass("collapsed").addClass("expanded");
                        ProductPage.Vars.SustainabilityChevron.removeClass("collapsed").addClass("expanded");
                        ProductPage.Vars.SustainabilityDataContainer.removeClass("collapsed").addClass("show");
                        ProductPage.Vars.DivSustainabilityAccordion.removeClass("collapsed").addClass("expanded");
                        if (dataLayer != null) {
                            dataLayer.push({
                                event: 'TrackGAEvent',
                                link_category: 'hyperlink',
                                link_id: 'click',
                                link_name: 'Accordion Click on PDP - Sustainability'
                            });
                        }
                    }
                    else {
                        _this.removeClass("expanded").addClass("collapsed");
                        ProductPage.Vars.SustainabilityChevron.removeClass("expanded").addClass("collapsed");
                        ProductPage.Vars.SustainabilityDataContainer.removeClass("show").addClass("collapsed");
                        ProductPage.Vars.DivSustainabilityAccordion.removeClass("expanded").addClass("collapsed");
                    }
                });
            },
            ToggleCareAndFabricAccordion: function () {
                $("#CareAndFabricTitle").on("click", function () {
                    var _this = $(this);
                    if (_this.hasClass("collapsed")) {
                        _this.removeClass("collapsed").addClass("expanded");
                        ProductPage.Vars.CareAndFabricChevron.removeClass("collapsed").addClass("expanded");
                        ProductPage.Vars.CareAndFabricDataContainer.removeClass("collapsed").addClass("show");
                        ProductPage.Vars.DivCareAndFabricAccordion.removeClass("collapsed").addClass("expanded");
                        if (dataLayer != null) {
                            dataLayer.push({
                                event: 'TrackGAEvent',
                                link_category: 'hyperlink',
                                link_id: 'click',
                                link_name: 'Accordion Click on PDP - CareAndFabric'
                            });
                        }
                    }
                    else {
                        _this.removeClass("expanded").addClass("collapsed");
                        ProductPage.Vars.CareAndFabricChevron.removeClass("expanded").addClass("collapsed");
                        ProductPage.Vars.CareAndFabricDataContainer.removeClass("show").addClass("collapsed");
                        ProductPage.Vars.DivCareAndFabricAccordion.removeClass("expanded").addClass("collapsed");
                    }
                });
            },
            ChanelBrandLogoClick: function () {
                const chanelHomePagePath = "/beauty/chanel";
                $(".chanelPDP .chanel-logo, .chanelPDP .black-thick-line").on("click", function () {
                    location.href = chanelHomePagePath;
                });
            }

        },
        SetPartialDescriptionStyle: function ($contentDiv) {
            $contentDiv.find('.read-more').show();
            $contentDiv.find('.read-more-padding').css('height',
                'calc(' + $firstSection.height() + ' - 2.5ex)');
            $contentDiv.css('height', $firstSection.height());
        },
        SetActiveStyle: function (targetStyleId) {
            var $currentStyle = $(".Style.Selected");
            var $targetStyle = $("article.Style[data-styleid='" + targetStyleId + "']");
            $targetStyle.addClass("has-animation");
            $(".grabPoint").remove();
            $("#lastArticleBottom").remove();
            $currentStyle.removeClass("Selected");
            $targetStyle.addClass("Selected");
            $targetStyle.prepend('<div class="grabPoint" id="lastItemImageGrab"></div>');
            $targetStyle.append('<div id="lastArticleBottom"></div>');
            ProductPage.Styles.ShowItem(false);
        },
        SetColourChipSelection: function ($styleArticle, selItemNo) {
            $styleArticle.find(".colourChip").removeClass("selected");
            var $colourChipLi = $styleArticle.find(".colourChip[data-itemval='" + selItemNo + "']");
            $colourChipLi.addClass("selected");
        },
        SetBeautyStockDisplay: function ($sizeSelect, stockMessage) {
            var stockStatusStr = "In Stock";
            if ($sizeSelect && $sizeSelect.children("option").length == 1) {
                if (stockMessage) {
                    stockStatusStr = stockMessage.trim().replace(/^-/, '').trim();
                }
                $sizeSelect.closest("article").find(".beauty-stock-status").text(stockStatusStr);
            }
        },
        ClearBeautyStockDisplay: function ($sizeSelect) {
            $sizeSelect.closest("article").find(".beauty-stock-status").text('');
        },
        ToggleDisable: function ($el, doDisable) {
            $el.toggleClass("disabled", doDisable).prop('disabled', doDisable);
        },
        ShowAfterpayInstallments: function () {

            $.each(ProductPage.Vars.$styles,
                function () {
                    var $style = $(this);
                    var itemNumber = $style.data("targetitem");
                    var currentItemData = ProductPage.Styles.GetPageDataForItem(itemNumber);

                    if (currentItemData.item.FullPrice.indexOf("-") == -1) {
                        var number = parseFloat(currentItemData.item.FullPrice.replace(/[^0-9.-]+/g, ""));
                        var currencySymbol = currentItemData.item.FullPrice.substring(0, 1);
                        var installment = parseFloat(number / 4);
                        var finalText;

                        // decimal point or whole number
                        if (parseFloat(installment) % 1 === 0) {
                            finalText = "of " + currencySymbol + parseInt(installment) + " ";
                        } else {
                            finalText = "of " + currencySymbol + parseFloat(installment).toFixed(2) + " ";
                        }

                        $style.find('.StyleForm .BagHolder .Afterpay .installment-text .afterpayPrice').text(finalText);
                    }
                });
        },
        DisableQtySelector: function ($styleForm, doDisable) {
            var $QtyBtnPlus = $styleForm.find(".quantity-selector-btn.quantity-selector-plus");
            var $QtyBtnMinus = $styleForm.find(".quantity-selector-btn.quantity-selector-minus");
            var $QtyInput = $styleForm.find(".quantity-selector-input");
            var maxQt = parseInt($QtyInput.attr("max"), 10) || 9;
            var minQt = parseInt($QtyInput.attr("min"), 10) || 1;
            var qtyCurrVal = parseInt($QtyInput.val(), 10) || minQt;
            ProductPage.Styles.ToggleDisable($QtyInput, doDisable);
            ProductPage.Styles.ToggleDisable($QtyBtnPlus, doDisable || (qtyCurrVal == maxQt));
            ProductPage.Styles.ToggleDisable($QtyBtnMinus, doDisable || (qtyCurrVal == minQt));
        },
        TrackGASelectionChanged: function (gaLabel, $gaControl) {
            var $gaStyle, gaItemNumber, $gaCurrentSel, gaCurrentVal, gaCurrentText, gaPreviousText, gaOptionsLength;
            try {
                //If only one option dropkick selects it by default on initialization.
                gaOptionsLength = $gaControl.children('option').length;
                if (gaOptionsLength > 1) {
                    $gaStyle = $gaControl.parents("article.Style");
                    gaItemNumber = $gaStyle.data("targetitem");
                    $gaCurrentSel = $gaControl.find("option:selected");
                    gaCurrentText = $gaCurrentSel.text();
                    gaCurrentVal = $gaCurrentSel.val();
                    gaPreviousText = $gaControl.data("last-sel-option");
                    if (gaCurrentVal && (gaPreviousText != gaCurrentText)) {
                        TrackGAEvent("PDP", "Dropdown Changed", "pdp-" + gaLabel + "-option-selected" + "_" + gaCurrentText + "_" + gaItemNumber);
                        $gaControl.data("last-sel-option", gaCurrentText);
                    }

                    if (document.getElementsByClassName('Afterpay').length > 0) {
                        var currentItemData = ProductPage.Styles.GetPageDataForItem(gaItemNumber);
                        var isRange = currentItemData.item.FullPrice.includes(" - ");
                        var currencySymbol = currentItemData.item.FullPrice.substring(0, 1);
                        var finalText = "";


                        if (isRange && gaCurrentText == "Choose Size") {
                            finalText = "";
                        }
                        else {
                            var amount = 0;

                            if (isRange) {
                                var text = gaCurrentText.split(currencySymbol)[1];
                                amount = parseFloat(text.replace(/[^0-9.-]+/g, ""));
                            }
                            else {
                                amount = parseFloat(currentItemData.item.FullPrice.replace(/[^0-9.-]+/g, ""));
                            }

                            if (!isNaN(amount)) {
                                var installment = parseFloat(amount / 4);
                                var precision = 0;

                                if (parseFloat(installment) % 1 === 0) {
                                    precision = parseInt(installment);
                                }
                                else {
                                    precision = parseFloat(installment).toFixed(2);
                                }
                                finalText = "of " + currencySymbol + precision;
                            }
                        }
                        $gaStyle.find('.StyleForm .BagHolder .Afterpay .installment-text .afterpayPrice').text(finalText);
                    }
                }
            } catch (e) { }

        },
        TrackGAChipSelection: function (gaLabel, $gaControl) {
            var $gaStyle, gaItemNumber, gaCurrentValue;
            try {
                if ($gaControl) {
                    $gaStyle = $gaControl.parents("article.Style");
                    gaItemNumber = $gaStyle.data("targetitem");
                    gaCurrentValue = $gaControl.data("value");
                    var department = "";
                    if (dataLayer && dataLayer.length > 0) {
                        for (var j = 0; j < dataLayer.length; j++) {
                            if (dataLayer[j].department != undefined) {
                                department = dataLayer[j].department + "-";
                                break;
                            }
                        }
                    }
                    if (gaCurrentValue) {
                        TrackGAEvent("PDP", "Chip Changed", department + "pdp-" + gaLabel + "-chip-selected" + "_" + gaCurrentValue + "_" + gaItemNumber);
                    }
                }
            } catch (e) { }
        },
        FitChanged: function ($fit, itemNo, makeCallToDynamicDiv) {
            if (typeof makeCallToDynamicDiv === 'undefined') { makeCallToDynamicDiv = true; }
            var $style = $fit.parents("article.Style");
            var styleId = $style.data("styleid");
            var fitName = $fit.val();
            var SplitFitName = "";



            if ($fit.hasClass("chipItem")) {
                fitName = $fit.data("value");
                if (fitName) {
                    SplitFitName = $fit.attr("data-fit");
                }

                if (!$fit.hasClass("active")) {
                        $fit.addClass("active").siblings().removeClass("active");
                        $style.attr("data-fit", fitName);
                }
            }
            else if ($fit.hasClass("asmFitList")) {
                SplitFitName = $fit.find("option:selected").data("fit");
                $style.attr("data-fit", fitName);
            }
            else {
                SplitFitName = fitName;
            }

            //#region Make call to ProductAggregator API to update item details of new FIT which is selected.
            if (Next.Settings.Channel.EnableProductAggregator) {
                const style = ProductPage.Vars.ItemData.find(f => f && f.StyleID === styleId);
                const fit = style && style.Fits.find(f => f && f.Name === fitName);

                if (fit) {
                    var itemNumber = fit.Items[0].ItemNumber;
                    ProductPage.GetShotForSingleItem(false, 3, itemNumber);
                    currentItemNum = itemNumber;
                }
            }
            // #endregion

            var style;
            $.each(ProductPage.Vars.ItemData, function () {
                if (this.StyleID == styleId) {
                    style = this;
                    return false;
                }
            });

            var fit;
            $.each(style.Fits, function () {

                if (ProductPage.Styles.SplitSize.SplitFitEnabled()) {
                    if (this.Name == SplitFitName) {
                        fit = this;
                        return false;
                    }
                }
                else if (this.Name === fitName) {
                    fit = this;
                    return false;
                }
            });

            var $colourSelect = $style.find("select.colourList");
            //This element is in DOM only when ColourChipsFeature is enabled in channelConfig
            var $colourChips = ProductPage.Vars.IsChanelBrandPDPEnabled ? $style.find("ul.chanelItemList") : $style.find("ul.colourChips");
            //Check colour selector (dropdown or chips) for previous fit
            var previousChips = $style.find("ul.colourChips").val()
                && $style.find("ul.colourChips").css("display") != "none";
            //If fit has more then maxcount (set in channelConfig and the feature switch is eneble) colour chips appear on pdp page
            if ((fit.ColourChipsEnabled && !pdpChipsEnabled) || (pdpChipsEnabled && fit.PDPChipsColourEnabled && ProductPage.Styles.pdpChipsShow())) {
                //Colour dropdown is hidden in case when colour chips are appearing on pdp 
                $colourSelect.hide();
                $colourChips.show();
                $colourSelect.closest(".DropDown").hide();
                $colourChips.closest(".Chips").show();
            } else {
                //Colour chips are hidden in case when we have fit with feature switch setting on false or with more then maxcount colours 
                ProductPage.Vars.IsChanelBrandPDPEnabled ? $colourChips.show() : $colourChips.hide();
                $colourSelect.show();
                $colourSelect.closest(".DropDown").show();
                ProductPage.Vars.IsChanelBrandPDPEnabled ? $colourChips.closest(".Chips").show() : $colourChips.closest(".Chips").hide();
            }

            var currentColour;
            if (previousChips) {
                currentColour = $colourChips.find("li.active").data("value");
            }
            else {
                currentColour = $colourSelect.find("option:selected").text();
            }

            if (Next.Settings.Channel.EnableProductAggregator && currentColour.trim.length === 0) {
                $.each(fit.Items, function () {
                    if ((currentItemNum && this.ItemNumber.toUpperCase() === currentItemNum.toUpperCase())) {
                        currentColour = this.Colour;
                        return false;
                    }
                });
            }

            if ((fit.ColourChipsEnabled && !pdpChipsEnabled) || pdpSingleColourChipsEnabled || (pdpChipsEnabled && fit.PDPChipsColourEnabled && ProductPage.Styles.pdpChipsShow()) || ProductPage.Vars.IsChanelBrandPDPEnabled) {
                if (Next.Settings.Channel.EnableEmbeddedReviews) {
                    // update data attrs in case colour is updated on fit change
                    $style.attr("data-colour", currentColour);
                }

                $colourChips.find("li").remove();

                var foundMatchingChips = false;
                var setSoldout = false;
                var $label = $style.find(".colourChipNameLabel");

                var hasMoreThanOneItems = true;
                if (Next.Settings.Channel.EnableProductAggregator && fit.Items && fit.Items.length === 1) {
                    $colourChips.hide();
                    hasMoreThanOneItems = false;
                }

                if (hasMoreThanOneItems) {
                    $colourChips.show();
                }

                $.each(fit.Items, function () {

                    if (pdpSingleColourChipsEnabled && !this.Colour) {
                        this.Colour = ProductPage.Vars.PdpSingleColourChipValue;
                    }

                    var colour = this.Colour;
                    if (!hasMoreThanOneItems && style.DefaultItemColour && style.DefaultItemColour.length > 0) {
                        colour = style.DefaultItemColour;
                    }

                    var $li = $("<li/>");
                    ProductPage.Vars.IsChanelBrandPDPEnabled ? $li.addClass('colourChip') : $li.addClass('chipItem');
                    ProductPage.Vars.IsChanelBrandPDPEnabled ? $li.attr("data-itemval", this.ItemNumber)
                        : $li.attr("data-itemnumber", this.ItemNumber);

                    $li.attr("data-value", colour);
                    $li.attr("title", colour);

                    if ((itemNo && this.ItemNumber.toUpperCase() === itemNo.toUpperCase())
                        || (!itemNo && colour === currentColour)) {
                        $li.addClass('active');
                        $label.text(colour);
                        foundMatchingChips = true;
                    }

                    if (Next.Settings.Channel.SoldoutColourChipStyle !== "" && this.IsSoldOut === "True") {
                        var isTargetItem = false;

                        var defaultItemNumber = $('#hdnDefaultItemNumber').val();
                        if (defaultItemNumber.toUpperCase().indexOf(this.ItemNumber.toUpperCase()) == 0) {
                            isTargetItem = true;
                        }

                        if (!isTargetItem) {
                            $li.addClass(Next.Settings.Channel.SoldoutColourChipStyle).addClass("SoldoutChip");

                            if (Next.Settings.Channel.EnablePersistColourAcrossTabs === "false") {
                                $li.removeClass('active');
                            }
                            setSoldout = true;
                        }
                    }

                    var $a = $("<a/>");
                    ProductPage.Vars.IsChanelBrandPDPEnabled ? $a.addClass('colourChipLink') : $a.addClass('chipItemLink');

                    var $img = $("<img/>");
                    $img.attr("src", this.ColourChipImage);
                    $img.attr("alt", colour);
                    $img.attr("title", colour);
                    $img.attr("onerror", "this.onerror = null; this.src = '/Images/Structural/ProductPage/swatchnoimage.jpg';");

                    $a.append($img);
                    $li.append($a);
                    $colourChips.append($li);
                });

                var colourChipsHasActive = $colourChips.find("li").hasClass("active");
                if ((!foundMatchingChips || setSoldout) && !colourChipsHasActive) {
                    var $firstElement = $colourChips.find("li").first();
                    if (Next.Settings.Channel.SoldoutColourChipStyle !== "" && $firstElement.hasClass("SoldoutChip")) {
                        $otherColourChips = $colourChips.find($("li:not(.SoldoutChip)"));
                        if ($otherColourChips.length > 0) {
                            $firstElement = $otherColourChips.first();
                        }
                    }
                    $firstElement.addClass('active');

                    // var $label = $style.find(".colourChipNameLabel");    
                    $label.text($firstElement.data("value"));
                }

                itemNo = $colourChips.length > 0 ? $colourChips.find("li.active").data("itemnumber") : fit.Items[0].ItemNumber;
                var previousItemNumber = $style.data("targetitem");
                var styleItemNo = $style.find(".StyleMeta .ItemNumber");
                if (pdpChipsEnabled && styleItemNo) {
                    if (ProductPage.Styles.SplitSize.IsEnabled($style) || styleItemNo.text() != previousItemNumber) {
                        previousItemNumber = styleItemNo.text();
                    }
                }
                $style.data("targetitem", itemNo);
                $style.attr("data-targetitem", itemNo);
                $(".Style.Selected").removeClass("Selected");
                $style.addClass("Selected");

                //It condition have been probably always true because in DOM we have dropdown, 
                //but if in future something will change it protect code by not refreshing element 

                ProductPage.Styles.ItemChanged(previousItemNumber, false);
                ProductPage.Styles.TrackGAChipSelection("colour", $colourChips.find("li.active"));

            }
            if ($colourSelect.length) {

                if (Next.Settings.Channel.EnableEmbeddedReviews) {
                    // update data attrs in case colour is updated on fit change
                    $style.attr("data-colour", currentColour);
                }

                var hasMoreThanOneItems = true;
                if (Next.Settings.Channel.EnableProductAggregator && fit.Items && fit.Items.length === 1) {
                    $colourSelect.parents(".ColourDropdown").hide();
                    $colourSelect.hide();
                    hasMoreThanOneItems = false;
                }

                if (hasMoreThanOneItems) {
                    $colourSelect.parents(".ColourDropdown").show();
                    $colourSelect.show();
                }

                $colourSelect.find("option").remove();

                $.each(fit.Items, function () {
                    // FB 161478 (Issue selecting same colourway in different fits) - remove the below code
                    //                   if (itemNo == null && this.ItemNumber != null) // if no itemNo is passed into the function, assigned the first colour's itemNumber 
                    //                   {
                    //                       itemNo = this.ItemNumber;
                    //                   }

                    var colour = this.Colour;
                    if (Next.Settings.Channel.EnableProductAggregator) {
                        if (!hasMoreThanOneItems && style.DefaultItemColour && style.DefaultItemColour.length > 0) {
                            colour = style.DefaultItemColour;
                            var styleTitle = colour;
                            if (Next.Settings.Channel.Language && Next.Settings.Channel.Language !== "en") {
                                styleTitle = styleTitle + " - " + style.StyleName;
                            }
                            else {
                                styleTitle = styleTitle + " " + style.StyleName;
                            }
                            $style.find(".StyleCopy .StyleHeader .Title h1").text(styleTitle);
                            if (Next.Settings.Channel.EnableEmbeddedReviews) {
                                // update data attrs in case colour is updated on fit change
                                $style.attr("data-colour", colour);
                            }
                        }
                        else {
                            $style.find(".StyleCopy .StyleHeader .Title h1").text(style.StyleName);
                        }
                    }


                    var $option = $("<option/>");
                    $option.val(this.ItemNumber);
                    $option.attr("data-excluded", this.Excluded);
                    $option.attr("data-imageurl", this.Image);

                    if (colour !== "") {
                        $option.text(colour);
                    } else {
                        $option.html("&nbsp;");
                    }

                    if ((itemNo && this.ItemNumber.toUpperCase() === itemNo.toUpperCase())
                        || (!itemNo && this.Colour === currentColour)) {
                        $option.prop('selected', true);


                    }

                    $colourSelect.append($option);
                });
                $colourSelect.dropkick("refresh");

                itemNo = $colourSelect.val();
            } else {
                //colourSelect does not exist, therefore there is no colour dropdown. Find hidden itemId input
                var $hiddenItemId = $style.find("input.hdnItmId");

                var itemNumber = itemNo || fit.Items[0].ItemNumber;

                $hiddenItemId.val(itemNumber);
                itemNo = $hiddenItemId.val();
                $(".Style.Selected").removeClass("Selected");
                $style.addClass("Selected");
                var previousItemNumber = $style.data("targetitem");
                var styleItemNo = $style.find(".StyleMeta .ItemNumber");
                if (pdpChipsEnabled && styleItemNo) {
                    if (ProductPage.Styles.SplitSize.IsEnabled($style) || styleItemNo.text() != previousItemNumber) {
                        previousItemNumber = styleItemNo.text();
                    }
                }
                $style.data("targetitem", itemNo);
                ProductPage.Styles.ItemChanged(previousItemNumber, makeCallToDynamicDiv);
            }

            if (Next.Settings.Channel.Afterpay != null && Next.Settings.Channel.Afterpay.enableOnProductPage) {
                this.ShowAfterpayInstallments();
            }
            if (pdpChipsEnabled && ProductPage.Styles.SplitSize.SplitFitEnabled()) {
                var ItmNo = $style.data("targetitem").toUpperCase();
                var CurrFit = $(".fitChips").find("li.chipItem.active").data("value");
                if (!CurrFit) {
                    CurrFit = $style.find(".StyleForm select.fitList").val();
                }
                var CurrFitSplitSizeContainer = $style.find("div.Chips.splitSizeContainer[for=Size-" + ItmNo + "]");
                if (CurrFitSplitSizeContainer.length > 0) {
                    Array.prototype.forEach.call(CurrFitSplitSizeContainer[0].children, function (child, index) {
                        var ItemFit = child.dataset.fit;
                        if (CurrFit != undefined) {
                            if (ItemFit === CurrFit) {
                                child.style.display = "inline";
                            }
                            else {
                                child.style.display = "none";
                            }
                        }
                    });
                }
                var $currentSizeSelector = $("select.SizeSelector#Size-" + itemNo);
                ProductPage.Styles.SplitSize.UpdateSplitSizeSelection($currentSizeSelector);
                if (pdpSplitSizeEnabled) {
                    ProductPage.Styles.SplitSize.SetSplitSizeInitialSelection($style);
                }
            }
        },
        SizeChipsEnabled: function (SelectedItemNumber) {
            var firstItem = ProductPage.Vars.$styles.get(0).dataset["targetitem"].toUpperCase();
            var itemData = ProductPage.Styles.GetPageDataForItem(firstItem);
            if (pdpChipsEnabled && SelectedItemNumber) {
                itemData = ProductPage.Styles.GetPageDataForItem(SelectedItemNumber.toUpperCase());
            }
            return ((itemData.fit.SizeChipsEnabled && !pdpChipsEnabled) || (pdpChipsEnabled && itemData.item.PDPChipsSizeEnabled && ProductPage.Styles.pdpChipsShow()))
        },
        pdpChipsShow: function () {
            var $style = ProductPage.Vars.$styles.filter(".Selected");
            var itemNumber = $style.data("targetitem");
            var sizeSelector = $("select.SizeSelector#Size-" + itemNumber);
            var ispdpChipsShow = sizeSelector.data("personalise") !== "Y" && sizeSelector.data("fulfilmenttype") !== "M" && !ProductPage.Vars.IsBeautyPage;
            return ispdpChipsShow;
        },
        PDPColourChipsEnabled: function () {
            var firstItem = ProductPage.Vars.$styles.get(0).dataset["targetitem"].toUpperCase();
            var itemData = ProductPage.Styles.GetPageDataForItem(firstItem);
            return (itemData.fit.PDPChipsColourEnabled && !ProductPage.Vars.IsBeautyPage)
        },
        UpdateSizeChipsStockStatus: function (sizeSelector, sizeChips) {
            var stockmessage = sizeSelector.find("option:selected").data("stockmessage");
            var optionNumber = sizeSelector.find("option:selected").val();
            var $sizeAvailabilitylabel = sizeChips.parent().find("div.sizeAvailability");
            var $pdpChipPricelabel = sizeChips.children("div.pdpChipPrice");
            var priceformatted = sizeSelector.find("option:selected").data("priceformatted");

            sizeChips.find("li.chipItem").filter(function (index) {
                if ($(this).data("value") == optionNumber) {
                    if (pdpChipsATBCtaJumpFix) {
                        if ($(this).hasClass("InStock")) {
                            $sizeAvailabilitylabel.addClass("InStock");
                        } else {
                            $sizeAvailabilitylabel.removeClass("InStock");
                        }
                    }
                    if ($(this).hasClass("LowStock")) {
                        $sizeAvailabilitylabel.addClass("LowStock");
                    }
                    else {
                        $sizeAvailabilitylabel.removeClass("LowStock");
                    }
                    if ($(this).hasClass("SoldOut")) {
                        $sizeAvailabilitylabel.addClass("SoldOut");
                    }
                    else {
                        $sizeAvailabilitylabel.removeClass("SoldOut");
                    }
                    if ($(this).hasClass("Delayed")) {
                        $sizeAvailabilitylabel.addClass("Delayed");
                    }
                    else {
                        $sizeAvailabilitylabel.removeClass("Delayed");
                    }
                    if ($(this).hasClass("SaleSoldOut")) {
                        $sizeAvailabilitylabel.addClass("SaleSoldOut");
                    }
                    else {
                        $sizeAvailabilitylabel.removeClass("SaleSoldOut");
                    }
                    if (pdpChipsATBCtaJumpFix) {
                        var formattedPrice = sizeSelector.find("option:selected").data("priceformatted") && sizeSelector.find("option:selected").data("priceformatted") !== " " ? sizeSelector.find("option:selected").data("priceformatted") + "-" : "";
                        $sizeAvailabilitylabel.text(formattedPrice + stockmessage);
                    }
                    else {
                        $sizeAvailabilitylabel.text(stockmessage);
                        $pdpChipPricelabel.text(priceformatted);
                    }
                }
            })
        },
        DisplaySizeChipsValidationMessage: function (itemNumber) {
            var $style = ProductPage.Vars.$styles.filter(".Selected");
            if (itemNumber && $style.find("div.sizeChipsContainer#Size-" + itemNumber).children("div.availabilityMessage").first().length <= 0) {
                $style = ProductPage.Vars.$styles.filter('[data-targetitem="' + itemNumber + '"]');
            }
            var $label;
            if (pdpChipsATBCtaJumpFix) {
                $label = $style.find("div.sizeChipsContainer#Size-" + itemNumber).parent().find("div.sizeAvailability").first();
                $label.addClass("availabilityMessage");
            }
            else {
                $label = $style.find("div.sizeChipsContainer#Size-" + itemNumber).children("div.availabilityMessage").first();
            }
            $label.text(nxt.jstranslations.productpage.nosizemessage);
        },
        LoadContentForDynamicDiv: function ($styleElement) {
            if (Next.Settings.Channel.DynamicDivEnabled && $styleElement.length === 1 && DynamicContent) {

                var itemNumber = $styleElement.data("targetitem").toUpperCase();
                var brand = $styleElement.data("brand");
                var category = $styleElement.data("category");
                var chain = $styleElement.data("chain");
                if (chain === undefined || chain.length === 0) {
                    chain = $styleElement.find(".hdnChain").val();
                }
                var department = $styleElement.data("department");
                var deviceType = "desktop";

                if (Next.Settings.Channel.Promotions.GWP) {
                    const $dynamicDivElement = $("#dynamic-div");
                    $dynamicDivElement.bind('DOMSubtreeModified', function () {
                        if ($dynamicDivElement.find("div").length > 0) {
                            $(".offersAvailableLink").show();
                        }
                    });
                }

                DynamicContent.loadContent(brand, category, chain, department, deviceType, itemNumber);
            }
        },
        LoadInitialItemOptions: function () {
            /// <summary>Get size options/stock status for initially loaded items</summary>            
            var productSKUs = "";
            var productInformation = "";
            var self = this;

            ProductPage.Vars.$styles.each(function () {
                var $style = $(this);
                var hashItem = ProductPage.HashSelection.CheckURLForHash();
                var itemNo = $style.data("targetitem").toUpperCase();
                var itemName = $style.data("itemname");

                //new update for TOV
                if (Next.Settings.Channel.WebDataFields.IsEnabled || isStackedPDPPage) {
                    if (Next.Settings.Channel.WebDataFields.ToneOfVoice || isStackedPDPPage) {
                        var $styleCopy = $style.find(".StyleCopy");
                        $.each(ProductPage.Vars.ItemData, function (iStyle, style) {
                            if (style.StyleID === $style.data("styleid")) {
                                $.each(style.Fits, function (iFit, fit) {
                                    $.each(fit.Items, function (iItem, item) {
                                        if (item.ItemNumber === itemNo) {
                                            self.UpdateItemData($style, $styleCopy, style, item, true);
                                        }
                                    });
                                });
                            }
                        });
                    }
                }

                //Load Sizing Guide's item number
                if (Next.Settings.Channel.SizingGuideEnabled && !pdpChipsEnabled) {
                    $style.find(".SizeGuideLink").attr("data-item-number", itemNo);
                }

                ProductPage.Styles.UpdateOptionLogoData($style);


                if (productSKUs !== "") {
                    productSKUs = productSKUs + ",";
                }
                if (productInformation !== "") {
                    productInformation = productInformation + ",";
                }
                productSKUs = productSKUs + itemNo;
                productInformation = productInformation + itemNo + "|" + itemName;

                if (!($style.hasClass("Selected") && $style.data("targetitem").toUpperCase() === hashItem.toUpperCase())) {


                    var itemDdl = $style.find("select.colourList");
                    var itemHdn = $style.find(".hdnItmId");
                    var $colourChip = $style.find("ul.colourChips li.active");

                    if (itemDdl.length) {
                        itemNo = itemDdl.val();
                    }
                    else if ($colourChip.length) {
                        itemNo = $colourChip.data("itemnumber");
                    }
                    else if (itemHdn.length) {
                        itemNo = itemHdn.val();

                        if (hashItem.length > 0 && hashItem !== itemNo) {

                            var styleId = $style.data("styleid");

                            var style;
                            $.each(ProductPage.Vars.ItemData, function () {
                                if (this.StyleID == styleId) {
                                    style = this;
                                    return false;
                                }
                                return true;
                            });

                            var $fitList = $style.find("select.fitList");
                            $.each(style.Fits, function () {
                                for (var i = 0; i < this.Items.length; i++) {
                                    if (this.Items[i].ItemNumber.toUpperCase() === hashItem.toUpperCase()) {
                                        itemNo = hashItem.toUpperCase();
                                        itemHdn.val(itemNo);
                                        var name = this.Name;
                                        $fitList.dropkick("setValue", name);
                                        return false;
                                    }
                                }
                                return true;
                            });
                        }
                    }
                }

                if (Next.Settings.Channel.TpPdpShowCareAndFabricAccordion) {
                    var displayCareAndFabric = false;
                    $.each(ProductPage.Vars.ItemData, function (iStyle, style) {
                        $.each(style.Fits, function (iFit, fit) {
                            $.each(fit.Items, function (iItem, item) {
                                if (item.ItemNumber === itemNo.toUpperCase()) {
                                    var table = "";
                                    if (item.WashingInstructions !== "") {
                                        table += '<table><tbody><tr><td class="description"><div class="description WashingInstructions">' + item.WashingInstructions + '</div></td></tr></tbody></table>';
                                        displayCareAndFabric = true;
                                    }
                                    if (item.Composition !== "") {
                                        table += '<table><tbody><tr><td class="description"><div class="description Composition">' + item.Composition + '</div></td></tr></tbody></table>';
                                        displayCareAndFabric = true;
                                    }
                                    if (displayCareAndFabric) {
                                        ProductPage.Vars.CareAndFabricDataContainer.html(table);
                                    }
                                }
                            });
                        });
                    });

                    if ($style.find("#Composition").length > 0) {
                        $style.find("#Composition").remove();
                    }

                    if ($style.find("#WashingInstructions").length > 0) {
                        $style.find("#WashingInstructions").remove();
                    }

                    if (displayCareAndFabric) {
                        ProductPage.Vars.DivCareAndFabricAccordion.show();
                    }
                }

                ProductDetails.Styles.RefreshOptionStockStatus($style, itemNo);
                if (pdpSplitSizeEnabled && ProductPage.Styles.SplitSize.IsEnabled($style)) {
                    ProductPage.Styles.SplitSize.SetSplitSizeInitialSelection($style);
                }
                // and will no longer go through to AddToBagCTA.SetState, 

                if (EnableFavourites) {
                    // so need to set binding for favs icon here 
                    NextFavourites.BindEvents();
                }

                ProductPage.Styles.HideSizeChipsWhenOverMaxLines(itemNo);
                ProductDetails.Styles.SelectOption(itemNo);
                if (ProductPage.Styles.SizeChipsEnabled(itemNo)) {
                    ProductDetails.Styles.ChipsChange(itemNo);
                }
                ProductPage.Styles.ShowWarranty($style, itemNo);
                if (pdpChipsEnabled && ProductPage.Styles.SplitSize.IsEnabled($style)) {
                    ProductPage.Styles.AttachEvents.SplitSizeChipChange($style);
                    if ($style.find(".Chips.splitSizeContainer[for=Size-" + itemNo + "]").find("li.splitSizeChip").length == 1) {
                        $('.splitSizeChip').click();
                    }
                }
            });

            if (dataLayer != undefined) {
                dataLayer.push({ "product_skus": productSKUs, "product_information": productInformation });
            }

            //Initial load logos
            //  $(".logos").hide();
            $(".legalWarningLogos").hide();

            //Loop through each styles and set the logo
            $.each(ProductPage.Vars.$styles,
                function (iStyle, style) {
                    var $currentStyleId = $(style).data("styleid");
                    var $targetItem = $(style).data("targetitem");
                    var $currentStyle;
                    $.each(ProductPage.Vars.ItemData, function (iStyle, style) {
                        if (style.StyleID == $currentStyleId) {
                            $currentStyle = style;
                        }
                    });
                    var $currentStyleCopy = $(style).find(".StyleCopy");

                    var myitem;
                    $.each($currentStyle.Fits, function (iFit, fit) {
                        $.each(fit.Items, function (iItem, item) {
                            if (item.ItemNumber === $targetItem.toUpperCase()) {
                                myitem = item;
                            }
                        });
                    });
                    //The items logos will be called here.
                    ProductPage.Styles.UpdateLogoData($currentStyleCopy, myitem);
                    ProductPage.Styles.UpdateLegalWarningLogosData($currentStyleCopy, myitem);
                });

        },
        AddToBagCTA: {
            SetState: function (sizeSelector, ignoreRecentlyViewed) {
                //<summary>Enable add to bag link when size drop down is selected</summary>
                var sizeSelectorElement = $(sizeSelector);

                var $style = sizeSelectorElement.parents("article.Style");
                if (!ignoreRecentlyViewed) {
                    if (!$style.hasClass("Selected")) {
                        $(".Style.Selected").removeClass("Selected");
                        $style.addClass("Selected");
                        ProductPage.Styles.ItemChanged();
                    }
                }

                if (Next.Settings.Channel.PersonalisedGiftsEnabled && sizeSelectorElement.data("personalise") === "Y") {
                    $style.find(".PersonaliseServiceIframe").children().remove();
                    $style.find(".PersonaliseServiceIframe").hide();
                    var $bagHolder = $style.find(".BagHolder");
                    if ($bagHolder.hasClass("nodisplay")) {
                        $bagHolder.removeClass("nodisplay");
                    }
                }

                sizeSelectorElement.find("option").each(function () {
                    var optionElement = $(this);
                    if (optionElement.hasClass("SoldOut") || optionElement.hasClass("SaleSoldOut") || optionElement.hasClass("ComingSoon")) {
                        optionElement.css("color", "red");
                    } else {
                        optionElement.css("color", "black");
                    }
                });
                var $button = Next.Settings.Channel.TotalPlatformFeatures.AltPDPItemNumberLocation ?
                    sizeSelectorElement.closest(".StyleForm").find("a.addToBagCTA")
                    : sizeSelectorElement.closest(".StyleForm").find("a.nxbtn")[0];
                var $personaliseAddToBagButton = sizeSelectorElement.closest(".StyleForm").find("a.PersonaliseAddToBagButton");
                sizeSelectorElement.closest(".StyleForm").find(".PersonaliseServiceDownMessage").hide();
                var sizeSelectorOptionSelected = sizeSelectorElement.find("option:selected");
                if ($style.hasClass("FirstItem") && sizeSelectorOptionSelected && sizeSelectorOptionSelected.data("stockstatus")) {

                    EnhancedEcommerceHelper.removeStockStatusfromDatalayer();
                    dataLayer.push({ "stockStatus": sizeSelectorOptionSelected.data("stockstatus") });

                }

                if (Next.Settings.Channel.BuyNow != null && Next.Settings.Channel.BuyNow.IsEnabled) {
                    if (sizeSelectorOptionSelected.hasClass("SoldOut") || sizeSelectorOptionSelected.hasClass("SaleSoldOut") || sizeSelectorOptionSelected.hasClass("ComingSoon")) {
                        $(".BuyNowLink").addClass("disabled");
                    } else {
                        $(".BuyNowLink").removeClass("disabled");
                    }
                }

                if (sizeSelectorElement.find("option:selected").hasClass("SoldOut") || sizeSelectorOptionSelected.hasClass("SaleSoldOut")) {

                    var enableSoldOutStatusChange = (Next.Settings.Channel.EnableSoldOutStatusChange || false) === true;
                    var outOfStockMessage = enableSoldOutStatusChange && sizeSelectorOptionSelected.hasClass("SoldOut")
                        ? nxt.jstranslations.productpage.outofstockmessagealternative
                        : nxt.jstranslations.productpage.outofstockmessage || "This item is currently out of stock"

                    if (Next.Settings.Channel.PersonalisedGiftsEnabled && sizeSelectorElement.data("personalise") === "Y") {
                        $personaliseAddToBagButton.removeClass("Enabled")
                            .addClass("disabled")
                            .attr("data-description", outOfStockMessage);
                    }

                    $($button).removeClass("Enabled")
                        .addClass("disabled")
                        .attr("data-description", outOfStockMessage);
                    if (Next.Settings.UI.DesktopQtySelectorEnabled) {
                        ProductPage.Styles.DisableQtySelector(sizeSelectorElement.closest(".StyleForm"), true);
                    }

                    var viewportWidth = $(window).width();


                    var settings =
                    {
                        customCSS: "height: 32px",
                        errorMessage: true,
                        align: viewportWidth < 1280 ? "bottom" : "right",
                        marginLeft: viewportWidth < 1280 ? 100 : 30,
                        width: (Next.Settings.UI.ReskinPDP || Next.Settings.UI.IsInnovationDesktopResponsiveEnabled) ? 120 : 115,
                        marginTop: viewportWidth < 1280 ? -5 : isIpad ? 6 : 18,
                        closeOnDialogueOut: true,
                        autoClose: true
                    };

                    $($button).mouseenter(function () {
                        var viewportWidth = $(window).width();
                        settings.align = viewportWidth < 1280 ? "bottom" : "right";
                        if (ProductPage.Vars.IsChanelBrandPDPEnabled) {
                            settings.marginLeft = viewportWidth < 1280 ? 53 : 20;
                        }
                        else {
                            settings.marginLeft = viewportWidth < 1280 ? 100 : 30;
                        }
                        settings.marginTop = viewportWidth < 1280 ? -5 : isIpad ? 6 : 18;


                        showDialoguePopUp(this, settings);
                    });

                    if (Next.Settings.Channel.PersonalisedGiftsEnabled && sizeSelectorElement.data("personalise") === "Y") {
                        $personaliseAddToBagButton.mouseenter(function () {
                            var viewportWidth = $(window).width();
                            var isChevronEnabled = $personaliseAddToBagButton.hasClass("icon-arrow-white-down-right") ? true : false;

                            settings.align = viewportWidth < 1280 ? "bottom" : "right";
                            settings.marginLeft = isChevronEnabled ? (viewportWidth < 1280 ? 100 : 45) : (viewportWidth < 1280 ? 100 : 30);
                            settings.marginTop = viewportWidth < 1280 ? -5 : isIpad ? 6 : 18;

                            showDialoguePopUp(this, settings);
                        });
                    }


                } else if (sizeSelectorElement.find("option:selected").hasClass("ComingSoon")) {
                    $($button).unbind("mouseenter mouseleave")
                        .addClass("disabled");
                    if (Next.Settings.UI.DesktopQtySelectorEnabled) {
                        ProductPage.Styles.DisableQtySelector(sizeSelectorElement.closest(".StyleForm"), true);
                    }

                    if (Next.Settings.Channel.PersonalisedGiftsEnabled && sizeSelectorElement.data("personalise") === "Y") {
                        $personaliseAddToBagButton.unbind("mouseenter mouseleave").addClass("disabled");
                    }
                } else {
                    $($button).unbind("mouseenter mouseleave")
                        .removeClass("disabled")
                        .addClass("Enabled");
                    if (Next.Settings.UI.DesktopQtySelectorEnabled) {
                        ProductPage.Styles.DisableQtySelector(sizeSelectorElement.closest(".StyleForm"), false);
                    }

                    if (Next.Settings.Channel.PersonalisedGiftsEnabled && sizeSelectorElement.data("personalise") === "Y") {
                        var oldBanner = display_old_ie_banner(11);
                        if (oldBanner) {
                            $personaliseAddToBagButton.unbind("mouseenter mouseleave").addClass("disabled");
                        }
                        else {
                            //check if the item is valid for editing and viewing however the service is switched off.
                            if (!Next.Settings.Channel.RealTimePersonalisedGiftsEnabled && parseInt(sizeSelectorElement.data("personalisedgifttheme")) == PersonalisedGiftsThemeEnum.BasicModal) {
                                $(".PersonaliseServiceDownMessage").css("display", "block");
                                $personaliseAddToBagButton.unbind("mouseenter mouseleave").addClass("disabled");
                            }
                            else {
                                $personaliseAddToBagButton.unbind("mouseenter mouseleave").removeClass("disabled").addClass("Enabled");
                            }
                        }
                    }

                    var customItem = sizeSelectorElement.data("personalise") === "Y" && sizeSelectorElement.data("fulfilmenttype") === "M";
                    if (customItem) {
                        if (display_old_ie_banner(11)) {
                            //Hide iframe
                            setTimeout(function () {
                                $('#customItemIframe').hide();
                                $('#customItemIframeLoader').hide();

                                $(".old-ie").css("display", "block");
                            }, 1);

                        }
                    }

                    //Pass in the minimum version supported
                    function display_old_ie_banner(minVersionSupported) {
                        var ie = (!!window.ActiveXObject && +(/msie\s(\d+)/i.exec(navigator.userAgent)[1])) || NaN;
                        if (!isNaN(ie) && ie < minVersionSupported) {
                            $(".old-ie").css("display", "block");
                            return true;
                        }
                        return false;
                    }

                    if (!ignoreRecentlyViewed) {
                        ProductPage.RecentlyViewed.SaveViewedItem(true, sizeSelectorElement.closest("article"));
                    }
                }

                if (Next.Settings.Channel.SoldoutColourChipStyle !== "") {
                    var $colourChipsElement = $style.find("ul.colourChips");
                    var $sizeChipContainer = $style.find(".sizeChipsContainer");
                    var isItemSoldout = false;

                    if ($colourChipsElement.parents(".Chips").length > 0 && $colourChipsElement.parents(".Chips").is(":visible")) {
                        var $activeColourChip = $colourChipsElement.find("li.active");
                        if ($activeColourChip.length > 0) {
                            isItemSoldout = $activeColourChip.hasClass("SoldoutChip");
                        }
                    } else if ($sizeChipContainer.length === 1 && $(".dk_container.SizeSelector").length === 1 && !ProductPage.Styles.SplitSize.IsEnabled($style)) {
                        isItemSoldout = $sizeChipContainer.parent(".Chips.formControls").css("display") === "none"
                                        && $(".dk_container.SizeSelector").parent().parent().css("display") === "none";
                    }

                    if (isItemSoldout) {
                        ProductPage.TogglePDPDisplayForSoldoutItem(false);
                    }
                }

                ProductPage.Styles.TrackGASelectionChanged("size", sizeSelectorElement);

                var dataFit = $style.find('.fitList .dk_option_current .dk_dropdown_option').first().attr('data-dk-dropdown-value');

                if (typeof dataFit == "undefined" || dataFit == "") {
                    var fitListText = $style.find('.fitList .dk_toggle').first().text();
                    dataFit = (typeof fitListText == "undefined") ? "" : fitListText;

                    // if fit chips are enabled, the above returns the empty string
                    if (dataFit == "") {
                        var $fitChip = $style.find("ul.fitChips li.active");
                        dataFit = $fitChip.data("value");
                    }
                }

                $style.attr("data-fit", dataFit);

                // If there is no colour dropdown / chip or shot data to get the colour from (usually the case with items that are 1 colour only),
                // then DO NOT set the data-colour attribute on the style as it will replace it with an empty string and break anything that uses this
                // attribute.
                var colourDataAvailable = false;

                var dataColour = $style.find('.colourList .dk_option_current .dk_dropdown_option').first().text();

                if (typeof dataColour == "undefined" || dataColour == "") {
                    var colourListText = $style.find('.colourList .dk_toggle').first().text();

                    if (typeof colourListText != "undefined" && dataColour != "") {
                        dataColour = colourListText;
                        colourDataAvailable = true;
                    }

                } else {
                    colourDataAvailable = true;
                }

                if (!colourDataAvailable) {
                    var $colourChip = $style.find("ul.colourChips li.active");
                    dataColour = $colourChip.data("value");
                    if (typeof dataColour != "undefined" && dataColour !== "") {
                        colourDataAvailable = true;
                    }
                }

                if (colourDataAvailable) {
                    $style.attr("data-colour", dataColour);
                }

                if (EnableFavourites) {

                    if ($style.length) {
                        /* Need to call .context at this point */
                        var dataOptionNo = !jqueryUpgradeEnabledOnPage ?
                            $style.find('.Selector.SizeSelector .dk_option_current').first().context.value :
                            $style.find('.Selector.SizeSelector .dk_option_current').first()[0].value;

                        if (typeof dataOptionNo == "undefined") {
                            if (typeof $style.attr("data-optionnumber") == "undefined" && $style.attr("data-optionnumber") == "") {
                                dataOptionNo = "-1";
                            }
                        }

                        // modified for both pdp chips and asm if no size option value set even if there is size
                        if (pdpChipsEnabled && dataOptionNo != sizeSelectorElement.val()) {
                            dataOptionNo = sizeSelectorElement.val() == "" ? -1 : sizeSelectorElement.val();
                        }
                        $style.attr("data-optionnumber", dataOptionNo);

                        var chain = $style.find(".hdnChain").val();

                        if (typeof chain == "undefined") {
                            chain = "";
                        }

                        $style.attr("data-chain", chain);

                        NextFavourites.BindEvents();

                        if (NextFavourites.Data.ShoppingListItems != undefined || NextFavourites.Data.ShoppingListItems != null) {
                            NextFavourites.FillFavouriteItems();
                        }
                    }
                }
            },
            AddItem: function (link) {
                //<summary>Add item to bag - including warranty</summary>

                var self = this;
                var $link = $(link);

                if ($link.hasClass("disabled") || (pdpChipsEnabled && ProductPage.Vars.$styles == null)) {
                    return false;
                }

                Button.UpdateUI($link, {
                    loading: true
                });
                if (pdpChipsEnabled && ProductPage.Styles.pdpChipsShow()) {
                    $(".PDPChips").css("pointer-events", "none");
                }
                //Add to recently viewed 
                var path = window.location.pathname;
                var itemJson = {
                    path: path
                };

                //Get parent form/container - all corresponding controls for this item are within this element
                var $parentForm = $link.closest(".StyleForm");

                var itemNumber = $parentForm.closest("article").data("targetitem");
                if (pdpChipsEnabled && ProductPage.Styles.pdpChipsShow()) {
                    var defItemNum = $parentForm.closest("article").find("section.StyleCopy > div.StyleMeta > div.ItemNumber").text();
                    if (defItemNum) {
                        if (defItemNum.toUpperCase() !== itemNumber.toUpperCase()) {
                            itemNumber = defItemNum;
                        }
                    }
                }

                //Google Analytics for Add To Bag 
                TrackGAEvent("PDP", "Link Clicked", "pdp-item-added-to-bag_" + itemNumber);

                var $styleDdl = $parentForm.find("select.subStyleList");
                var fullItemNumber = "";
                if ($styleDdl.val()) {
                    fullItemNumber = $styleDdl.val();
                } else {
                    fullItemNumber = $parentForm.find("input.hdnItmId").val();
                }

                if (pdpChipsEnabled && ProductPage.Styles.PDPColourChipsEnabled() && ProductPage.Styles.pdpChipsShow()) {
                    var $colourChips = $parentForm.find("ul.colourChips");
                    if ($colourChips.length > 0) {
                        var chpItmNum = $colourChips.find("li.active").data("itemnumber")
                        if (chpItmNum) {
                            fullItemNumber = fullItemNumber != chpItmNum ? chpItmNum : fullItemNumber;
                        }
                    }
                }
                itemJson.itemNumber = fullItemNumber;
                if (pdpSplitSizeEnabled && !ProductPage.Styles.SplitSize.IsEnabled($link.parents("article.Style")) && ProductPage.Styles.SplitSize.SplitFitEnabled()) {
                        var CurrFit = $parentForm.find(".fitChips li.chipItem.active").data("value");
                        var sizeSelector = $parentForm.find("select[id='Size-" + itemNumber + CurrFit +"']");
                    }
                else {
                    var sizeSelector = $parentForm.find("select[id='Size-" + itemNumber + "']");
                    }
                if ((!self.ValidateControl(sizeSelector)) || $(":selected", sizeSelector).hasClass("SoldOut")) {
                    if (ProductPage.Styles.SplitSize.IsEnabled($link.parents("article.Style"))) {
                        ProductPage.Styles.SplitSize.SetValidationError(sizeSelector);
                    }
                    ProductPage.Styles.DisplaySizeChipsValidationMessage(itemNumber);
                    Button.UpdateUI($link, {
                        loading: false
                    });
                    if (pdpChipsEnabled && ProductPage.Styles.pdpChipsShow()) {
                        $(".PDPChips").css("pointer-events", "auto");
                    }
                    return false;
                }
                EnhancedEcommerceHelper.pushAddtoBagClickToDataLayer($parentForm.closest("article"))
                var size = sizeSelector.val();
                if (size !== "") {
                    itemJson.Size = size;
                }

                RecentlyViewed.addItem(itemJson);

                //Check for warranty item
                var addWithWarranty = true;
                var warrantyWrapperName = ".ParentItem" + fullItemNumber;
                var ddlWarantyItem = $parentForm.find(warrantyWrapperName).find("select.ddlWarantyItem");
                var hdnWarranty = $parentForm.find(warrantyWrapperName).find("input.hdnWarranty");


                var shortItemNumber = fullItemNumber.replace(/-/g, "");
                var linkClass = "tempClass" + shortItemNumber;
                $link.addClass(linkClass);

                if (Next.Settings.Channel.ChannelTheme && Next.Settings.Channel.ChannelTheme.toLowerCase() === "preview") {
                    shortItemNumber = shortItemNumber + ($('#hdnPublication').val() || '')
                }

                if ($(ddlWarantyItem).val() && $(hdnWarranty).val()) {
                    var warantyOption = $(ddlWarantyItem).val();
                    if (warantyOption !== "0") {
                        //Add the item with warranty
                        var warantyId = $(hdnWarranty).val().replace(/-/g, "");
                        NextBasket.ItemAddWarranty(shortItemNumber, size, warantyId, warantyOption, function () {
                            var targetClass = "." + linkClass;
                            $(targetClass).removeClass("disabled");

                            Button.UpdateUI($(targetClass), {
                                loading: false
                            });
                            if (pdpChipsEnabled && ProductPage.Styles.pdpChipsShow()) {
                                $(".PDPChips").css("pointer-events", "auto");
                            }
                        });
                    } else {
                        addWithWarranty = false;
                    }
                } else {
                    addWithWarranty = false;
                }

                //No warranty - just add the item
                if (!addWithWarranty) {

                    var useDefaultA2B = true;
                    var $hdnChain = $parentForm.find("input.hdnChain");
                    var chain = $hdnChain.val();
                    var isQtySelectorEnabled = Next.Settings.UI.DesktopQtySelectorEnabled || Next.Settings.Channel.PDPQtyDropdownFeatures.Enabled;
                    var qtyElement = Next.Settings.Channel.PDPQtyDropdownFeatures.Enabled ? "select.pdp-item-quantity-dropdown" : ".quantity-selector-input";
                    var qtyCurrVal = isQtySelectorEnabled ? (parseInt($parentForm.find(qtyElement).val(), 10) || 1) : 1;
                    if (modalMode === true) {
                        if (ProductPage.Vars.SingleModalMode) {
                            if (window.parent && window.parent.ModalProductPageHelper) {
                                useDefaultA2B = false;
                                var location = window.location.pathname + "/" + shortItemNumber;
                                window.parent.ModalProductPageHelper.ModularPDPAddToBag(shortItemNumber, size, chain, qtyCurrVal, location);
                            }
                        }
                        else if (window.parent && window.parent.TabbedContentPage) {
                            useDefaultA2B = false;
                            window.parent.TabbedContentPage.ModalAddToBag(shortItemNumber, size, chain, qtyCurrVal);
                        }
                    }

                    if (useDefaultA2B) {
                        if (itemJson.path.indexOf(shortItemNumber) == -1) {
                            if (itemJson.path.indexOf('style') > -1) {
                                var urlPathSegments = ModularPDPHelper.getSegmentOptions(window.location.pathname);
                                urlPathSegments.segments[urlPathSegments.segmentsCount - 1] = shortItemNumber;
                                itemJson.path = urlPathSegments.segments.join('/');
                            } else {
                                itemJson.path = itemJson.path + '/' + shortItemNumber;
                            }
                        }
                        NextBasket.ItemAdd(shortItemNumber, size, qtyCurrVal, chain, false, function () {
                            var targetClass = "." + linkClass;
                            $(targetClass).removeClass("disabled");

                            Button.UpdateUI($(targetClass), {
                                loading: false
                            });
                            if (pdpChipsEnabled && ProductPage.Styles.pdpChipsShow()) {
                                $(".PDPChips").css("pointer-events", "auto");
                            }
                            // Common fix for Add To Bag button enabled for currently unavailable products, if we change the product before add to bag complete
                            var addToBagSection = $parentForm.find($(".AddToBag")).find("a");
                            var $addToBagButton = $(addToBagSection[0]);
                            if ($(":selected", sizeSelector).hasClass("SoldOut") || $(":selected", sizeSelector).hasClass("SaleSoldOut")
                                || $(":selected", sizeSelector).hasClass("ComingSoon")) {
                                $addToBagButton.removeClass("Enabled")
                                    .addClass("disabled");
                            }
                            else {
                                $addToBagButton.removeClass("disabled").addClass("Enabled");
                            }

                            if (Next.Settings.Channel.AddtoBagButtonTextUpdate) {
                                var $selectedArticle = $("article .ItemNumber:contains('" + itemNumber + "')");
                                var $parentArticle = $selectedArticle.closest("article");
                                var $targetButton = $parentArticle.find($(".AddToBag"));
                                ProductPage.Styles.ToggleTickWrapper($targetButton, true);
                                var desktopTickTimer = setTimeout(function req() {
                                    ProductPage.Styles.ToggleTickWrapper($targetButton, false);
                                    $targetButton.show();
                                    clearTimeout(desktopTickTimer);
                                }, 3000);


                            }

                        }, "", itemJson.path);
                    }
                }

                return true;
            },
            NotifyItem: function (link) {
                var _this = this;
                var $link = $(link);

                if ($link.hasClass("disabled")) {
                    return false;
                }

                var $parentForm = $link.closest(".StyleForm");
                var $parentArticle = $parentForm.closest(".Style");

                var $styleDdl = $parentForm.find("select.subStyleList");
                var fullItemNumber = "";
                if ($styleDdl.val()) {
                    fullItemNumber = $styleDdl.val();
                } else {
                    fullItemNumber = $parentForm.find("input.hdnItmId").val();
                }
                var productTitle = $parentArticle.find("section.StyleCopy > div.StyleHeader > div.Title").text();
                Notify.Vars.ItemNumber = fullItemNumber;
                Notify.Vars.ProductTitle = productTitle;
                Notify.Vars.Page = "Productpage";
                Notify.Vars.StyleNumber = $parentArticle.data("stylenumber");
                Notify.OpenPopup();
            },
            ValidateControl: function (control) {
                //<summary>Add to bag validation</summary>

                var viewportWidth = $(window).width();

                var errorDialogSettings =
                {
                    customCSS: "height: 26px",
                    errorMessage: true,
                    align: "bottom",
                    customMarginLeft: 180,
                    width: 120,
                    customMarginTop: (Next.Settings.UI.ReskinPDP || Next.Settings.UI.IsInnovationDesktopResponsiveEnabled) ? -12 : -14,
                    closeOnDialogueOut: true,
                    autoClose: false
                };

                if (viewportWidth < 1025) {
                    errorDialogSettings.customMarginTop = (Next.Settings.UI.ReskinPDP || Next.Settings.UI.IsInnovationDesktopResponsiveEnabled) ? -8 : -10;
                    errorDialogSettings.customMarginLeft = 170;
                }

                return $(control).validateControl("validate", errorDialogSettings);
            },
        },
        BuyNowItemCTA: function (link, requiresAuth, buttonClass) {
            var validate = ProductPage.Styles.AddToBagCTA.ValidateControl; //uses addToBag.Validate method to check size has been selected
            var $link = $(link);
            Button.UpdateUI($link, {
                loading: true
            });
            var path = window.location.pathname;

            var $parentForm = $link.closest(".StyleForm");
            var $styleDdl = $parentForm.find("select.subStyleList");
            var itemNumber = $styleDdl.val() || $parentForm.find("input.hdnItmId").val();
            var sizeSelector = $parentForm.find("select[id='Size-" + itemNumber + "']");
            var optionNo = sizeSelector.val();
            if ((!validate(sizeSelector)) || $(":selected", sizeSelector).hasClass("SoldOut")) {
                Button.UpdateUI($link,
                    {
                        loading: false
                    });
                return false;
            }
            function appendQueryString(url, queryVars) {
                var firstSeperator = (url.indexOf('?') == -1 ? '?' : '&');
                var queryStringParts = new Array();
                for (var key in queryVars) {
                    queryStringParts.push(key + '=' + queryVars[key]);
                }
                var queryString = queryStringParts.join('&');
                return url + firstSeperator + queryString;
            }

            if (requiresAuth) {
                var url = Next.Settings.Channel.SecureSiteUrl + "/secure/accounts/transfer/buynowcta";
                var queryVars = { 'pId': itemNumber, 'optionNo': optionNo, 'shot': path };
                window.location.href = appendQueryString(url, queryVars);
            }
            else {
                if (preventBuyNowLoop) {
                    isRedirectFromAccountPortal = false;
                }
                //Force item to be selected (scenario if we have multiple buttons on the page)
                //Remove Selected class from any article first
                $("article").removeClass("Selected");
                var $itemArticle = $parentForm.closest("article");
                $itemArticle.addClass("Selected");

                $link.closest("." + buttonClass).find('[nx-tray]').each(function () {
                    $(this).trigger("openTray");
                });
            }
        },
        AddToBagContainer: {
            SetWidth: function () {
                var containerWidth = $('.dk_container').width();
                $(".AddToBag").css("width", containerWidth);
            }
        },
        ToggleTickWrapper: function ($button, shown) {
            if (shown) {
                $button.find(".tickWrapperCls").show();
                $button.find($("a.btn-addtobag.add-to-bag")).text("ADDED");
                $button.find($("a.btn-addtobag.add-to-bag")).css("pointer-events", "none");
            } else {
                $button.find(".tickWrapperCls").hide();
                $button.find($("a.btn-addtobag.add-to-bag")).text("ADD TO BAG");
                $button.find($("a.btn-addtobag.add-to-bag")).css("pointer-events", "auto");
            }
        },
        ItemChanged: function (previousItemNumber, makeCallToDynamicDiv, initialLoad = false) {
            if (typeof makeCallToDynamicDiv === 'undefined') { makeCallToDynamicDiv = true; }
            var self = this;
            var IsNextDayDeliveryItem = false;

            // Get the current style and target item
            var $style = ProductPage.Vars.$styles.filter(".Selected");
            var itemNumber = $style.data("targetitem");

			if (Next.Settings.Channel.IsPikcells360DegViewerEnabled) {
				var isThreeSixtyButtonVisible = $(".ZoomComponent .shotWrapper").find(".threeSixtyDesktop:visible").length > 0;
				if (isThreeSixtyButtonVisible) {
					$(".ZoomComponent .shotWrapper").find(".threeSixtyDesktop").hide();
				}
			}

            if (jsonLoaded === false) {
                if (jsonInitalTry === true) {
                    ProductPage.LoadShotJson(3, false, $style.data("stylenumber"), previousItemNumber);
                } else {
                    ProductPage.LoadShotJson(0, true, $style.data("stylenumber"), previousItemNumber);
                }
            }

            if ($("#pdpnav")) {
                $(".pdp-tab.active a").attr("data-target", itemNumber);
                $(".pdp-tab.active a").data("target", itemNumber);
            }

            if (Next.Settings.Channel.EnableClientsideSizeDropdown) {
                if (pdpSplitSizeEnabled || ProductPage.Styles.SplitSize.IsEnabled($style)) {
                    $("div.splitSizeMessage[for='Size-" + previousItemNumber + "']").attr("for", "Size-" + itemNumber);
                    $(".splitSizeContainer[for='Size-" + previousItemNumber + "']").attr("for", "Size-" + itemNumber);
                }
                $('article[data-targetitem=\"' + previousItemNumber + '\"]').attr("data-targetitem", itemNumber);
                $("select.SizeSelector#Size-" + previousItemNumber).attr("id", "Size-" + itemNumber);
                $("div.dk_container#dk_container_Size-" + previousItemNumber).attr("id", "dk_container_Size-" + itemNumber);
                $("label[for='Size-" + previousItemNumber + "']").attr("for", "Size-" + itemNumber);
                $(".Chips.formControls").find("#Size-" + previousItemNumber).attr("id", "Size-" + itemNumber);
            }


            var itemData = ProductPage.Styles.GetPageDataForItem(itemNumber);

            if (Next.Settings.Channel.ChannelId == "NEXT_IL" && itemData.item.ShotImage) {
                $("meta[name='twitter:image']").attr('content', itemData.item.ShotImage);
            }

            var sizeChipsEnabled = (itemData.fit.SizeChipsEnabled && !pdpChipsEnabled) || (pdpChipsEnabled && itemData.item.PDPChipsSizeEnabled && ProductPage.Styles.pdpChipsShow());

            //if (Next.Settings.Channel.CountdownTimers) {
            //    var cdtStartDate = ProductPage.Vars.CountdownTimerServiceResponse.StartInUtc;
            //    var cdtEndDate = ProductPage.Vars.CountdownTimerServiceResponse.EndInUtc;
            //    var countdown = new Countdown();

            //    $.each(ProductPage.Vars.ItemData, function (iStyle, style) {
            //        $.each(style.Fits, function (iFit, fit) {
            //            $.each(fit.Items, function (iItem, item) {
            //                if (item.ItemNumber === itemNumber.toUpperCase()) {
            //                    IsNextDayDeliveryItem = item.IsNextDayDeliveryItem;
            //                }
            //            });
            //        });
            //    });

            //    if (IsNextDayDeliveryItem) {
            //        var isEligible = countdown.IsEligible(cdtStartDate, cdtEndDate);
            //        if (isEligible && !countdown.IsRunning()) {
            //            countdown.loadCountdownTimer();
            //        }
            //    }
            //    else {
            //        if (countdown.IsRunning()) {
            //            countdown.hide();
            //        }
            //    }
            //}

            if (!Next.Settings.Channel.EnableClientsideSizeDropdown) {
                $style.find("select.SizeSelector").parents("div.DropDown").hide();
            }

                if (pdpSplitSizeEnabled && !ProductPage.Styles.SplitSize.IsEnabled($style) && ProductPage.Styles.SplitSize.SplitFitEnabled()) {
                    var CurrFit = $style.find(".fitChips li.chipItem.active").data("value");
                    var $currentSizeSelector = $("select.SizeSelector#Size-" + itemNumber + CurrFit);
                }
            else {
                var $currentSizeSelector = $("select.SizeSelector#Size-" + itemNumber);
            }
            var itemSizeSelector = $currentSizeSelector.parents("div.DropDown");
            itemSizeSelector.show();

            if (sizeChipsEnabled && !Next.Settings.Channel.EnableClientsideSizeDropdown) {
                $style.find("div.sizeChipsContainer").parents("div.Chips").hide();
                var $currentSizeChips = $("div.sizeChipsContainer#Size-" + itemNumber);
                var itemSizeChips = $currentSizeChips.parents("div.Chips");
                itemSizeChips.show();
                if (pdpSplitSizeEnabled && !ProductPage.Styles.SplitSize.IsEnabled($style)) {
                    itemSizeChips.hide();
                }
            }
            else {
                if (pdpChipsEnabled && !Next.Settings.Channel.EnableClientsideSizeDropdown) {
                    $style.find("div.sizeChipsContainer").parents("div.Chips").hide();
                    var $currentSizeChips = $("div.sizeChipsContainer#Size-" + itemNumber);
                    var itemSizeChips = $currentSizeChips.parents("div.Chips");
                    itemSizeChips.hide();
                }
            }

            var previousSplitSizeContainer = $style.find("div.splitSizeContainer div[for=Size-" + previousItemNumber + "]").parent(".splitSizeContainer");
            var currentSplitSizeContainer = $style.find("div.splitSizeContainer div[for=Size-" + itemNumber + "]").parent(".splitSizeContainer");

            if (!Next.Settings.Channel.EnableClientsideSizeDropdown) {
                if (ProductPage.Styles.SplitSize.IsEnabled($style)) {
                    previousSplitSizeContainer.hide();
                    currentSplitSizeContainer.show();
                }
                else {
                    previousSplitSizeContainer.hide();
                    currentSplitSizeContainer.hide();
                }
            }

            //Show warranty for this item
            self.ShowWarranty($style, itemNumber);
            var previousOptionNumber = previousItemNumber ? $("select.SizeSelector#Size-" + previousItemNumber).val() : null;
            var $PreviousSelection = previousItemNumber ? $("select.SizeSelector#Size-" + previousItemNumber) : null;
            var $CurrentSelection = itemNumber ? $("select.SizeSelector#Size-" + itemNumber) : null;
            var SelectedOptionNumber = $CurrentSelection.val();
            if (pdpChipsEnabled && ProductPage.Styles.SplitSize.IsEnabled($style) ) {
                if (pdpSplitSizeEnabled && ProductPage.Styles.SplitSize.SplitFitEnabled() && ProductPage.Vars.isFitChanged) {
                    SelectedOptionNumber = '';
                    $CurrentSelection.dropkick("setValue", SelectedOptionNumber);
                    ProductDetails.Styles.SelectOption(itemNumber, SelectedOptionNumber);
                    ProductPage.Styles.SplitSize.DeselectChip($(".splitSizeChip.active"), $CurrentSelection);
                    ProductPage.Vars.isFitChanged = false;
                }
                else {
                    if (previousItemNumber != itemNumber) {
                        $CurrentSelection.find("option").each(function () {
                            if ($(this).attr("data-size") == $PreviousSelection.find(':selected').data("size")) { //$PreviousSelection.data("lastSelOption")
                                SelectedOptionNumber = $(this).val();
                            }
                        });
                        if (SelectedOptionNumber != "") {
                            ProductDetails.Styles.SelectOption(itemNumber, SelectedOptionNumber);
                        }
                        else {
                            $CurrentSelection.dropkick("setValue", "");
                        }
                    }
                    else
                    {
                        var $splitSizeContainers = $style.find("div.Chips.splitSizeContainer[for=Size-" + itemNumber + "]");
                        if ($splitSizeContainers.find(".splitSizeRow.DropDown:visible").length > 0) {
                            $splitSizeContainers.find(".splitSizeRow.DropDown:visible").each(function () {
                                $(this).prop("selectedIndex", 0);
                                $(this).parent().find(".dk_label").text("Choose Size");
                                $(this).val("Choose Size");
                            });
                        }
                        $CurrentSelection.dropkick("setValue", SelectedOptionNumber);
                        ProductDetails.Styles.SelectOption(itemNumber, SelectedOptionNumber);
                    }

                }


            }
            else {
                ProductDetails.Styles.SelectOption(itemNumber, previousOptionNumber);
            }

            if (sizeChipsEnabled) {
                ProductDetails.Styles.ChipsChange(itemNumber, previousOptionNumber);
            }
            if (ProductPage.Styles.SplitSize.IsEnabled($style)) {
                ProductPage.Styles.SplitSize.UpdateSplitSizeSelection($currentSizeSelector);
                if (pdpSplitSizeEnabled) {
                    ProductPage.Styles.SplitSize.SetSplitSizeInitialSelection($style);
                    if (ProductPage.Styles.SplitSize.IsResetDropdown(itemNumber))
                        ProductPage.Styles.SplitSize.ResetDropDownChipVisibility(itemNumber, null);
                }
            
                //to show and hide size chips and to retain selected chips
                if (pdpChipsEnabled) {
                    var $style = pdpChipsEnabled ? $currentSizeSelector.parents("article.Style") : ProductPage.Vars.GetCurrentStyleElement();
                    var sizeId = $currentSizeSelector.attr('id');
                    var $splitSizeContainer = $style.find(".splitSizeContainer[for=" + sizeId + "]");
                    if ($splitSizeContainer.length > 0) {
                        var $SplitSizeContainers = $splitSizeContainer
                            .find(".splitSizeRow .splitSizeChips");
                        var $SplitSizeContainersDDL = $splitSizeContainer
                            .find(".splitSizeRow.DropDown:visible").length;
                        $SplitSizeContainers.each(function () {
                            ProductPage.Styles.SplitSize.BindClickEventForChips($(this).attr("for"), $style);
                            //var x = $(this).parent().parent().find("li:visible").length;
                            var x = $(this).parent().parent().find('li:not([style*="display: none"])').length;
                            if (!(x > 0) && !($SplitSizeContainersDDL > 0)) {
                                $(this).parent().parent().hide();
                            }
                            else {
                                $(this).parent().parent().show();
                            }
                        });
                    }

                }
            }

            if (!Next.Settings.Channel.EnableClientsideSizeDropdown) {
                ProductDetails.Styles.RefreshOptionStockStatus($style, itemNumber);
            }

            ProductPage.Styles.HideSizeChipsWhenOverMaxLines(itemNumber);

            //Tidy up ID
            var shortItemNumber = itemNumber.replace("-", "").toLowerCase().substring(0, 6);

            //Build new image URL - cdnURL is set as a global variable in parent page
            var newImgUrl = cdnURL + "/Common/Items/Default/Default/ItemImages/AltItemThumb/" + shortItemNumber + ".jpg";

            newImgUrl = this.OverrideImagePath(newImgUrl);

            //Update display image
            $style.find(".StyleImages").find("img").attr("src", newImgUrl);

            //Update item number display
            var $styleCopy = $style.find(".StyleCopy");
            $styleCopy.find(".ItemNumber").text(itemNumber.substring(0, 7));
            if (Next.Settings.Channel.IsStackedPDPEnabled) {
                if ($(event.target).closest("article").attr("data-targetitem") !== itemNumber.substring(0, 7)) {
                    $(event.target).closest("article").attr("data-targetitem", itemNumber.substring(0, 7));
                }
            }

            //Update Sizing Guide's item number
            if (Next.Settings.Channel.SizingGuideEnabled && !pdpChipsEnabled) {
                $style.find(".SizeGuideLink").attr("data-item-number", itemNumber.substring(0, 7));
            }

            //Update whatsapp link item number
            if (Next.Settings.Channel.PdpContactUsHTMLIdentifier.Enabled) {
                var productnameforwhatsapp = $style.data("productnameforwhatsapp");
                var whatsappButton = $('.btn.btn-contact-us.whatsapp-button');
                var whatsappLinkTemplate = Next.Settings.Channel.PdpContactUsHTML.WhatsAppUrlTemplate;
                if (whatsappButton) {
                    whatsappButton.attr("href", whatsappLinkTemplate.replace("{ItemNumber}", itemNumber.substring(0, 7)).replace("{ProductTitle}", productnameforwhatsapp));
                }
            }

            //Update intelligent recommendations
            if (Next.Settings.Channel.YouMayAlsoLikeIsEnabled && Next.Settings.Channel.SelfStartForYouMayAlsoLikeIsEnabled) {
                if (window.IntelRecs) {
                    window.IntelRecs.LoadRecommendations(itemNumber.substring(0, 7), Next.Settings.Channel.YouMayAlsoLikeAlgorithm);
                }
            }

            //Update review count and review click events

            $styleCopy.find(".StyleMeta").addClass("Meta" + shortItemNumber.toUpperCase());

            //Update Collect In Store Today link id
            if (Next.Settings.Channel.IsCollectInStoreTodayEnabled) {
                $styleCopy.find(".CollectInStoreLink").attr("id", "collect-in-store-link-" + itemNumber);
            }

            //Update item level data. Don't change for non-Pim items.
            var styleNumber = $style.data("stylenumber");
            if (styleNumber !== "" && styleNumber != null) {

                var $logos = $styleCopy.find(".logos");
                var $logosTable = $logos.find("table");
                var $multibuys = $styleCopy.find(".MultibuyTypes");
                var $multibuysTable = $multibuys.find("table");

                $logosTable.empty();
                $multibuysTable.empty();

                $.each(ProductPage.Vars.ItemData, function (iStyle, style) {
                    $.each(style.Fits, function (iFit, fit) {
                        $.each(fit.Items, function (iItem, item) {
                            if (item.ItemNumber === itemNumber.toUpperCase()) {
                                self.UpdateItemData($style, $styleCopy, style, item, initialLoad);
                            }
                        });
                    });
                });

                if (FeefoEnabled) {
                    setTimeout(function () {
                        PageReviews.GetReviewSummaries(shortItemNumber, ProductPage.Styles.Reviews.BindAnimatedReviewSummaries);
                    }, 200);
                }
            }

            if (ProductPage.Vars.IsBeautyPage) {
                ProductPage.Styles.SetColourChipSelection($style, itemNumber);
                if ($currentSizeSelector.children("option").length <= 0) {
                    itemSizeSelector.hide();
                }
            }
            //Append colour in header
            if (Next.Settings.Channel.PDPH1TitleColourAppend) {
                var productTitle = $currentSizeSelector.closest('.StyleCopy').find('#productTitleWithoutColour').attr('value');
                var selectedColour = ProductPage.Vars.$itemsContainer.find("select.colourList").find(':selected').text();
                var parentElement = $currentSizeSelector.closest(".StyleCopy");
                var titleElement = $currentSizeSelector.closest(".StyleCopy").find(".Title");
                if (parentElement.find(".Title h1").length > 0)
                    titleElement.find('h1').text(selectedColour + ' ' + productTitle);
                else if (parentElement.find(".Title h2").length > 0)
                    titleElement.find('a').text(selectedColour + ' ' + productTitle);
            }

            if (makeCallToDynamicDiv) {
                //Load DynamicDiv if enabled
                ProductPage.Styles.LoadContentForDynamicDiv($style);
            }

            // Update Url
            if (StyleWithScroll) {
                var url = $style.data("url").toLowerCase() + "#" + shortItemNumber;
                $style.find(".StyleImages a").attr("href", url);
                $style.find(".StyleHeader a").attr("href", url);
            }

            // Update data-colour attribute removed dependancy from PageReviews.
            $style.attr("data-colour", this.GetItemColour(false));

            var isSearchDescriptionTitleProvided = false;
            if (Next.Settings.Channel.PDPStyleDescription.EnableSearchDescriptionAsPDPTitle) {
                isSearchDescriptionTitleProvided = ProductPage.Styles.PDPStyleDescription.SetTitleAsSearchDescription($currentSizeSelector, itemData);
            }

            if (Next.Settings.Channel.EnableEmbeddedReviews) {
                // Reload embedded reviews at bottom of PDP, on change of fit/colour.
                if (Next.Settings.Channel.EnableEmbeddedReviews && !Next.Settings.Channel.DisableEmbeddedReviewsOnLocalLang) {

                    var embeddedReviewsContainer = $('#EmbeddedReviewsContainer');
                    embeddedReviewsContainer.attr('data-itemnumber', shortItemNumber);

                    var itemName = Next.Settings.Channel.PDPStyleDescription.EnableSearchDescriptionAsPDPTitle && isSearchDescriptionTitleProvided ?
                        ProductPage.Styles.PDPStyleDescription.GetItemNameForReviews(itemData) : PageReviews.GetItemName(false);
                    var itemColour = PageReviews.GetItemColour(false);
                    var itemFit = PageReviews.GetItemFit(false);

                    PageReviews.LoadReviewsHtml(shortItemNumber, 1, "", "", "", false, function (html) {
                        PageReviews.BindHtmlResponse(embeddedReviewsContainer, html, true, itemName, itemColour, itemFit, false, false, isSearchDescriptionTitleProvided);
                    });
                }
            }

            if (itemData.item) {
                if (itemData.item.SEOProductName) {
                    $style.attr("data-seoproductname", itemData.item.SEOProductName);
                }
            }

            this.ShowItem(false);
            $style.triggerHandler("StyleItemChanged");
            document.dispatchEvent(new CustomEvent("StyleItemChanged", { detail: { itemNumber: itemNumber } }));

            // only remove if itemNumber in dataLayer is different to current itemNumber, this prevents unnecessary data pushes
            if (dataLayer.some(elem => elem.event === 'ee-productView'
                && elem.ecommerce
                && elem.ecommerce.detail
                && elem.ecommerce.detail.products
                && elem.ecommerce.detail.products[0]
                && elem.ecommerce.detail.products[0].id
                && elem.ecommerce.detail.products[0].id.toLowerCase() != shortItemNumber)) {
                EnhancedEcommerceHelper.removeEventFromDatalayer('ee-productView');
            };

            EnhancedEcommerceHelper.pushProductViewToDataLayer();
            var $labelAvailabilityMessage = $style.find("div.sizeChipsContainer#Size-" + itemNumber).children("div.availabilityMessage").first();
            $labelAvailabilityMessage.text("");

            if (Next.Settings.Channel.PDPStyleDescription.EnableURLChange) {
                ProductPage.Styles.PDPStyleDescription.SetUrlWhenColorFitTypeOrVolumeChanged(itemData, ProductPage.Vars.ItemData, ProductPage.Vars.StyleWithEnabled);
            }
        },
        GetItemColour: function (isSofaItem) {
            var itemColour = "";
            if (isSofaItem) {
            }
            else {
                var $colourChip;
                var $selectedStyle = $("article.Style.Selected").first();
                if (Next.Settings.Channel.IsMobileSite) {
                    $colourChip = $('.ppm-colourchips').find('li.chipItem.active');
                }
                else {
                    $colourChip = $selectedStyle.find("ul.colourChips li.active");
                }
                itemColour = $colourChip.data("value");
                if (!itemColour) {
                    if (Next.Settings.Channel.IsMobileSite) {
                        itemColour = !PageReviews.isHomewarePDPPage ? $('#ppm-colourselector option:selected').text() : $("#colorSelector option:selected").text();
                    }
                    else {
                        itemColour = $selectedStyle.find('.colourList .dk_label').text();
                    }
                }
            }
            if (!itemColour || itemColour === "null")
                itemColour = "";
            return itemColour;
        },
        OverrideImagePath: function (strImagePath) {
            var amendedImagePath = strImagePath;
            if (Next.Settings.Channel.ProductImageSettings.Enabled) {
                if (Next.Settings.Channel.ProductImageSettings.ImageFolder) {
                    amendedImagePath = amendedImagePath.replace('/ItemImages/', '/ItemImages/' + Next.Settings.Channel.ProductImageSettings.ImageFolder + '/');
                    Next.Settings.Channel.ProductImageSettings.ImageDimensionOverrides.forEach(function (value) {
                        if (amendedImagePath.indexOf(value.ImageType) >= 0) {
                            if (amendedImagePath.indexOf(value.OriginalValue) >= 0) {
                                amendedImagePath = amendedImagePath.replace(value.OriginalValue, value.NewValue);
                            }
                        }
                    });
                }
            }
            else if (Next.Settings.Channel.TotalPlatformFeatures.IsEnabled) {
                if (Next.Settings.Channel.TotalPlatformFeatures.ProductImages.ImageFolder) {
                    amendedImagePath = amendedImagePath.replace('/ItemImages/', '/ItemImages/' + Next.Settings.Channel.TotalPlatformFeatures.ProductImages.ImageFolder + '/');
                    Next.Settings.Channel.TotalPlatformFeatures.ProductImages.ImageDimensionOverrides.forEach(function (value) {
                        if (amendedImagePath.indexOf(value.ImageType) >= 0) {
                            if (amendedImagePath.indexOf(value.OriginalValue) >= 0) {
                                amendedImagePath = amendedImagePath.replace(value.OriginalValue, value.NewValue);
                            }
                        }
                    });
                }
            }
            return amendedImagePath;
        },
        UpdateLogoData: function ($styleCopy, item) {
            var $logos;
            var $logosTable;
            var refresh = function () {
                var $styleContent = $styleCopy.find(".StyleContent");
                $styleContent.append("<div id='logos' class='logos' style='display:none'><table></table></div>");

                $logos = $styleCopy.find("#logos");
                $logosTable = $logos.find("table");

                var displaySustainabilityAccordion = false;
                if (Next.Settings.Channel.TpPdpShowSustainabilityAccordion) {
                    ProductPage.Vars.SustainabilityDataContainer.empty();
                }

                $.each(item.Logos, function (iLogo, logo) {
                    if ((startsWith(logo.Name)) && Next.Settings.Channel.TpPdpShowSustainabilityAccordion) {
                        var template = getLogoTemplate(logo.Name,
                            logo.Description,
                            "fallbackLogo");
                        var table = '<table><tbody><tr><td class="img" valign="top">' + template + '<td/><td class="description"><div class="description">' + logo.Description + '</div></td></tr></tbody></table>';
                        ProductPage.Vars.SustainabilityDataContainer.append(table);
                        displaySustainabilityAccordion = true;
                    }
                    else {
                        AddLogoImage($styleCopy, logo.Image, logo.Name, logo.Description);
                    }
                });

                if (Next.Settings.Channel.TpPdpShowSustainabilityAccordion && displaySustainabilityAccordion) {
                    ProductPage.Vars.DivSustainabilityAccordion.show();
                }

                SetupFallbackForChannelisedLogos();
            }

            function startsWith(str) {
                return str.lastIndexOf("rs", 0) === 0;
            }

            function getLogoTemplate(name, description, fallbackImageClassName) {
                var logoPath = CdnBaseUrl + "/Common/Items/Default/Default/Logos/32/" + name + ".gif";
                return '<img class="' + fallbackImageClassName + '" src = "' + logoPath + '" alt ="' + description + '" data-code= "' + name + '"/ >';
            }

            $logos = $styleCopy.find("#logos");

            if (item.Logos.length === 0) {
                if ($logos.length > 0) {
                    // No logo data for this item, so remove the unnecessary elements
                    $logos.remove();
                }
            } else {
                if ($logos.length === 0) {
                    // No logo elements in place so build and populate UI
                    refresh();
                } else {
                    // Refresh the logo UI
                    $logos.remove();
                    refresh();
                }
            }
        },
        UpdateLegalWarningLogosData: function ($styleCopy, item) {
            var $legalWarningLogos;
            var refresh = function () {
                var $legalWarningContainer = $styleCopy.find(".legalWarningContainer");

                $legalWarningContainer.append("<div id='legalWarningLogos' class='legalWarningLogos'></div>");

                $legalWarningLogos = $styleCopy.find("#legalWarningLogos");

                if (item.LegalWarningLogos) {
                    if (Next.Settings.Channel.CountryCode === "GB") {
                        $.each(item.LegalWarningLogos,
                            function (iLogo, logo) {
                                if (logo.Name !== "NOT_FOUND") {
                                    AddLegalWarningLogoImage($styleCopy, logo.Image, logo.Name, logo.Description);
                                }
                            });
                    }
                    else {
                        var validLegalWarningFound = false;
                        var firstLogo = true;
                        var lwTable = '<table>';

                        $.each(item.LegalWarningLogos,
                            function (iLogo, logo) {
                                if (logo.Name !== "NOT_FOUND") {
                                    var template = getLogoTemplate(logo.Image,
                                        logo.Name,
                                        logo.Description,
                                        "channelisedLegalWarningLogo");
                                    var description = $(template).attr('alt');
                                    if (!firstLogo) {
                                        lwTable += '<tr class="lwTableSpacingRow"><td colspan="2"></td></tr>';
                                    }
                                    lwTable += '<tr><td>' + template + '</td><td>' + description + '</td></tr>';
                                    validLegalWarningFound = true;
                                    firstLogo = false;
                                }
                            });
                        lwTable += '</table>';

                        if (validLegalWarningFound) {
                            $legalWarningLogos.append(lwTable);
                        }
                    }

                    if ($legalWarningLogos.html()) {
                        SetupFallbackForChannelisedLegalWarningLogos();
                        $legalWarningLogos.show();
                    } else {
                        $legalWarningLogos.remove();
                    }
                }
            }

            function getLogoTemplate(logoPath, name, description, fallbackImageClassName) {
                return '<img class="' + fallbackImageClassName + '" src = "' + logoPath + '" alt ="' + description + '" data-code= "' + name + '"/ >';
            }

            $legalWarningLogos = $styleCopy.find("#legalWarningLogos");

            if (item.LegalWarningLogos && item.LegalWarningLogos.length === 0) {
                if ($legalWarningLogos.length > 0) {
                    // No Visisble logo data for this item, so remove the unnecessary elements
                    $legalWarningLogos.remove();
                }
            } else {
                if ($legalWarningLogos.length === 0) {
                    // No Visisble logo elements in place so build and populate UI
                    refresh($styleCopy, item);
                } else {
                    // Refresh the Visisble logo UI
                    $legalWarningLogos.remove();
                    refresh($styleCopy, item);
                }
            }
        },
        UpdateOptionLogoData: function ($style) {
            // Clear previous logos
            var $styleCopy = $style.find(".StyleCopy");
            var $styleContent = $styleCopy.find(".OptionLogos");
            var $styleAlsoIn = $styleCopy.find("#alsoin");
            $styleContent.empty();
            $styleAlsoIn.hide();

            // Look for other fit options in this same style id and the same colour (if there is a colour)
            var $colour = $style.find(".StyleForm select.colourList");
            var currentColour = $colour.find("option:selected").text();

            if (!currentColour) {
                $colour = $style.find(".StyleForm ul.colourChips li.active");
                currentColour = $colour.data("value");
            }

            var styleId = $style.data("styleid");
            var style;
            $.each(ProductPage.Vars.ItemData, function () {
                if (this.StyleID == styleId) {
                    style = this;
                    return false;
                }
                return true;
            });

            var petitDisplayed = false;
            var tallDisplayed = false;
            var plusDisplayed = false;
            if (style != null) {
                $.each(style.Fits, function () {
                    var $styleCopy = $style.find(".StyleCopy");
                    var $styleContent = $styleCopy.find(".OptionLogos");
                    for (var i = 0; i < this.Items.length; i++) {

                        // Only show the other fits in the same colour
                        if (this.Items[i].Colour == currentColour) {
                            for (var logoIndex = 0; logoIndex < this.Items[i].Logos.length; logoIndex++) {

                                var hasFit = 0;
                                if (this.Items[i].Logos[logoIndex].Image.toLowerCase().indexOf("petit") != -1 && petitDisplayed == false) { hasFit = 1; petitDisplayed = true; }
                                if (this.Items[i].Logos[logoIndex].Image.toLowerCase().indexOf("tall") != -1 && tallDisplayed == false) { hasFit = 1; tallDisplayed = true; }
                                if (this.Items[i].Logos[logoIndex].Image.toLowerCase().indexOf("plus") != -1 && plusDisplayed == false) { hasFit = 1; plusDisplayed = true; }

                                if (hasFit == 1) {
                                    $styleContent.append("<li> <img src=\"" + this.Items[i].Logos[logoIndex].Image + "\" alt=\"Also available in other fits\" /></li>");
                                    $styleAlsoIn.show();
                                }
                            }
                        }
                    }
                });
            }
        },
        UpdateMultibuyData: function ($styleCopy, item) {
            var $multibuys;
            var $multibuysTable;
            var refresh = function () {
                var $styleContent = $styleCopy.find(".StyleContent");
                $styleContent.append('<div id=' + 'MultibuyTypes' + '><table></table></div>');

                $multibuys = $styleCopy.find("#MultibuyTypes");
                $multibuysTable = $multibuys.find("table");

                $.each(item.MultibuyTypes, function (iMultibuy, multibuy) {
                    $multibuysTable.append("<tr><td><div class='description'>" + multibuy.Description + "</div></td></tr>");
                });
            }

            $multibuys = $styleCopy.find("#MultibuyTypes");

            if (item.MultibuyTypes.length === 0) {
                if ($multibuys.length > 0) {
                    $multibuys.remove();
                }
            } else {
                if ($multibuys.length === 0) {
                    refresh();
                } else {
                    $multibuys.remove();
                    refresh();
                }
            }
        },
        UpdateProductInformationData: function ($styleCopy, item) {

            var $productInformation;
            var $productInformationTable;

            var refresh = function () {
                var $styleContent = $styleCopy.find(".StyleContent");
                $styleContent.append('<div id=' + 'ProductInformationList' + '></div>');

                $productInformation = $styleCopy.find("#ProductInformationList");

                $.each(item.ProductInformationList, function (iProductInformation, productInformation) {
                    $productInformation.append("<div>" + productInformation.ProductInformation + "</div>");
                });
            }

            $productInformation = $styleCopy.find("#ProductInformationList");

            if (item.ProductInformationList.length === 0) {
                if ($productInformation.length > 0) {
                    $productInformation.remove();
                }
            } else {
                if ($productInformation.length === 0) {
                    refresh();
                } else {
                    $productInformation.remove();
                    refresh();
                }
            }

        },
        IsPersonalisedGift: function (item) {
            return item.Personalisation == "Y" || item.Personalisation == "P";
        },
        ClearItemData: function ($styleCopy) {
            var itemElementIds = [];
            $.each(ProductPage.Vars.DisplayConfiguration, function (idx, displayConfiguration) {
                // Use the values from display configuration to build up an array of possible
                // item element Id's for copy text and links.
                if (displayConfiguration.Name.toUpperCase().indexOf('COPY TEXT') === 0 || displayConfiguration.Name.toUpperCase().indexOf('LINK') === 0) {
                    var divId = displayConfiguration.Name.replace(/\s+/g, '');
                    itemElementIds.push(divId);
                }
            });

            // Add all remaining item elements.
            itemElementIds.push('Composition');
            itemElementIds.push('Measurements');
            itemElementIds.push('ToneOfVoice');
            itemElementIds.push('WashingInstructions');
            itemElementIds.push('logos');
            itemElementIds.push('MultibuyTypes');
            itemElementIds.push('CountryOfOrigin');
            itemElementIds.push('CareInstructions');
            itemElementIds.push('CompositionData');
            itemElementIds.push('TermsAndConditions');
            itemElementIds.push('ProductInformationList');
            itemElementIds.push('SearchDescription');
            itemElementIds.push('Department');

            // Remove all existing item elements from the DOM.
            $.each(itemElementIds, function (idx, divId) {
                var $divElement = $styleCopy.find('#' + divId);

                if ($divElement.length > 0) {
                    $divElement.remove();
                }
            });

            var $divaSideElement = $styleCopy.find('aside');
            if ($divaSideElement.length > 0) {
                $divaSideElement.remove();
            }
        },
        UpdateCopyTextData: function ($styleCopy, item, displayConfigurationName) {
            // Determine which copy text element is to be appended to the DOM.
            var displayElement = displayConfigurationName.substr(displayConfigurationName.indexOf("Copy Text") + 10);
            var copyTextDomElementId = '#CopyText' + displayElement;
            var $copyTextDomElement = $styleCopy.find(copyTextDomElementId);
            var $styleContent = $styleCopy.find(".StyleContent");

            if (item.CopyText && item.CopyText.length > 0) {
                // Iterate through all item copy text data to find any matching display element (i.e. 4 = 'Copy Text 4').
                $.each(item.CopyText, function (idx, l) {
                    if (l.DisplayElement === displayElement) {
                        var copyTextData = l.Description;
                        var elementId = displayConfigurationName.replace(/\s+/g, '');
                        if (copyTextData !== '' && copyTextData != null) {
                            if ($copyTextDomElement.length === 0) {
                                // Append the relevant copy text data to the DOM.
                                $styleContent.append('<div id=' + elementId + '>' + copyTextData + '</div>');
                            }
                        }
                    }
                });
            }
        },
        UpdateLinkData: function ($styleCopy, item, displayConfigurationName) {
            // Determine which link element is to be appended to the DOM.
            var displayElement = displayConfigurationName.substr(displayConfigurationName.indexOf("Links") + 6);
            var linkDomElementId = '#Links' + displayElement;
            var $linkDomElement = $styleCopy.find(linkDomElementId);

            if (item.Links && item.Links.length > 0) {
                // Iterate through all item links to find any matching display element (i.e. 2 = 'Links 2').
                $.each(item.Links, function (idx, l) {
                    if (l.DisplayElement === displayElement) {
                        var elementId = displayConfigurationName.replace(/\s+/g, '');
                        if (l.HyperlinkText !== '' && l.HyperlinkText != null) {
                            var link;
                            if ($linkDomElement.length === 0) {
                                // Build and append the relevant link to the DOM.
                                var $styleContent = $styleCopy.find(".StyleContent");
                                $styleContent.append('<div id=' + elementId + '></div>');
                                $linkDomElement = $styleCopy.find('#' + elementId);
                                link = '<a href="' + l.Hyperlink + '">' + l.HyperlinkText + '</a>';
                                $linkDomElement.html(link);
                            }
                        }
                    }
                });
            }
        },
        UpdateItemData: function ($style, $styleCopy, style, item, initialLoad = true) {

            var _this = this;
            var refreshItemLine = function ($element, data, elementId) {

                if (data !== '' && data != null) {
                    if ($element.length === 0) {
                        // Append the line item data to the DOM.
                        var $styleContent = $styleCopy.find(".StyleContent");
                        var displayElementData = Next.Settings.Channel.TpPdpShowCareAndFabricAccordion ? (elementId !== "WashingInstructions" && elementId !== "Composition") : true;
                        if (displayElementData) {
                            if (elementId === 'ToneOfVoice' && Next.Settings.Channel.ToneOfVoiceHtmlDecodingEnabled) {
                                $styleContent.append('<div id=' + elementId + '>' + $("<textarea/>").html(data).text() + '</div>');
                            }
                            else {
                                $styleContent.append('<div id=' + elementId + '>' + data + '</div>');
                            }
                        }
                        else {
                            var table = '<table><tbody><tr><td class="description"><div class="description ' + elementId + '">' + data + '</div></td></tr></tbody></table>';
                            ProductPage.Vars.DivCareAndFabricAccordion.show();
                            ProductPage.Vars.CareAndFabricDataContainer.append(table);
                        }
                    }
                }
            };

            var refreshCareInstructions = function (careInformation) {
                if (!careInformation) return;

                var $content = $("<div>").attr("id", "CareInstructions").html("<b>Care Instruction:</b>");

                if (careInformation.WashLabels) {
                    var $labels = $("<div>");
                    var lbls = careInformation.WashLabels.split(',');
                    $.each(lbls, function (i, lbl) {
                        if (lbl) {
                            $url = $("<img>").attr("src", shotData.CareImagePath + lbl + '.png');
                            $labels.append($url, '&nbsp;');
                        }
                    });
                    $content.append($labels);
                }

                if (careInformation.WashInstructions) {
                    $wash = $("<div>").text(careInformation.WashInstructions);
                    $content.append($wash);
                }

                var $styleContent = $styleCopy.find(".StyleContent");
                $styleContent.append($content);

            };

            var $aSideElement = $($styleCopy).find(".StyleContent").find("aside"); //will be later to append to DOM

            _this.ClearItemData($styleCopy);

            if (item.Excluded === "True" || item.IsSoldOut == "True") {
                if (item.IsSoldOut == "True") {

                    var $showMoreElement = $styleCopy.find("div.showmore");
                    var $showLessElement = $styleCopy.find("div.showless");

                    if (Next.Settings.Channel.SoldoutColourChipStyle !== "") {
                        if (!$showMoreElement.hasClass("IsSoldOut"))
                            $showMoreElement.addClass("IsSoldOut");

                        if (!$showLessElement.hasClass("IsSoldOut"))
                            $showLessElement.addClass("IsSoldOut");
                    }

                    //if item is sold out only or sold-out and excluded it will show this message
                    if (!$styleCopy.find('.ItemSoldOutMessage').length) {
                        $styleCopy.find(".StyleForm .BagHolder").before("<div class='ItemSoldOutMessage'></div>");
                    }

                    $styleCopy.find(".ItemSoldOutMessage").text(nxt.jstranslations.productpage.soldoutitemmessage);
                }
                else {
                    //if item is excluded but not sold-out it will show this message
                    if (!$styleCopy.find('.ItemUnavailableMessage').length) {
                        $styleCopy.find(".StyleForm").append("<div class='ItemUnavailableMessage'></div>");
                    }

                    $styleCopy.find(".ItemUnavailableMessage").text("Regrettably, this item is unavailable to order.");
                }

                $styleCopy.find(".toggleDescription").hide();
                $style.find("select.SizeSelector").parents("div.DropDown").hide();
                $styleCopy.find(".SizeGuide").hide();
                if (Next.Settings.Channel.SoldoutColourChipStyle === "") {
                    $styleCopy.find(".BagHolder").hide();
                    $styleCopy.find(".StyleContent").hide();
                    $styleCopy.find(".Price").hide();
                }

                if (item.IsSoldOut === "True") {
                    $styleCopy.find(".ItemSoldOutMessage").show();
                    $styleCopy.find(".ItemUnavailableMessage").hide();
                    if (Next.Settings.Channel.SoldoutColourChipStyle !== "") {
                        ProductPage.TogglePDPDisplayForSoldoutItem(false);
                        var sizeId = "Size-" + $style.data("targetitem");
                        var $sizeContainer = $(".Chips.formControls").find("#" + sizeId);
                        var $splitSizeContainer = $style.find(".splitSizeContainer[for=" + sizeId + "]");
                        if (Next.Settings.Channel.EnableClientsideSizeDropdown) {
                            if ($sizeContainer.length > 0) {
                                $sizeContainer.parent().hide();
                            }
                            if ($splitSizeContainer.length > 0) {
                                $splitSizeContainer.hide();
                            }
                        }
                        else {
                            if ($sizeContainer.length > 0) {
                                $sizeContainer.parent().hide();
                            }
                            else if ($splitSizeContainer.length > 0) {
                                $splitSizeContainer.hide();
                            }
                        }
                    }
                }
                else if (item.Excluded === "True") {
                    $styleCopy.find(".ItemUnavailableMessage").show();
                    $styleCopy.find(".ItemSoldOutMessage").hide();
                }

                if (Next.Settings.Channel.SoldoutColourChipStyle === "") {
                    return;
                }
    
            } else {
                if (Next.Settings.Channel.SoldoutColourChipStyle !== "") {
                    ProductPage.TogglePDPDisplayForSoldoutItem(true);
                }

                var $showMoreElement = $styleCopy.find("div.showmore");
                var $showLessElement = $styleCopy.find("div.showless");

                if ($showMoreElement.hasClass("IsSoldOut"))
                    $showMoreElement.removeClass("IsSoldOut");

                if ($showLessElement.hasClass("IsSoldOut"))
                    $showLessElement.removeClass("IsSoldOut");

                $styleCopy.find(".ItemSoldOutMessage").hide();
                $styleCopy.find(".ItemUnavailableMessage").hide();
                $styleCopy.find(".Price").show();
                $styleCopy.find(".BagHolder").show();
                $styleCopy.find(".toggleDescription").show();
                $("select.SizeSelector#Size-" + $style.data("targetitem")).parents("div.DropDown").show();

                if (Next.Settings.Channel.EnableClientsideSizeDropdown && !initialLoad) {
                    var $itemNumber = $style.data("targetitem");
                    
                    try {
                        ProductPage.Styles.SplitSize.PopulateSizeSelect($itemNumber);
                    }
                    catch (e) {
                        console.log(e.message);
                    };
                };

                if (Next.Settings.Channel.PersonalisedGiftsEnabled && item.Personalisation && _this.IsPersonalisedGift(item)) {
                    $styleCopy.find(".SizeGuide").hide();
                } else {
                    if (ProductPage.Vars.ShowSizeGuide) {
                        $styleCopy.find(".SizeGuide").show();
                    }
                }

                if (!$styleCopy.find(".toggleDescription").length || $styleCopy.find(".toggleDescription .arrow.open").length)
                    $styleCopy.find(".StyleContent").show();
            }

            if (!ProductPage.Vars.StyleWithEnabled) {
                $styleCopy.find("div.StyleHeader").height("");
            }

            var $composition = $styleCopy.find("#Composition");
            var $measurements = $styleCopy.find("#Measurements");
            var $toneOfVoice = $styleCopy.find("#ToneOfVoice");
            var $washingInstructions = $styleCopy.find("#WashingInstructions");
            var $countryoforigin = $styleCopy.find("#CountryOfOrigin");
            var $careinstruction = $styleCopy.find("#CareInstructions");

            var $compositionData = $styleCopy.find("#CompositionData");
            var $termsAndConditions = $styleCopy.find("#TermsAndConditions");
            var $productInformationList = $styleCopy.find("#ProductInformationList");
            var $searchDescription = $styleCopy.find("#SearchDescription");
            var $department = $styleCopy.find("#Department");

            if (Next.Settings.Channel.TpPdpShowCareAndFabricAccordion) {
                ProductPage.Vars.DivCareAndFabricAccordion.hide();
                ProductPage.Vars.CareAndFabricDataContainer.empty();
            }

            // Handle the display of item data based on the order provided from the display configuration.
            $.each(ProductPage.Vars.DisplayConfiguration, function (arrayId, displayConfiguration) {
                var name = $.trim(displayConfiguration.Name).toLowerCase();

                if (name === 'careinstructions') {
                    refreshCareInstructions(item.CareInformation);
                }
                if (name === 'countryoforigin') {
                    refreshItemLine($countryoforigin, item.CountryOfOrigin, 'CountryOfOrigin');
                }

                if (name === 'composition') {
                    refreshItemLine($composition, item.Composition, 'Composition');
                }
                if (name === 'compositiondata') {
                    refreshItemLine($compositionData, item.CompositionData, 'CompositionData');
                }
                if (name === 'termsandconditions') {
                    refreshItemLine($termsAndConditions, item.TermsAndConditions, 'TermsAndConditions');
                }

                if (name === 'tone of voice') {
                    var strToneOfVoice = style.ToneOfVoice;

                    if (Next.Settings.Channel.WebDataFields.IsEnabled) {
                        if (Next.Settings.Channel.WebDataFields.ToneOfVoice) {
                            var strWebToneOfVoice = null;
                            if (item) {
                                var itemLevelToneOfVoiceWebData = item.WebData.find(function (obj) { return obj.DataFieldName === 'WebTov'; });
                                if (itemLevelToneOfVoiceWebData) {
                                    if (itemLevelToneOfVoiceWebData.Value) {
                                        strWebToneOfVoice = itemLevelToneOfVoiceWebData.Value;
                                    }
                                }
                            }
                            if (!strWebToneOfVoice) {
                                var styleLevelToneOfVoiceWebData = style.WebData.find(function (obj) { return obj.DataFieldName === 'WebTov'; });
                                if (styleLevelToneOfVoiceWebData) {
                                    if (styleLevelToneOfVoiceWebData.Value) {
                                        strWebToneOfVoice = styleLevelToneOfVoiceWebData.Value;
                                    }
                                }
                            }

                            if (strWebToneOfVoice) {
                                strToneOfVoice = strWebToneOfVoice;
                            }
                        }
                    }

                    refreshItemLine($toneOfVoice, strToneOfVoice, 'ToneOfVoice');
                }
                if (name === 'washing instructions') {
                    refreshItemLine($washingInstructions, item.WashingInstructions, 'WashingInstructions');
                }
                if (name === 'measurements') {
                    refreshItemLine($measurements, item.Measurements, 'Measurements');
                }
                if (name === 'productinformationlist') {
                    _this.UpdateProductInformationData($styleCopy, item);
                }
                if (name.toUpperCase().indexOf('LINKS') === 0) {
                    _this.UpdateLinkData($styleCopy, item, displayConfiguration.Name);
                }
                if (name === 'multibuy') {
                    _this.UpdateMultibuyData($styleCopy, item);
                }
                if (name.toUpperCase().indexOf('COPY TEXT') === 0) {
                    _this.UpdateCopyTextData($styleCopy, item, displayConfiguration.Name);
                }
                if (name === 'searchDescription') {
                    refreshItemLine($searchDescription, item.SearchDescription, 'SearchDescription');
                }
                if (name === 'department') {
                    refreshItemLine($department, item.Department, 'Department');
                }
            });

            if (!$styleCopy.find(".StyleContent").html().trim().length)
                $styleCopy.find(".StyleContent").hide();

            //fix for fb case 96547
            if ($aSideElement.length !== 0) {
                $($styleCopy).find(".StyleContent").append($aSideElement);
            }

            var addToBagSection = $styleCopy.find("div.BagHolder > div.AddToBag");
            var addToBagHelp = $styleCopy.find("div.BagHolder");
            var notificationHelp = addToBagSection.find(".NotifyMeHelp");
            var collectInStoreTodayHelp = addToBagHelp.find(".CistHelp");
            var actions = addToBagSection.find("a");
            var addToBagButton = $(actions[0]);
            var notifyMeButton = $(actions[1]);
            var findInStoreOrBuyNowButton = $(actions[2]);
            var personaliseAddToBagButton;
            if (Next.Settings.Channel.AddtoBagButtonTextUpdate) {
                ProductPage.Styles.ToggleTickWrapper(addToBagSection, false);
            }
            if (Next.Settings.Channel.PersonalisedGiftsEnabled) {
                personaliseAddToBagButton = $(actions[2]);
                findInStoreOrBuyNowButton = $(actions[3]);
                $styleCopy.find(".PersonaliseUnavailableMessage").hide();
                $styleCopy.find(".PersonaliseServiceDownMessage").hide();
                $styleCopy.find(".PersonaliseServiceIframe").children().remove();
                $styleCopy.find(".PersonaliseServiceIframe").hide();
                var bagHolder = $styleCopy.find(".BagHolder");
                if (!personaliseAddToBagButton.hasClass("nodisplay")) {
                    personaliseAddToBagButton.addClass("nodisplay");
                }

                if (bagHolder.hasClass("nodisplay")) {
                    bagHolder.removeClass("nodisplay");
                }
            }

            //if (preventOptionsUpdate) {
            //    preventOptionsUpdate = false;
            //}
            //else {
            if (item.ComingSoon) {

                if (item.ComingSoonEnabled === "False") {

                    notificationHelp.addClass("nodisplay");

                    if (!addToBagButton.hasClass("disabled")) {
                        addToBagButton.removeClass("Enabled")
                            .addClass("disabled");
                    }
                } else {
                    if (!addToBagButton.hasClass("nodisplay")) {
                        addToBagButton.addClass("nodisplay");
                    }

                    if (notifyMeButton.hasClass("disabled")) {
                        notifyMeButton.removeClass("disabled")
                            .addClass("Enabled");
                    }

                    notifyMeButton.removeClass("nodisplay");
                    notificationHelp.removeClass("nodisplay");
                }
            } else {
                if (!notifyMeButton.hasClass("nodisplay")) {
                    notifyMeButton.addClass("nodisplay");
                }

                if (Next.Settings.Channel.PersonalisedGiftsEnabled && personaliseAddToBagButton && item.Personalisation && _this.IsPersonalisedGift(item)) {
                    if (!addToBagButton.hasClass("nodisplay")) {
                        addToBagButton.addClass("nodisplay");
                    }

                    if (personaliseAddToBagButton.hasClass("nodisplay")) {
                        personaliseAddToBagButton.removeClass("nodisplay");
                    }

                    if (item.Personalisation === "P") {
                        personaliseAddToBagButton.removeClass("Enabled").addClass("disabled");
                        $styleCopy.find(".PersonaliseUnavailableMessage").show();
                    } else {
                        personaliseAddToBagButton.removeClass("disabled").addClass("Enabled");
                    }
                }
                //else {
                //    addToBagButton.removeClass("nodisplay");
                //    if (addToBagButton.hasClass("disabled")) {
                //        addToBagButton.removeClass("disabled")
                //            .addClass("Enabled");
                //    }
                //}

                if (notificationHelp) {
                    notificationHelp.addClass("nodisplay");
                }
            }
            //}            

            //Hide the Notification Success message in case it is displayed.
            var notificationMessage = $styleCopy.find("span.NotificationSuccess");
            if (!notificationMessage.hasClass("nodisplay")) {
                notificationMessage.addClass("nodisplay");
            }
            if (ProductPage.Vars.ProductBuyNowEligibility[item.ItemNumber]) {
                collectInStoreTodayHelp.addClass("nodisplay");
                if (findInStoreOrBuyNowButton.hasClass("nodisplay"))
                    findInStoreOrBuyNowButton.removeClass("nodisplay");
            }
            else if (Next.Settings.Channel.IsCollectInStoreTodayEnabled) {
                if (findInStoreOrBuyNowButton.hasClass("CollectInStoreLink")) {
                    findInStoreOrBuyNowButton.addClass("nodisplay");
                    collectInStoreTodayHelp.addClass("nodisplay");
                    findInStoreOrBuyNowButton.attr("data-cist-item", item.CollectInStoreTodayEnabled);
                    collectInStoreTodayHelp.attr("data-cist-item", item.CollectInStoreTodayEnabled);
                    showCistButton(item, notifyMeButton);
                }
            } else {
                if (item.StoreStockCheckEnabled === "False") {
                    if (findInStoreOrBuyNowButton.hasClass("FindInStoreLink")) {
                        findInStoreOrBuyNowButton.addClass("nodisplay");
                        collectInStoreTodayHelp.addClass("nodisplay");
                        addToBagSection.find(".button-container > a.fav").children(".favTexts").removeClass('spacing');
                    }
                } else {
                    findInStoreOrBuyNowButton.removeClass("nodisplay");
                    collectInStoreTodayHelp.removeClass("nodisplay");
                }
            }
            if (item.CollectInStoreTodayEnabled === "False") {
                addToBagSection.find(".button-container > a.fav").children(".favTexts").removeClass('spacing');
            }

            _this.UpdateLogoData($styleCopy, item);
            _this.UpdateLegalWarningLogosData($styleCopy, item);
            _this.UpdateOptionLogoData($style);

            if (Next.Settings.Channel.WebDataFields.IsEnabled) {
                if (Next.Settings.Channel.WebDataFields.ToneOfVoice) {
                    $(window).trigger('redrawDescription');
                }
            }

            function displayCistOrBuyNowButtons() {
                findInStoreOrBuyNowButton.removeClass("nodisplay");
                collectInStoreTodayHelp.removeClass("nodisplay");
                findInStoreOrBuyNowButton.children('.cistText').removeClass('smallerCTA');
                addToBagSection.find(".button-container > a.fav").children(".favTexts").removeClass('smallerCTA');
                addToBagSection.find(".button-container > a.fav").children(".favTexts").addClass('spacing');
            }
            function showCistButton(selectedItem, currentNotifyButton) {
                try {
                    //item is not CIST enabled or notify me is visible or CIST is hidden
                    if (selectedItem.CollectInStoreTodayEnabled.toLowerCase() === "false"
                        || currentNotifyButton.is(":visible")
                        || ProductPage.CistConfig().Config.CistFeatureHidden.toLowerCase() === "true") {
                        return;
                    }

                    Common.CollectInStoreAvailable($, Next.Settings.Mobile.CollectInStore.Config).done(function (result) {
                        // If it's eligible, show all 'Cist Enabled' elements...
                        _cistStoresOpen = result.Eligible;
                        if (_cistStoresOpen) {
                            displayCistOrBuyNowButtons();
                        }
                    });
                }
                catch (ex) {
                    console.log("Exception : " + ex);
                }
            }
        },
        ShowItem: function (callLoadShotJson = true) {
            // Get the current style and target item
            var $style = ProductPage.Vars.$styles.filter(".Selected");
            var itemNumber = $style.data("targetitem");
            var itemName = $style.data("itemname");

            //Format item number
            var shortItemNumber = ProductPage.RemoveDashFromItemNumber(itemNumber);

            if (callLoadShotJson && jsonLoaded === false) {
                if (jsonInitalTry === true) {
                    ProductPage.LoadShotJson(3, false, $style.data("stylenumber"), itemNumber);
                } else {
                    ProductPage.LoadShotJson(0, true, $style.data("stylenumber"), itemNumber);
                }
            }

            //On page load we might have an item number passed as a hash param that will trigger and auto select
            //We might also have a size option that will be auto selected when loaded.
            //Need to check if a size option was also passed through so we can allow the selection of the size option 
            //to trigger the save, rather than the selection of the item.
            //But - we should only do this on page load as we need to save all other, subsequent actions on the page
            //the saveItemFromSizeOptionOnLoad flag will be reset immediately if we bypass this save on load
            //Basically - doing this prevents us saving the same item twice...
            if (hashExists && window.location.hash.indexOf('?i=') > -1 && saveItemFromSizeOptionOnLoad) {
                //reset this bool so all subsequent selections will be saved
                saveItemFromSizeOptionOnLoad = false;

            } else {
                ProductPage.RecentlyViewed.SaveViewedItem(true);
            }

            //Build new image URL - cdnURL is set as a global variable in parent page
            var newImgUrl = cdnURL + "/Common/Items/Default/Default/ItemImages/AltItemThumb/" + shortItemNumber + ".jpg";

            newImgUrl = this.OverrideImagePath(newImgUrl);

            //Update display image
            $style.find(".StyleImages").find("img").attr("src", newImgUrl);

            // Set the description
            var title = $.trim($style.find(".Title").text());
            var colour = $style.find(".colourList .dk_label").text();
            // ChanelPDP Description - Removing first Occurence CHANEL Brand name.
            if (typeof $("article").attr("data-brand") != 'undefined' || $("article").attr("data-brand") != '') {
                var index = $('article').attr('data-itemname').indexOf($('article').attr('data-brand'));
                var chanelBrandTitle = (index == 0) ? $('article').attr('data-itemname').slice($('article').attr('data-brand').length).trim()
                    : $('article').attr('data-itemname').trim();
            }
            var desc = ProductPage.Vars.IsChanelBrandPDPEnabled ? chanelBrandTitle : title;

            if (Next.Settings.Channel.Coords.Enabled && $("#pdpnav").length && Next.Settings.Channel.EnablePersistColourAcrossTabs) {
                if ($(".pdp-tab >.tabLabel > a").attr("colourwayFlag") !== "true") {
                    if ($(".pdp-tab.active a").attr("data-styleid") === $(".pdp-tab >.tabLabel > a").attr("data-styleid")) {
                        colour = $(".pdp-tab >.tabLabel > a").attr("colour") ? $(".pdp-tab >.tabLabel > a").attr("colour") : $style.find(".colourList .dk_label").text();
                    }
                }
            }
            // check if color null then select default option
            if (colour === "null") {
                var defaultColourSelect = $style.find(".StyleForm select.colourList option").first().text();
                $style.find(".StyleForm select.colourList option").first().attr("selected", "selected")
                $style.find(".colourList .dk_label").text(defaultColourSelect);
                colour = defaultColourSelect
            }

            if (!colour) {
                var $colourChip = $style.find(".StyleForm ul.colourChips li.active");
                colour = $colourChip.data("value");
            }

            if (Next.Settings.Channel.SoldoutColourChipStyle !== "") {
                var $colourChips = $style.find("ul.colourChips li");
                $colourChips.each(function () {
                    if ($(this).hasClass("SoldoutChip") && $(this).hasClass("active")) {
                        $(this).removeClass(Next.Settings.Channel.SoldoutColourChipStyle);
                    }
                });
            }

            if (pdpChipsEnabled && ProductPage.Styles.PDPColourChipsEnabled() && ProductPage.Styles.pdpChipsShow()) {
                colour = $(".colourChips .chipItem.active").attr("title");
            }

            if (isStackedPDPPage || $("div.Content.suitsPDPCls").length === 1) {
                if ($style.find(".StyleForm .Chips .colourChipsContainer").is(":visible")) {
                    var $colourChip = $style.find(".StyleForm ul.colourChips li.active");
                    colour = $colourChip.data("value");
                }
                else {
                    colour = $style.find(".colourList .dk_label").text();
                }
            }

            if (colour && title.indexOf(colour) !== 0)
                desc = colour + " " + desc;

            var mainImage = "";
            var zoomImage = "";

            // Show lifestyle shot if not come from a Style With item, identified by hash without catalogue code (#999999).
            var lifestyleShot;
            if (StyleWithScroll) {
                lifestyleShot = initialLoad && (window.location.hash.length !== 7);
            } else {
                lifestyleShot = initialLoad && (window.location.hash.length !== 7 || $style.hasClass("FirstItem"));
            }

            var pageType = ProductPage.Vars.$zoomComponent.attr("data-pagetype");
            var currentItemData = ProductPage.Styles.GetPageDataForItem(itemNumber);
            if (Next.Settings.Channel.PDPStyleDescription.EnableSearchDescriptionAsPDPTitle) {
                this.PDPStyleDescription.HandleRange($style, currentItemData);
            }
            else {
                if (Next.Settings.Channel.TotalPlatformFeatures.TPStyleDescriptionEnabled && currentItemData.style.TPStyleDescription) {
                    if (Next.Settings.Channel.TotalPlatformFeatures.RangeEnabled && currentItemData.item.Range) {
                        $style.find(".StyleCopy .StyleHeader .Title h1").text(currentItemData.item.Range + ' ' + currentItemData.style.TPStyleDescription);
                    }
                }
            }
            
            if ((!Next.Settings.Channel.M2MCurtainsAndBlindsEnabled && currentItemData.item.Personalisation === "Y" && currentItemData.item.FulfilmentType === "M")
                || (!Next.Settings.Channel.EnableFlowers && currentItemData.item.Personalisation === "Y" && currentItemData.item.FulfilmentType === "F")) {
                $("#m2mServiceDownMessage").show();
            }

            //Set Shot View Image
            if (Next.Settings.Channel.PliNewMediaFormatIsEnabled && Next.Settings.Channel.PliBehaviourIsEnabled) {
                var setMainAndZoomImageForShotMedia = function (book, page, filename) {
                    mainImage = shotData.ShotBasePath + book + shotData.ShotViewPath + page + "/" + filename + ".jpg";
                    zoomImage = shotData.ShotBasePath + book + shotData.ShotZoomPath + page + "/" + filename + ".jpg";
                };
                var setMainAndZoomImagesFromName = function (name) {
                    mainImage = window.cdnURL + "/Common/Items/Default/Default/ItemImages/AltItemShot/315x472/" + name + ".jpg";
                    zoomImage = window.cdnURL + "/Common/Items/Default/Default/ItemImages/AltItemZoom/" + name + ".jpg";
                };
                var isDefaultItem = PLI.IsDefaultItem(itemNumber);
                //For style pages
                if (pageType === "style" && ItemLevelImagery && currentItemData.item.Media) {
                    var stylePageMedia = currentItemData.item.Media;
                    if (stylePageMedia != null && stylePageMedia.length > 0) {
                        if (stylePageMedia[0].level === "book" && stylePageMedia[0].outlet && stylePageMedia[0].pageNo) {
                            setMainAndZoomImageForShotMedia(stylePageMedia[0].outlet, stylePageMedia[0].pageNo, stylePageMedia[0].name);
                        }
                        else if (stylePageMedia[0].level === "book" && book.length > 0 && pageNumber.length > 0) {
                            setMainAndZoomImageForShotMedia(book, pageNumber, stylePageMedia[0].name);
                        } else {
                            //For level=item and fail safe way
                            setMainAndZoomImagesFromName(stylePageMedia[0].name);
                        }
                    }
                    else {
                        //Fail safe way
                        setMainAndZoomImagesFromName(shortItemNumber);
                    }
                }
                //If Default Item - use Shot Book Media else use Item Level Media 
                else if (isDefaultItem) {
                    var defaultItemMedia = shotData.Media;
                    if (defaultItemMedia != null && defaultItemMedia.length > 0) {
                        //Added the below condition for the scenario when there is only one item in the root level media
                        if (defaultItemMedia[0].level === "book" && book.length > 0 && pageNumber.length > 0) {
                            setMainAndZoomImageForShotMedia(book, pageNumber, defaultItemMedia[0].name);
                        } else {
                            //For level=item and fail safe way
                            setMainAndZoomImagesFromName(defaultItemMedia[0].name);
                        }
					}
                    else {
                        //Fail safe way
                        setMainAndZoomImagesFromName(shortItemNumber);
                    }
                }
                else {
                    var currentItemMedia = currentItemData.item.Media;
                    if (currentItemMedia && currentItemMedia.length > 0) {
                        if (currentItemMedia[0].level === "book") {
                            setMainAndZoomImageForShotMedia(currentItemMedia[0].outlet, currentItemMedia[0].pageNo, currentItemMedia[0].name);
                        } else {
                            //For level=item and fail safe way
                            setMainAndZoomImagesFromName(currentItemMedia[0].name);
                        }
                    }
                    else {
                        //Fail safe way
                        setMainAndZoomImagesFromName(shortItemNumber);
                    }
                }
            } else if (Next.Settings.Channel.PliNewMediaFormatIsEnabled) {
                var media = shotData.Media;
                if (pageType === "style" && ItemLevelImagery)
                    media = currentItemData.item.Media;
                if (media === undefined) {
                    media = [];
                }
                var useFailSafe = true;
                if (lifestyleShot && media && media.length > 0) {
                    if (media[0].level === "book" && book.length > 0 && pageNumber.length > 0 && media[0].alsoItemLevel == "") {
                        useFailSafe = false;
                        mainImage = shotData.ShotBasePath + book + shotData.ShotViewPath + pageNumber + "/" + media[0].name + ".jpg";
                        zoomImage = shotData.ShotBasePath + book + shotData.ShotZoomPath + pageNumber + "/" + media[0].name + ".jpg";
                    }
                    if (media[0].level === "book" && media[0].alsoItemLevel === "true" ||
                        media[0].level === "item") {
                        useFailSafe = false;
                        mainImage = cdnURL + "/Common/Items/Default/Default/ItemImages/AltItemShot/315x472/" + media[0].name + ".jpg";
                        zoomImage = cdnURL + "/Common/Items/Default/Default/ItemImages/AltItemZoom/" + media[0].name + ".jpg";
                    }
                }
                if (useFailSafe) {
                    mainImage = cdnURL + "/Common/Items/Default/Default/ItemImages/AltItemShot/315x472/" + shortItemNumber + ".jpg";
                    zoomImage = cdnURL + "/Common/Items/Default/Default/ItemImages/AltItemZoom/" + shortItemNumber + ".jpg";
                }
            } else {
                var media = shotData.Media;

                if (pageType === "style" && ItemLevelImagery)
                    media = currentItemData.item.Media;

                if (media === undefined) {
                    media = [];
                }

                var useFailSafe = true;

                if (lifestyleShot && media && media.length > 0) {

                    if (media[0].level === "book" && book.length > 0 && pageNumber.length > 0) {
                        useFailSafe = false;
                        mainImage = shotData.ShotBasePath + book + shotData.ShotViewPath + pageNumber + "/" + media[0].name + ".jpg";
                        zoomImage = shotData.ShotBasePath + book + shotData.ShotZoomPath + pageNumber + "/" + media[0].name + ".jpg";
                    }
                    if (media[0].level === "item") {
                        useFailSafe = false;
                        mainImage = cdnURL + "/Common/Items/Default/Default/ItemImages/AltItemShot/315x472/" + media[0].name + ".jpg";
                        zoomImage = cdnURL + "/Common/Items/Default/Default/ItemImages/AltItemZoom/" + media[0].name + ".jpg";
                    }

                }

                if (useFailSafe) {
                    mainImage = cdnURL + "/Common/Items/Default/Default/ItemImages/AltItemShot/315x472/" + shortItemNumber + ".jpg";
                    zoomImage = cdnURL + "/Common/Items/Default/Default/ItemImages/AltItemZoom/" + shortItemNumber + ".jpg";
                }
            }

            if (Next.Settings.Channel.PDPImageManDimensions) {
                mainImage = this.OverrideImagePath(zoomImage)
            }
            else {
                mainImage = this.OverrideImagePath(mainImage);
            }
            zoomImage = this.OverrideImagePath(zoomImage);

            var params = {
                SmallImage: mainImage,
                LargeImage: zoomImage,
                Description: desc
            };

            ProductImages.Styles.Images.Update(itemNumber, $style, initialLoad);

            // Update Discount flag
            $style.data("isdiscount", currentItemData.item.IsDiscount.toString());

            //Sale
            if (currentItemData.item.IsDiscount) {
                if ($('.mod-pdp-reviewstars')) {
                    $('.mod-pdp-reviewstars').addClass('hasWasPrice');
                }
                $style.find('.Price span').text(currentItemData.item.SalePlainPrice);
                $style.find('.Price .wasPrice').text(currentItemData.item.SaleHighlightPrice);
                $style.find('.Price span').parent().closest('div').removeClass("nowPrice").addClass("highlightPrice");

                if (currentItemData.item.MarkdownType === 2) {
                    $style.find('.Price span').parent().closest('div')
                        .removeClass("nowPrice")
                        .removeClass("discountPermanent")
                        .addClass("discountTemporary");
                }
                if (currentItemData.item.MarkdownType === 1) {
                    $style.find('.Price span').parent().closest('div')
                        .removeClass("nowPrice")
                        .removeClass("discountTemporary")
                        .addClass("discountPermanent");
                }

                $style.find('.StyleHeader .SpecialOffer').text(Next.Settings.Channel.SalePriceBasketSubText).show();

                var $tbody = $style
                    .find('.priceHistoryGroup').show()
                    .find("tbody").empty();
                if (currentItemData.item.IsSoldOut == "False" && Next.Settings.Channel.SaleShowPriceHistory) {
                    $style.find('.priceHistoryGroup').attr('data-display', 'show');
                } else {
                    $style.find('.priceHistoryGroup').attr('data-display', 'hide');
                }
                var pH = currentItemData.item.PriceHistory;
                for (var i in pH) {
                    $tbody
                        .append($("<tr/>")
                            .addClass(i % 2 == 0 ? 'odd' : '')
                            .addClass(i == pH.length - 1 ? 'last' : '')
                            .append($("<td/>").text(pH[i].DatePoint))
                            .append($("<td/>").text(pH[i].PricePoint))
                        );
                }
            } else {
                $style.find('.Price span').text(currentItemData.item.FullPrice);
                $style.find('.Price span').parent().closest('div').removeClass("highlightPrice").addClass("nowPrice");
                $style.find('.Price .wasPrice').empty();
                $style.find('.priceHistoryGroup').hide();
                $style.find('.StyleHeader .SpecialOffer').hide();
                if ($('.mod-pdp-reviewstars')) {
                    if ($('.mod-pdp-reviewstars').hasClass('hasWasPrice')) {
                        $('.mod-pdp-reviewstars').removeClass('hasWasPrice');
                    }
                }

                if (Next.Settings.Channel.SizeChipsOnProductPage && Next.Settings.Channel.DisplaySingleSizePrice) {
                    var $selectedSizeChip = $style.find('ul.sizeChips li.active:visible');

                    if ($selectedSizeChip.length) {
                        var $priceLabel = $style.find('.Price span');
                        var $price = $selectedSizeChip.data('price');
                        $priceLabel.text(Next.Settings.Channel.CurrencySymbol + $price);
                    }
                }
            }

            $style.find(".StyleImages").find("img").attr("src", newImgUrl);

            if (Next.Settings.Channel.Afterpay != null && Next.Settings.Channel.Afterpay.enableOnProductPage) {
                this.ShowAfterpayInstallments();

                jQuery(function ($) {

                    $(".Afterpay div a[rel^='lightbox']").slimbox({
                    }, null, function (el) {
                        return (this == el) || ((this.rel.length > 8) && (this.rel == el.rel));
                    });

                    $(".Afterpay div a[rel^='lightbox']").click(function () {
                        TrackGAEvent("PDP", "Link Clicked", "Afterpay More Info", 0);
                    });

                });
            }

            initialLoad = false;

            ProductImages.ZoomComponent.Update(params, function () {
                if (jqueryUpgradeEnabledOnPage) {
                    if ((navigator.userAgent.toLowerCase().indexOf('msie') === -1 || document.documentMode >= 8)) {
                        if (!(Next.Settings.UI.IsSocialPLPEnabled && window.isSocialPLPPage)) {
                            ProductImages.Positioning.ScrollItemToTop($style);
                        }
                    }
                } else {
                    if ((!$.browser.msie || $.browser.version >= 8)) {
                        if (!(Next.Settings.UI.IsSocialPLPEnabled && window.isSocialPLPPage)) {
                            ProductImages.Positioning.ScrollItemToTop($style);
                        }
                    }
                }
            });

            // execute after everything is loaded due to race condition with gtm.js
            window.addEventListener('load', function (event) {
                var $mainStyle = ProductPage.Vars.$styles.filter(".FirstItem");
                var mainItemNumber = $mainStyle.data("targetitem");

                var monetateEnabled = false;
                var bloomReachPixelEnabled = false;
                var pageType = "";
                var deviceType = "";
                if (dataLayer != undefined) {
                    for (var j = 0; j < dataLayer.length; j++) {
                        if (dataLayer[j].monetate_enabled != undefined) {
                            monetateEnabled = dataLayer[j].monetate_enabled === "true";
                        }
                        if (dataLayer[j].page_type != undefined) {
                            pageType = dataLayer[j].page_type;
                        }
                        if (dataLayer[j].device_type != undefined) {
                            deviceType = dataLayer[j].device_type;
                        }
                        if (dataLayer[j].br_pixel_enabled != undefined) {
                            bloomReachPixelEnabled = dataLayer[j].br_pixel_enabled === "true";
                        }
                    }
                    dataLayer.push({ "prod_id": itemNumber, "prod_name": itemName, "sku": itemNumber });

                    if (bloomReachPixelEnabled) {
                        dataLayer.push({ "br_prod_id": itemNumber.replace(/-/g, ""), "br_prod_name": itemName, "br_sku": itemNumber.replace(/-/g, "") });
                    }
                }

                if (monetateEnabled && !ProductPage.Vars.isPushToMonetate) {
                    window.monetateQ.push(["setPageType", pageType]);
                    window.monetateQ.push(["addCategories", [deviceType]]);
                    window.monetateQ.push(["setCustomVariables", [{ name: "deviceType", value: deviceType }]]);
                    window.monetateQ.push(["addProductDetails", JSON.parse('["' + mainItemNumber + '"]')]);
                    window.monetateQ.push(["trackData"]);
                    if (pdpChipsEnabled) {
                        ProductPage.Vars.isPushToMonetate = true
                    }
                }
            });

            return false;

        },
        OverrideImagePath: function (strImagePath) {
            var amendedImagePath = strImagePath;
            if (Next.Settings.Channel.ProductImageSettings.Enabled) {
                if (Next.Settings.Channel.ProductImageSettings.ImageFolder) {
                    if (amendedImagePath.includes('/ItemImages/')) {
                        amendedImagePath = amendedImagePath.replace('/ItemImages/', '/ItemImages/' + Next.Settings.Channel.ProductImageSettings.ImageFolder + '/');
                    }
                    else {
                        if (amendedImagePath.includes('/itemimages/')) {
                            amendedImagePath = amendedImagePath.replace('/itemimages/', '/itemimages/' + Next.Settings.Channel.ProductImageSettings.ImageFolder + '/');
                        }
                        else {
                            if (amendedImagePath.includes('/Publications/')) {
                                amendedImagePath = amendedImagePath.replace('/Publications/', '/Publications/' + Next.Settings.Channel.ProductImageSettings.ImageFolder + '/');
                            }
                            else {
                                if (amendedImagePath.includes('/publications/')) {
                                    amendedImagePath = amendedImagePath.replace('/publications/', '/publications/' + Next.Settings.Channel.ProductImageSettings.ImageFolder + '/');
                                }
                            }
                        }
                    }

                    Next.Settings.Channel.ProductImageSettings.ImageDimensionOverrides.forEach(function (value) {
                        if (amendedImagePath.indexOf(value.ImageType) >= 0) {
                            if (amendedImagePath.indexOf(value.OriginalValue) >= 0) {
                                amendedImagePath = amendedImagePath.replace(value.OriginalValue, value.NewValue);
                            }
                        }
                    });
                }
            }
            else if (Next.Settings.Channel.TotalPlatformFeatures.IsEnabled) {
                if (Next.Settings.Channel.TotalPlatformFeatures.ProductImages.ImageFolder) {
                    if (amendedImagePath.includes('/ItemImages/')) {
                        amendedImagePath = amendedImagePath.replace('/ItemImages/', '/ItemImages/' + Next.Settings.Channel.TotalPlatformFeatures.ProductImages.ImageFolder + '/');
                    }
                    else {
                        if (amendedImagePath.includes('/itemimages/')) {
                            amendedImagePath = amendedImagePath.replace('/itemimages/', '/itemimages/' + Next.Settings.Channel.TotalPlatformFeatures.ProductImages.ImageFolder + '/');
                        }
                        else {
                            if (amendedImagePath.includes('/Publications/')) {
                                amendedImagePath = amendedImagePath.replace('/Publications/', '/Publications/' + Next.Settings.Channel.TotalPlatformFeatures.ProductImages.ImageFolder + '/');
                            }
                            else {
                                if (amendedImagePath.includes('/publications/')) {
                                    amendedImagePath = amendedImagePath.replace('/publications/', '/publications/' + Next.Settings.Channel.TotalPlatformFeatures.ProductImages.ImageFolder + '/');
                                }
                            }
                        }
                    }

                    Next.Settings.Channel.TotalPlatformFeatures.ProductImages.ImageDimensionOverrides.forEach(function (value) {
                        if (amendedImagePath.indexOf(value.ImageType) >= 0) {
                            if (amendedImagePath.indexOf(value.OriginalValue) >= 0) {
                                amendedImagePath = amendedImagePath.replace(value.OriginalValue, value.NewValue);
                            }
                        }
                    });
                }
            }
            return amendedImagePath;
        },

        GetPageDataForItem: function (itemNumber) {

            var data = {
                style: null,
                fit: null,
                item: null
            };

            $.each(ProductPage.Vars.ItemData, function (i, style) {
                $.each(style.Fits, function (i, fit) {
                    $.each(fit.Items, function (i, item) {
                        // Here we trim off the book number so that we match only the 6 digit item number
                        // But some item numbers are 7 digits followed by a single character (e.g. 169230X for Tall items),
                        // in which case there is no book appended and we need to keep all 7 digits for comparison.
                        var finditemNumber = $.trim(itemNumber.toUpperCase()).replace(/-/g, "");
                        if (finditemNumber.length > 7) finditemNumber = finditemNumber.substring(0, 6);

                        var thisitemnumber = $.trim(item.ItemNumber).replace(/-/g, "")
                        if (thisitemnumber.length > 7) thisitemnumber = thisitemnumber.substring(0, 6);

                        if (thisitemnumber === finditemNumber) {
                            data.style = style;
                            data.fit = fit;
                            data.item = item;
                            if (pdpChipsEnabled && ProductPage.Styles.SplitSize.SplitFitEnabled()) {

                                var fitList = [];
                                $.each(item.Options, function (i, opt) {
                                    $.each(opt.FitSizes, function (i, ftSize) {
                                        if (fitList.indexOf(ftSize.Value) == -1) {
                                            fitList.push(ftSize.Value);
                                        }
                                    });
                                });
                                if (fitList) {
                                    if (fitList.includes("Regular")) {
                                        data.splitFit = "Regular";
                                    }
                                    else {
                                        data.splitFit = fitList[0];
                                    }
                                }
                            }
                            return;
                        }
                    });
                    if (data.item) {
                        return;
                    }
                });
                if (data.item) {
                    return;
                }
            });

            return data;
        },
        SelectItem: function (itemNumber, makeCallToDynamicDiv, initialLoad = false) {
            if (typeof makeCallToDynamicDiv === 'undefined') { makeCallToDynamicDiv = true; }
            var _this = this;
            var itemSelected = false;
            var selection = ProductPage.Styles.GetPageDataForItem(itemNumber);

            if (!selection.item) return false;

            //Get style element for selection
            var $style = ProductPage.Vars.$styles.filter("#Style" + selection.style.StyleID);

            //Check that $style has been found
            //Also check that it is not already selected
            //Already selected items should not be re-selected as this will change the default shot image to the style image
            //(causing inconsistencies with search imagery)

            if (!$style.length) return false;

            if ($style.hasClass("Selected")
                && $style.data("targetitem").toUpperCase() === selection.item.ItemNumber.toUpperCase()) {

                if (!selectedFirstItemSaved) {
                    selectedFirstItemSaved = true;
                    ProductPage.RecentlyViewed.SaveViewedItem(true);
                }

                EnhancedEcommerceHelper.pushProductViewToDataLayer();
                EnhancedEcommerceHelper.pushPDPProductImpressionsToDataLayer();

                if (Next.Settings.Channel.WebDataFields.IsEnabled) {
                    if (Next.Settings.Channel.WebDataFields.ToneOfVoice) {
                        //redraw tone of voice for correctly selected item
                        ProductPage.Styles.ItemChanged(selection.item.ItemNumber, makeCallToDynamicDiv, initialLoad);
                    }
                    itemSelected = true;
                }
            } else {

                var $fit = $style.find("select.fitList");

                if (!$fit.length) {
                    var $fitChips = $style.find("ul.fitChips li");
                    if (!($fitChips.hasClass("active") && pdpSplitSizeEnabled)) {
                        $fitChips.each(function () {
                            $(this).removeClass("active");
                            var fitName = $(this).data("value");
                            if (fitName === selection.fit.Name || fitName === selection.splitFit) {
                                $(this).addClass("active");
                                $fit = $(this);
                            }
                        });
                    }
                }

                //Check if fit exists
                if ($fit.length) {
                    if (!$fit.hasClass("chipItem")) {
                        //Fit dropdown exists. Therefore update fit dropdown selected value, and call FitChanged() to deal with pre-selecting the colour dropdown/hidden input                       
                        if ($fit.hasClass("asmFitList") && ProductPage.Styles.SplitSize.SplitFitEnabled()) {
                            $fit.val(selection.splitFit);
                        }
                        else {
                            $fit.val(selection.fit.Name);
                            $fit.dropkick("refresh");
                        }
                    }

                    ProductPage.Styles.FitChanged($fit, selection.item.ItemNumber, false);
                    ProductPage.Vars.ItemNumberToPreSelect = selection.item.ItemNumber;
                } else {
                    // Update colour dropdown/hidden input in the case where there is no fit.
                    var $colour = $style.find("select.colourList");
                    var $itemHdn = $style.find(".hdnItmId");

                    if ((selection.fit.ColourChipsEnabled && !pdpChipsEnabled) || (pdpChipsEnabled && selection.fit.PDPChipsColourEnabled && ProductPage.Styles.pdpChipsShow())) {
                        var $colourChips = $style.find("ul.colourChips li");
                        var $label = $style.find(".colourChipNameLabel");
                        $colourChips.each(function () {
                            $(this).removeClass("active");
                            var itemNumber = $(this).data("itemnumber");
                            if (itemNumber === selection.item.ItemNumber) {
                                $(this).addClass("active");

                                $colour.val(selection.item.ItemNumber);
                                $colour.dropkick("setValue", selection.item.ItemNumber);
                                $colour = $(this);
                                $label.text(selection.item.Colour);

                                if (Next.Settings.Channel.SoldoutColourChipStyle !== "" && $(this).hasClass("SoldoutChip")) {
                                    $(this).removeClass(Next.Settings.Channel.SoldoutColourChipStyle);
                                }
                            }
                        });
                    }

                    if ($colour.length) {
                        if (!$colour.hasClass("chipItem")) {
                            $colour.val(selection.item.ItemNumber);
                            $colour.dropkick("refresh");
                        }
                    } else if ($itemHdn) {
                        $itemHdn.val(selection.item.ItemNumber);
                    }
                }

                $(".Style.Selected").removeClass("Selected");
                $style.addClass("Selected");
                var previousItemNumber = $style.data("targetitem");
                var styleItemNo = $style.find(".StyleMeta .ItemNumber");
                if (pdpChipsEnabled && styleItemNo) {
                    if (ProductPage.Styles.SplitSize.IsEnabled($style) || styleItemNo.text() != previousItemNumber) {
                        previousItemNumber = styleItemNo.text();
                    }
                }
                $style.data("targetitem", selection.item.ItemNumber);
                $style.attr("data-targetitem", selection.item.ItemNumber);
                _this.ItemChanged(previousItemNumber, makeCallToDynamicDiv);

                itemSelected = true;
            }
            return itemSelected;
        },
        ShowWarranty: function ($style, itemNo) {

            var _this = this;

            var $styleForm = $style.find(".StyleForm");
            var warranyWrapperClass = ".ParentItem" + itemNo;

            $styleForm.find("div.Warranty").each(function () {
                $(this).removeClass("Enabled");
            });

            var $warrantyItem = $styleForm.find("section.WarrantyItem");
            var warantyDd = $warrantyItem.find("select");
            var containsValues = _this.ElementContainsValues(warantyDd);

            if ($styleForm.find(warranyWrapperClass).length && containsValues) {
                $styleForm.find(warranyWrapperClass).addClass("Enabled");
                $warrantyItem.show();
            } else {
                $warrantyItem.hide();
            }
            ProductImages.Positioning.ScrollElements();

        },
        ElementContainsValues: function (ddl) {
            var containsValues = false;

            $(ddl).find("option").each(function () {

                if ($(this).index() > 0) {
                    if ($(this).attr("value")) {
                        containsValues = true;
                    }
                }
            });

            return containsValues;
        },
        IsCISTSoldoutOverrideEnabled: function () {
            var cistConfigFeatureHidden = (Next.Settings.Mobile.CollectInStore.Config.CistFeatureHidden || 'false').toLowerCase() == "true";
            var cistConfigOverrideStockText = (Next.Settings.Mobile.CollectInStore.Config.OverrideStockText || 'false').toLowerCase() == "true";

            return Next.Settings.Mobile.CollectInStore.Enabled
                && (!cistConfigFeatureHidden)
                && cistConfigOverrideStockText;
        },
        IsCISTItem: function (dataCistItem, isCistStoresOpen) {
            // Is Item a Collect In Store Today (CIST) item?
            return (Next.Settings.Mobile.CollectInStore.Enabled && isCistStoresOpen) ?
                dataCistItem.toString().toLowerCase() === "true" : false;
        },
        GetItemSoldOutText: function (dataCistItem, soldoutAlternativeEnabled, isCistStoresOpen) {
            var defaultSoldout = nxt.jstranslations.productpage.soldout || "Sold Out";

            // Get override flags
            var isCISTSoldoutOverrideEnabled = ProductPage.Styles.IsCISTSoldoutOverrideEnabled();

            // If no overrides active return default
            if (!isCISTSoldoutOverrideEnabled && !soldoutAlternativeEnabled) {
                return defaultSoldout;
            }

            var isCISTItem = ProductPage.Styles.IsCISTItem(dataCistItem, isCistStoresOpen);

            var soldoutAlternative = nxt.jstranslations.productpage.soldoutalternative || defaultSoldout;
            var soldOutCistAlternative = nxt.jstranslations.productpage.soldoutcisteligiblealternative || defaultSoldout;

            if (isCISTSoldoutOverrideEnabled && soldoutAlternativeEnabled) {
                if (isCISTItem) {
                    return soldOutCistAlternative;
                } else {
                    return soldoutAlternative;
                }
            } else if (isCISTSoldoutOverrideEnabled) {
                if (isCISTItem) {
                    return nxt.jstranslations.productpage.soldoutcisteligible;
                } else {
                    return nxt.jstranslations.productpage.soldoutcistineligible;
                }
            } else {
                // default is CIST OFF, SoloutAlternative ON
                return soldoutAlternative;
            }
        },
        GetItemOptionSoldOutTextOverride: function (dataCistItem, sizeType, soldOut, enableSoldOutStatusChange, isCistStoresOpen) {
            // Is CIST SoldOut text override active? 
            if (!ProductPage.Styles.IsCISTSoldoutOverrideEnabled()) {
                return soldOut;
            }

            // Is Item CIST?
            if (!ProductPage.Styles.IsCISTItem(dataCistItem, isCistStoresOpen)) {
                return soldOut;
            }

            // Have we got a sizeType?
            if (!sizeType || sizeType.length === 0) {
                return soldOut;
            }

            // Get list of SizeTypes which can override CIST ItemOption SoldOut text
            var overrideSoldOutSizeTypes = nxt.jstranslations.productpage.overridesoldoutsizetypes
                ? nxt.jstranslations.productpage.overridesoldoutsizetypes.toLowerCase().split(",")
                : ["tall"];

            // Is ItemOption SizeType a match to the list?
            var sizeTypeMatchOverride = overrideSoldOutSizeTypes.indexOf(sizeType.toLowerCase()) > -1;

            if (sizeTypeMatchOverride) {
                if (enableSoldOutStatusChange) {
                    return nxt.jstranslations.productpage.soldoutalternative;
                }
                else {
                    return nxt.jstranslations.productpage.soldoutcistineligible;
                }
            }

            return soldOut;
        },
        ClearSoldoutTextFromOptionText: function (optionText, soldOutText) {
            var defaultSoldout = nxt.jstranslations.productpage.soldout || "Sold Out";
            var soldOutTextWhenSoldOutStatusChangeEnabled = nxt.jstranslations.productpage.soldoutalternative || defaultSoldout;
            var soldOutCistEligibleTextWhenSoldOutStatusChangeEnabled = nxt.jstranslations.productpage.soldoutcisteligiblealternative || defaultSoldout;
            var soldoutTextOptions =
                [
                    // Order is important! E.g. remove " - Currently Unavailable online, try Collect Today" before " - Currently Unavailable";
                    nxt.jstranslations.productpage.soldoutcisteligible,
                    soldOutCistEligibleTextWhenSoldOutStatusChangeEnabled,
                    nxt.jstranslations.productpage.soldoutcistineligible,
                    soldOutTextWhenSoldOutStatusChangeEnabled,
                    soldOutText,
                    defaultSoldout,
                ]

            for (var i = 0; i < soldoutTextOptions.length; i++) {
                optionText = optionText.replace(" - " + soldoutTextOptions[i], "");
            }

            return optionText;
        },
        HideSizeChipsWhenOverMaxLines: function (itemNumber) {
            if (Next.Settings.Channel.SizeChipsOnProductPageMaxLines > 0) {
                var sizeDropDown = $(".DropDown").has("select.SizeSelector#Size-" + itemNumber);
                var sizeChipsContainer = $(".Chips.formControls").has("div.sizeChipsContainer#Size-" + itemNumber)
                var sizeChips = sizeChipsContainer.find(("div.sizeChipsContainer#Size-" + itemNumber));
                var sizeChip = sizeChips.find(".chipItem").first();
                var sizeChipsHeight = sizeChips.outerHeight();
                var sizeChipHeight = sizeChip.outerHeight(true);

                if (sizeChipsHeight > (sizeChipHeight * Next.Settings.Channel.SizeChipsOnProductPageMaxLines)) {
                    sizeChipsContainer.hide();
                    sizeDropDown.addClass("sizeDropDownEnabled");
                    if (sizeDropDown.find(".formControls").first().css("display") == "none") {
                        sizeDropDown.find(".formControls").first().css("display", "");
                    }
                }
            }
        },
        Reviews: {
            Init: function () {
                if (BazaarVoiceEnabled) {
                    this.InitReviewSummaries();
                } else {
                    $('.ProductPage .ProductDetail .StyleMeta .ItemNumber').css('float', 'left').css('text-align', 'left');
                }
            },
            AttachEvents: {
                ReviewLinkClick: function () {
                    if (!Next.Settings.Channel.EnableEmbeddedReviews || Next.Settings.Channel.DisableEmbeddedReviewsOnLocalLang) {
                        var $links = ProductPage.Vars.$styles.find(".Reviews").find(".Rating .readReviewImg,.Text .readReviewLink");
                        $links.off("click");

                        $links.click(function (e) {
                            e.preventDefault();

                            var $style = $(this).parents("article.Style").first();

                            Reviews.OpenPopup($style);
                        });
                    }
                }

            },
            LoadReviewStarImage: function ($reviewStars, rating) {
                var isGelEnabled = Next.Settings.UI.EnableNextGel3Styling;
                var ratingImg;
                if (isGelEnabled) {
                    ratingImg = "/Images/Gel3-0/Ratings/" + rating + ".png";
                }
                else {
                    ratingImg = "/images/structural/Reviews/Ratings/small/" + rating + ".gif";
                }
                $reviewStars.attr("src", ratingImg)
                    .attr("title", "Rating: " + rating).attr("data-starrating", rating);
            },
            BindReviewSummaries: function (data) {
                //if (!BazaarVoiceEnabled) {
                //    return;
                //}

                //check hash exist and get position on page                
                var hashId = window.location.hash.replace("#", "");
                hashId = hashId.substr(0, 6).toUpperCase();
                var hashPosition = -1;
                if (hashId && hashId !== "") {
                    hashPosition = $.find(".StyleMeta").indexOf($.find(".Meta" + hashId)[0]);
                }

                for (var i = 0; i < data.Results.length; i++) {
                    var result = data.Results[i];

                    var reviewCount;
                    var productId;

                    if (FeefoEnabled) {
                        reviewCount = result.ReviewStatistics.TotalReviewCount;
                        productId = result.ItemNumber;
                    } else {
                        reviewCount = result.TotalReviewCount;
                        productId = result.Id;
                    }

                    // When comparing hashId and productId


                    var $styleMeta = ProductPage.Vars.$styles.find(".Meta" + productId.toUpperCase());

                    //Rating Stars
                    var $reviewStars = $styleMeta.find("img.reviewStars").first();
                    if (result.ReviewStatistics.AverageOverallRating == null) {
                        $reviewStars.hide();
                    } else {

                        var rating = Helpers.RoundToHalf(result.ReviewStatistics.AverageOverallRating);
                        if (rating > 5) {
                            rating = 5;
                        }

                        //fix review bug when item loaded from hash is not the default item.
                        if (i === hashPosition && loadedItemFromHash && selectedItemFromHash) {
                            if (hashId === productId) {
                                ProductPage.Styles.Reviews.LoadReviewStarImage($reviewStars, rating);
                                $reviewStars.show();
                            }
                        } else {
                            ProductPage.Styles.Reviews.LoadReviewStarImage($reviewStars, rating);
                            $reviewStars.show();
                        }
                        if (!rating) {
                            $reviewStars.hide();
                        }
                    }

                    //Review Count
                    var $reviewCount = $styleMeta.find(".reviewCount");
                    var reviewText = (reviewCount) ? ("(" + reviewCount + ")") : (reviewCount + " " + nxt.jstranslations.common.reviews);

                    //fix review bug when item loaded from hash is not the default item.
                    if (i === hashPosition && loadedItemFromHash && selectedItemFromHash) {
                        if (hashId === productId) {
                            $styleMeta.find(".reviewCount").text(reviewText);
                            $reviewCount.show();
                        } else $reviewCount.hide();
                        selectedItemFromHash = false;
                    } else {
                        $styleMeta.find(".reviewCount").text(reviewText);
                        $reviewCount.show();
                    }

                    //remove existing review link if present
                    if ($reviewCount.parent().hasClass("readReviewLink")) {
                        $reviewCount.unwrap();
                    }

                    //Write a Review
                    var pId;

                    if (!FeefoEnabled) {
                        pId = result.Id;

                        $styleMeta.find(".writeReviewLink").unbind('click');
                        //$styleMeta.find(".writeReviewLink").attr("onclick", "$BV.ui('rr', 'submit_review', { productId: '" + pId + "' });");
                    }

                    if (!reviewCount) {
                        $styleMeta.find(".Reviews .Text").addClass("zeroReviews");

                    } else {
                        $styleMeta.find(".Reviews .Text").removeClass("zeroReviews");
                        $reviewCount.wrap("<a class=\"readReviewLink\" href=\"#\"></a>");
                    }

                    ProductPage.Styles.Reviews.AttachEvents.ReviewLinkClick();
                }
                EnhancedEcommerceHelper.pushProductViewToDataLayer();
            },
            BindAnimatedReviewSummaries: function (data) {
                //if (!BazaarVoiceEnabled) {
                //    return;
                //}

                //check hash exist and get position on page                
                var hashId = window.location.hash.replace("#", "");
                hashId = hashId.substr(0, 6).toUpperCase();
                var hashPosition = -1;
                if (hashId && hashId !== "") {
                    hashPosition = $.find(".StyleMeta").indexOf($.find(".Meta" + hashId)[0]);
                }

                for (var i = 0; i < data.Results.length; i++) {
                    var result = data.Results[i];

                    var reviewCount;
                    var productId;

                    if (FeefoEnabled) {
                        reviewCount = result.ReviewStatistics.TotalReviewCount;
                        productId = result.ItemNumber;
                    } else {
                        reviewCount = result.TotalReviewCount;
                        productId = result.Id;
                    }

                    // When comparing hashId and productId
                    var $styleMeta = ProductPage.Vars.$styles.find(".Meta" + productId.toUpperCase());

                    var rating = 0;

                    //Rating Stars
                    var $reviewStars = $styleMeta.find(".reviewStars").first();

                    $reviewStars.css("width", "0px");
                    $reviewStars.closest(".Reviews").children(".Text").children(".readReviewLink").children(".reviewCount").css("display", "none");
                    if (result.ReviewStatistics.AverageOverallRating != null) {

                        rating = Helpers.RoundToHalf(result.ReviewStatistics.AverageOverallRating);

                        if (rating > 5) {
                            rating = 5;
                        }

                        //fix review bug when item loaded from hash is not the default item.
                        if (i === hashPosition && loadedItemFromHash && selectedItemFromHash) {
                            if (hashId === productId) {
                                ProductPage.Styles.Reviews.LoadAnimatedReviewStarImage($reviewStars, rating);

                            }
                        }
                        else {
                            ProductPage.Styles.Reviews.LoadAnimatedReviewStarImage($reviewStars, rating);

                        }
                        if (!rating) {
                            rating = 0;
                            ProductPage.Styles.Reviews.LoadAnimatedReviewStarImage($reviewStars, rating);
                        }
                    }

                    //Review Count
                    var $reviewCount = $styleMeta.find(".reviewCount");
                    var reviewText = (reviewCount) ? ("(" + reviewCount + ")") : "";

                    //fix review bug when item loaded from hash is not the default item.
                    if (i === hashPosition && loadedItemFromHash && selectedItemFromHash) {
                        if (hashId === productId) {
                            $styleMeta.find(".reviewCount").text(reviewText);
                            $reviewCount.show();
                        } else $reviewCount.hide();
                        selectedItemFromHash = false;
                    } else {
                        $styleMeta.find(".reviewCount").text(reviewText);
                        //  $reviewCount.show();
                    }

                    //remove existing review link if present
                    if ($reviewCount.parent().hasClass("readReviewLink")) {
                        $reviewCount.unwrap();
                    }

                    //Write a Review
                    var pId;

                    if (!FeefoEnabled) {
                        pId = result.Id;

                        $styleMeta.find(".writeReviewLink").unbind('click');
                        //$styleMeta.find(".writeReviewLink").attr("onclick", "$BV.ui('rr', 'submit_review', { productId: '" + pId + "' });");
                    }

                    if (!reviewCount) {
                        $styleMeta.find(".Reviews .Text").addClass("zeroReviews");

                    } else {
                        $styleMeta.find(".Reviews .Text").removeClass("zeroReviews");
                        $reviewCount.wrap("<a class=\"readReviewLink\" href=\"#\"></a>");
                    }

                    ProductPage.Styles.Reviews.AttachEvents.ReviewLinkClick();
                }
                EnhancedEcommerceHelper.pushProductViewToDataLayer();
            },
            LoadAnimatedReviewStarImage: function ($reviewStars, rating) {

                var val = parseFloat(rating);
                // Make sure that the value is in 0 - 5 range, multiply to get width
                var size = Math.max(0, (Math.min(5, val))) * 12;

                $reviewStars.attr("title", "Rating: " + rating).attr("data-starrating", rating);

                var val = parseFloat(rating);
                // Make sure that the value is in 0 - 5 range, multiply to get width
                var size = Math.max(0, (Math.min(5, val))) * 12;

                // Create stars holder


                $reviewStars.animate({ width: size }, 1000);
                if (!$reviewStars.closest(".Text").hasClass("zeroReviews")) {
                    // console.log("here test" + $reviewStars.closest(".Reviews").children(".Text").children(".readReviewLink").children(".reviewCount").html());
                    $reviewStars.closest(".Reviews").children(".Text").children(".readReviewLink").children(".reviewCount").delay(700).animate({ width: 'show' }, 1000);
                }
            },
            InitReviewSummaries: function (itemId) {
                var _this = this;

                var $idList = ProductPage.Vars.$productDetail.find("#idList");

                if (!$idList.length) {
                    setTimeout(ProductPage.Styles.Reviews.InitReviewSummaries, 100);
                }

                var idList;

                if (itemId) {
                    idList = itemId;
                } else {
                    idList = $idList.val();
                }


                PageReviews.GetReviewSummaries(idList, _this.BindAnimatedReviewSummaries);
            }
        },
        EmbeddedReviews: {
            Init: function () {
                this.AttachEvents.ShowMoreReviews();
                this.AttachEvents.ShowSharingBanner();
                this.AttachEvents.HideSharingBanner();
                this.AttachEvents.TrackSocialSharing();
                this.AttachEvents.RatingsBreakdownVisibility();
                this.AttachEvents.FilterReviewsByRating();
                this.AttachEvents.ResetFilterByRating();
                this.AttachEvents.ReviewRatingClick();
                this.AttachEvents.ScrollDownToEmbeddedReviews();
                this.BackToTop.Init();
            },
            AttachEvents: {
                ShowMoreReviews: function () {
                    var embeddedReviewsContainer = ProductPage.Styles.EmbeddedReviews.Helpers.GetReviewsContainer();
                    PageReviews.ShowMoreReviews(embeddedReviewsContainer);
                },
                ShowSharingBanner: function () {
                    var embeddedReviewsContainer = ProductPage.Styles.EmbeddedReviews.Helpers.GetReviewsContainer();
                    PageReviews.ShowSharingBanner(embeddedReviewsContainer);
                },
                HideSharingBanner: function () {
                    var embeddedReviewsContainer = ProductPage.Styles.EmbeddedReviews.Helpers.GetReviewsContainer();
                    PageReviews.HideSharingBanner(embeddedReviewsContainer);
                },
                TrackSocialSharing: function () {
                    var embeddedReviewsContainer = ProductPage.Styles.EmbeddedReviews.Helpers.GetReviewsContainer();
                    PageReviews.TrackSocialSharing(embeddedReviewsContainer);
                },
                RatingsBreakdownVisibility: function () {
                    var embeddedReviewsContainer = ProductPage.Styles.EmbeddedReviews.Helpers.GetReviewsContainer();
                    PageReviews.RatingsBreakdownVisibility(embeddedReviewsContainer);
                },
                FilterReviewsByRating: function () {
                    var embeddedReviewsContainer = ProductPage.Styles.EmbeddedReviews.Helpers.GetReviewsContainer();
                    PageReviews.FilterReviewsByRating(embeddedReviewsContainer);
                },
                ResetFilterByRating: function () {
                    var embeddedReviewsContainer = ProductPage.Styles.EmbeddedReviews.Helpers.GetReviewsContainer();
                    PageReviews.ResetFilterByRating(embeddedReviewsContainer);
                },
                ReviewRatingClick: function () {
                    var embeddedReviewsContainer = ProductPage.Styles.EmbeddedReviews.Helpers.GetReviewsContainer();
                    PageReviews.ReviewRatingClick(embeddedReviewsContainer);
                },
                ScrollDownToEmbeddedReviews: function () {
                    var embeddedReviewsContainer = ProductPage.Styles.EmbeddedReviews.Helpers.GetReviewsContainer();
                    var headerOffset = PageReviews.EmbeddedReviewsHeaderOffset();
                    PageReviews.ScrollDownToEmbeddedReviews(headerOffset, embeddedReviewsContainer);
                }
            },
            Helpers: {
                GetReviewsContainer: function () {
                    return $('#EmbeddedReviewsContainer');
                },
                GetHeaderOffset: function () {
                    var height = $(".HeaderContent").height() + $(".BreadcrumbNavigation").height();
                    if ($(".tabControls").length) {
                        height = height + $(".tabControls").height();
                    }
                    return height;
                }
            },
            BackToTop: {
                Init: function () {
                    // On click, jump back to top
                    ProductPage.Vars.$backToTop.on("click", function () {
                        $("html, body").animate({ scrollTop: 0 }, 700, "easeOutExpo");
                        TrackGAEvent("productpage", "click", "back-to-top-selected", 0);
                        return false;
                    });

                    // On scroll, show / hide depending on position
                    $(window).scroll(function () {
                        if (Next.Settings.UI.IsSocialPLPEnabled && window.isSocialPLPPage) return false;
                        var backToTopHeight = ProductPage.Vars.$backToTop.outerHeight(true);
                        var footerOffset = 22;
                        var top = $(window).scrollTop() + $(window).height() - backToTopHeight - footerOffset;
                        if (top > (Math.max($("#EmbeddedReviewsContainer").offset().top, $(window).height()))) {
                            ProductPage.Styles.EmbeddedReviews.BackToTop.Show();
                        } else {
                            ProductPage.Styles.EmbeddedReviews.BackToTop.Hide();
                        }
                    });
                },
                Show: function () {
                    if (!ProductPage.Vars.$backToTop.hasClass("open") && !ProductPage.Vars.$backToTop.hasClass("opening")) {
                        ProductPage.Vars.$backToTop.stop().removeClass("closing").css("display", "block").addClass("open opening").animate(
                            { bottom: 51 }, 600, "easeOutQuart", function () {
                                $(this).removeClass("opening");
                            });
                    }
                },
                Hide: function () {
                    if (ProductPage.Vars.$backToTop.hasClass("open") && !ProductPage.Vars.$backToTop.hasClass("closing")) {
                        ProductPage.Vars.$backToTop.stop().removeClass("open opening").css("display", "block").addClass("closing").animate(
                            { bottom: -22 }, 600, "easeOutQuart", function () {
                                $(this).removeClass("closing");
                            });
                    }
                }
            }
        },
        SplitSize: {
            IsEnabled: function ($currentstyle) {
                var fit = ProductPage.Vars.GetCurrentFit();
                var $hiddenItemId = $(".hdnItmId");
                var $style = ProductPage.Vars.GetCurrentStyleElement();
                if (pdpChipsEnabled && $currentstyle) {
                    $style = $currentstyle;
                }
                var styleItmNo = $style.data("targetitem");
                if (pdpChipsEnabled && styleItmNo) {
                    var itemNo = styleItmNo;
                    if (itemNo != undefined) {
                        var itemData = ProductPage.Styles.GetPageDataForItem(itemNo.toUpperCase());
                        return itemData && (itemData.item && itemData.item.PDPChipsSplitSizeEnabled && ProductPage.Styles.pdpChipsShow());
                    }
                    else if ($hiddenItemId.val()) {
                        var itemData = ProductPage.Styles.GetPageDataForItem($hiddenItemId.val().toUpperCase());
                        return itemData && (itemData.item && itemData.item.PDPChipsSplitSizeEnabled && ProductPage.Styles.pdpChipsShow());
                    }
                }
                //var ColourChipItmNo = $("ul.colourChips li.active").data("itemnumber"); 
                else {
                    return fit && fit.SplitSizeEnabled;
                }
            },
            SplitFitEnabled: function () {
                var fit = ProductPage.Vars.GetCurrentFit();
                var splitFitEnabled = false;
                if (fit != undefined) {
                    splitFitEnabled = ProductPage.Styles.SplitSize.HasEqualFitSizeCount(fit.Items);
                }
                return fit && (pdpChipsEnabled && splitFitEnabled && fit.PDPChipsSplitSizeFitEnabled && ProductPage.Styles.pdpChipsShow());
            },
            HasEqualFitSizeCount: function (fitItems) {
                let equalFitSizeCount = true;
                for (let i = 0; i < fitItems.length; i++) {
                    var y = fitItems[i].Options;
                    var firstLengthFit = (y[0] != null && y[0].FitSizes) ? y[0].FitSizes.length : 0;
                    equalFitSizeCount = y.every(function (element) {
                        return element.FitSizes && element.FitSizes.length == firstLengthFit;
                    });
                    if (!equalFitSizeCount) {
                        break;
                    }

                }
                return equalFitSizeCount;
            },
            BindClickEventForChips: function (splitSizeName, $style) {
                // unbind event before re-binding it
                $("body").undelegate("ul[for=" + splitSizeName + "] li.splitSizeChip", "click");

                $("body").delegate("ul[for=" + splitSizeName + "] li.splitSizeChip", "click", function () {
                    var $clickedChip = $(this);
                    if (pdpChipsEnabled) {
                        $style = $clickedChip.parents("article.Style")
                    }
                    var itemNumber = $style.data("targetitem");
                    var $sizeSelector = $style.find("select#Size-" + itemNumber);
                    if (!$clickedChip.hasClass("active")) {
                        $clickedChip.addClass("active").siblings().removeClass("active");
                        if (pdpSplitSizeEnabled) {
                            ($clickedChip.hasClass("unavailable")) ?
                                $clickedChip.parents(".splitSizeContainer").parent().find(".btn-addtobag").removeClass("Enabled").addClass("disabled") :
                                $clickedChip.parents(".splitSizeContainer").parent().find(".btn-addtobag").removeClass("disabled").addClass("Enabled");

                            if ($clickedChip.parent().siblings(".splitSizeSelector").length)
                                $clickedChip.parent().siblings(".splitSizeSelector").find("select").dropkick("setValue", $clickedChip.data("value"));
                            ($clickedChip.hasClass("unavailable")) ?
                                $clickedChip.parents(".splitSizeContainer").parent().find(".btn-addtobag").removeClass("Enabled").addClass("disabled") :
                                $clickedChip.parents(".splitSizeContainer").parent().find(".btn-addtobag").removeClass("disabled").addClass("Enabled");
                        }

                        ProductPage.Styles.SplitSize.UpdateSizesAvailability($sizeSelector);
                        if (pdpSplitSizeEnabled) {
                            if (ProductPage.Styles.SplitSize.IsResetDropdown(itemNumber))
                                ProductPage.Styles.SplitSize.ResetDropDownChipVisibility(itemNumber, $clickedChip);
                        }
                        if (ProductPage.Styles.SplitSize.SelectionComplete($sizeSelector)) {
                            var selectorValue = ProductPage.Styles.SplitSize.GetSizeSelectorValueForSplitSize($sizeSelector);
                            if (selectorValue) {
                                $sizeSelector.dropkick("setValue", selectorValue);
                                if (pdpChipsEnabled && ProductPage.Styles.SplitSize.IsEnabled($style)) {
                                    ProductPage.Styles.SplitSize.SetSplitSizeStockDisplay($sizeSelector);
                                }
                            }
                        }
                        else {
                            $sizeSelector.prop("selectedIndex", 0);
                        }
                    }
                    if (pdpSplitSizeEnabled) {
                        ProductPage.Styles.SplitSize.SetsplitSizeLabelValidation($sizeSelector);
                    }
                })
            },
            ResetDropDownChipVisibility: function (itemNo, $selectedChip) {
                var splitSizeRow = ".splitSizeRow[for=Size-" + itemNo + " ]";
                var splitSizeSelector = ".splitSizeSelector";
                var availableSizes = 0;
                if (pdpSplitSizeEnabled) {
                    if ($selectedChip != null && $selectedChip.length) {
                        if ($selectedChip.parent().parent().siblings(splitSizeRow).find(splitSizeSelector).length > 0) {
                            availableSizes = $(".splitSizeRow[for=Size-" + itemNo + " ] select option").length - $(".splitSizeRow[for=Size-" + itemNo + " ] select option[style='display: none;']").length;
                        }
                        if (availableSizes != 0) {
                            if (availableSizes <= Next.Settings.Channel.PdpChipsSplitSizeMaxCount) {
                                if ($selectedChip.parent().parent().siblings(splitSizeRow).hasClass("DropDown")) {
                                    $selectedChip.parent().parent().siblings(splitSizeRow).removeClass("DropDown height-38").addClass("Chips");
                                    $selectedChip.parent().parent().siblings(splitSizeRow).find(splitSizeSelector).hide();
                                    $selectedChip.parent().parent().siblings(splitSizeRow).find(".splitSizeChips").show();
                                }
                            } else {
                                if ($selectedChip.parent().parent().siblings(splitSizeRow).hasClass("Chips")) {
                                    var hasDropDown = ($selectedChip.parent().parent().siblings(".splitSizeRow[for=Size-" + itemNo + " ].Chips")).find(splitSizeSelector).length > 0 ? true : false;
                                    if (hasDropDown) {
                                        $selectedChip.parent().parent().siblings(splitSizeRow).find(splitSizeSelector).parent().removeClass("Chips").addClass("DropDown height-38");
                                        $selectedChip.parent().parent().siblings(splitSizeRow).find(splitSizeSelector).parent().find(".splitSizeChips").hide();
                                        $selectedChip.parent().parent().siblings(splitSizeRow).find(splitSizeSelector).show();
                                    }

                                }
                            }

                        }
                    } else {
                        $(splitSizeRow).each((index, currentElement) => {
                            var currFit = $(".fitChips .chipItem.active").data("value");
                            var currLength = $(splitSizeRow).find(".splitSizeChip.Length.active") ? $(splitSizeRow).find(".splitSizeChip.Length.active").text().trim() :
                                "";
                            var availableSize = 0;
                            if (currLength != "") {
                                $("#dk_container_Size-" + itemNo + ".SizeSelector").find("select option").each((index, currOpt) => {
                                    if ($(currOpt).data("splitsizes-length") == currLength) {
                                        ++availableSize;
                                    }

                                });
                            }
                            else {
                                availableSize = $("#dk_container_Size-" + itemNo + ".SizeSelector").first().find("select option[data-splitfits=" + currFit + "]").length
                            }

                            if (availableSize <= Next.Settings.Channel.PdpChipsSplitSizeMaxCount) {
                                if ($(currentElement).find(".splitSizeChips").length) {
                                    $(currentElement).find(".splitSizeSelector").hide();
                                    if ($(currentElement).hasClass("Dropdown")) {
                                        $(currentElement).addClass("Chips").removeClass("DropDown height-38");
                                        $(currentElement).find(".splitSizeChips").show();
                                    }

                                }
                            } else {
                                if ($(currentElement).find(".splitSizeSelector").length) {
                                    $(currentElement).find(".splitSizeChips").hide();

                                    $(currentElement).addClass("DropDown height-38").removeClass("Chips");
                                    $(currentElement).find(".splitSizeSelector").show();
                                }
                            }
                        })
                    }
                }
            },
            IsSingleSplitSizeItem: function () {
                var $style = ProductPage.Vars.GetCurrentStyleElement();
                var ItemNumber = $style.data("targetitem");
                var $itemData = ProductPage.Styles.GetPageDataForItem(ItemNumber);
                var options = $itemData.item.Options;
                if (pdpSplitSizeEnabled && ProductPage.Styles.SplitSize.IsEnabled($style)) {
                    if (options && options.length == 1 && options[0].SplitSizes.length == 1) {
                        return true;
                    }
                    else {
                        return false;
                    }
                }

            },

            IsResetDropdown: function (itemnumber) {
                var isReset = $("article").data("target-item", itemnumber).find(".chips-dropdown").length > 0 ? true : false;
                return isReset;
            },

            ResetSplitSizeMessage: function ($sizeSelector) {
                var $style = pdpChipsEnabled ? $sizeSelector.parents("article.Style") : ProductPage.Vars.GetCurrentStyleElement();
                var itemNumber = $style.data("targetitem");
                var defaultClass = "splitSizeMessage";
                var $availabilityMessage = $style.find("." + defaultClass + "[for=Size-" + itemNumber + "]");

                $availabilityMessage.hide();
                $availabilityMessage.attr("class", "");
                $availabilityMessage.addClass(defaultClass);
                $availabilityMessage.html("");
                if (pdpChipsEnabled) {
                    var sizeId = $sizeSelector.attr('id');
                    var $splitSizeContainer = $style.find(".splitSizeContainer[for=" + sizeId + "]");
                    $splitSizeContainer.find(".splitSizeRow:visible").find($("label")).removeClass("splitSizeLabelValidation");
                }
            },
            SetSplitSizeMessage: function (message, msgClass, $sizeSelector) {
                var $style = pdpChipsEnabled ? $sizeSelector.parents("article.Style") : ProductPage.Vars.GetCurrentStyleElement();
                var itemNumber = $style.data("targetitem");
                var defaultClass = "splitSizeMessage";
                var $availabilityMessage = $style.find("." + defaultClass + "[for=Size-" + itemNumber + "]");

                if ($availabilityMessage) {
                    $availabilityMessage.show();
                    var $price = $style.find(".StyleCopy .Price span").text();
                    if (pdpSplitSizeEnabled && $price.indexOf("-") != -1 && $sizeSelector.find("option:selected").val() != '') {
                        var formattedPrice = $sizeSelector.find('option:selected').data('priceformatted') && $sizeSelector.find('option:selected').data("priceformatted") !== "" ? $sizeSelector.find('option:selected').data("priceformatted") + " - " : "";
                        $availabilityMessage.html(formattedPrice + message);
                    }
                    else {
                        $availabilityMessage.html(message);
                    }
                    $availabilityMessage.attr("class", "");
                    $availabilityMessage.addClass(defaultClass);
                    $availabilityMessage.addClass(msgClass);
                }
            },
            SetValidationError: function ($sizeSelector) {
                this.SetSplitSizeMessage(nxt.jstranslations.productpage.nosizemessage, "validationError", $sizeSelector);
                if (pdpSplitSizeEnabled) {
                    this.SetsplitSizeLabelValidation($sizeSelector);
                }
            },
            SetsplitSizeLabelValidation: function ($sizeSelector) {
                var $style = $sizeSelector.parents("article.Style");
                var itemNumber = $style.find(".StyleMeta .ItemNumber").text();
                $style.find(".Chips.splitSizeContainer[for=Size-" + itemNumber + "]")
                    .first()
                    .find(".splitSizeRow:visible")
                    .each(function () {
                        var splitSizeKey = $(this).find(" .splitSizeChips").attr("for");
                        var $splitSizeLabel = $(this).find($("label[for=" + splitSizeKey + " ]"));
                        if ($style.find(".splitSizeMessage[for=Size-" + itemNumber + "]").hasClass("validationError")) {
                            $splitSizeLabel.toggleClass("splitSizeLabelValidation", !$(this).find(" .splitSizeChips .splitSizeChip").hasClass("active"));
                        }
                        if ($(this).find("Select.splitSizeSelector").length > 0) {
                            $(this).find("Select.splitSizeSelector").each(function () {
                                var $SplitSizeDKContainer = $(this);
                                var splitSizeKey = $SplitSizeDKContainer.attr("for");
                                var $splitSizeLabel = $SplitSizeDKContainer.parent().find($("label[for=" + splitSizeKey + " ]")).length > 0 ? $(this).parent().find($("label[for=" + splitSizeKey + " ]")) : $(this).parent().parent().find($("label[for=" + splitSizeKey + " ]"));
                                if ($style.find(".splitSizeMessage[for=Size-" + itemNumber + "]").hasClass("validationError")) {
                                    $splitSizeLabel.toggleClass("splitSizeLabelValidation", !$SplitSizeDKContainer.val());
                                    $SplitSizeDKContainer.parent().find(".dk_label").toggleClass("er_prompt", !$SplitSizeDKContainer.val())
                                }
                                else {
                                    $splitSizeLabel.toggleClass("splitSizeLabelValidation", false);
                                    $SplitSizeDKContainer.parent().find(".dk_label").toggleClass("er_prompt", false);
                                }
                            })
                        }
                    });
            },
            SetSplitSizeStockDisplay: function ($sizeSelector) {
                var inStockStockStatus = "InStock";
                if (this.IsEnabled) {
                    var $selectedOption = $sizeSelector.find("option:selected");
                    this.ResetSplitSizeMessage($sizeSelector);
                    if ($selectedOption) {
                        var stockstatus = $selectedOption.data("stockstatus");
                        var stockmessage = $selectedOption.data("stockmessage");
                        if (stockstatus !== inStockStockStatus) {
                            this.SetSplitSizeMessage(stockmessage, stockstatus, $sizeSelector);
                        }
                        else if (!Next.Settings.Channel.ModularPDPSplitSize && (pdpChipsEnabled && ProductPage.Styles.pdpChipsShow()) && stockstatus === inStockStockStatus) {
                            this.SetSplitSizeMessage(stockmessage, stockstatus, $sizeSelector);
                        }
                    }
                }
            },
            PopulateSizeSelect: function ($itemnumber) {

                var $style = ProductPage.Vars.GetCurrentStyleElement();

                if ($style) {

                    var styleId = $style.data("styleid");
                    var style = undefined;

                    $.each(ProductPage.Vars.ItemData, function () {
                        if (this.StyleID == styleId) {
                            style = this;
                            return false;
                        }
                    });
                }

                var singleOption = false;

                $.each(style.Fits, function (i, f) {

                    $.each(f.Items, function (i, v) {
                        
                        if (v.ItemNumber == $itemnumber) {

                            var currentArticle = $('article[data-targetitem=\"' + $itemnumber + '\"]');
                            var styleId = currentArticle.attr("data-styleid");
                            var stylesection = $('[data-styleid=\"' + styleId + '\"]');
                            var sizeSelector = stylesection.find("select.SizeSelector");
                            var selectedValue = sizeSelector.find("option:selected").val();

                            var styleOptionId = "Size-" + $itemnumber;
                            sizeSelector.attr("id", styleOptionId);
                            stylesection.find(".sizeChipsContainer").attr("id", styleOptionId);
                            stylesection.find(".sizeAvailability").attr("for", styleOptionId);
                            stylesection.find(".availabilityMessage").attr("for", styleOptionId);
                            stylesection.find(".pdpChipPrice").attr("for", styleOptionId);
                            stylesection.find(".SizeGuideLink").attr("data-item-number", $itemnumber);

                            if (v.Options.length == 1) {
                                singleOption = true;
                            }

                            var firstOption;
                            if (!singleOption) {
                                firstOption = sizeSelector.find("option:nth-child(1)");
                            }

                            sizeSelector.empty();
                            if (!singleOption && firstOption) {
                                sizeSelector.append(firstOption);
                            }
                            sizeSelector.removeAttr("disabled");
                            sizeSelector.parent(".dk_container.SizeSelector").removeClass("dk-disable");
                            sizeSelector.attr("data-personalisedgifttheme", v.PersonalisedGiftTheme);
                            sizeSelector.attr("data-personalise", v.Personalisation);
                            sizeSelector.attr("data-ddfulfiller", v.DDFulfiller);
                            sizeSelector.attr("data-fulfilmenttype", v.FulfilmentType);
                            stylesection.find(".sizeChips").empty();
                            stylesection.find(".itemLabel.sizeLabel").attr("for", styleOptionId);
                            stylesection.find("div.sizeAvailability").empty();

                            var chipsSection = stylesection.find(".Chips.formControls");

                            var splitSection = stylesection.find(".splitSizeContainer");

                            var sizeChipsEnabled = (f.SizeChipsEnabled && !pdpChipsEnabled) || (pdpChipsEnabled && v.PDPChipsSizeEnabled && ProductPage.Styles.pdpChipsShow());

                            if (sizeChipsEnabled) {
                                if (!pdpChipsEnabled) {
                                    sizeChipsEnabled = !((Next.Settings.Channel.SizeChipsOnProductPageMaxCount > 0 && v.Options.length > Next.Settings.Channel.SizeChipsOnProductPageMaxCount)
                                        || (Next.Settings.Channel.SizeChipsOnProductPageMaxCharLimit > 0 && v.Options.find(n => n.Name.length > Next.Settings.Channel.SizeChipsOnProductPageMaxCharLimit) !== undefined));
                                }
                            }

                            if (sizeChipsEnabled) {
                                chipsSection.attr("style", "display:inline;");
                                sizeSelector.parents(".formControls").attr("style", "display:none;");
                                sizeSelector.parents(".DropDown").attr("style", "display:none;");
                                splitSection.attr("style", "display:none;");
                            }
                            if (pdpSplitSizeEnabled || ProductPage.Styles.SplitSize.IsEnabled($style)) {

                                chipsSection.attr("style", "display:none;");
                                splitSection.attr("style", "display:inline;");
                                splitSection.attr("for", styleOptionId);
                                splitSection.find(".splitSizeRow").attr("for", styleOptionId);
                                splitSection.empty();
                            }
                            if (!pdpSplitSizeEnabled && !sizeChipsEnabled) {
                                chipsSection.attr("style", "display:none;");
                                splitSection.attr("style", "display:none;");
                                sizeSelector.parents(".formControls").attr("style", "display:inline;");
                                sizeSelector.parents(".DropDown").attr("style", "display:inline;");
                            }

                            sizeSelector.parents(".DropDown").attr("data-id", styleOptionId);

                            if (singleOption) {
                                sizeSelector.attr("disabled", "disabled");
                                sizeSelector.parent(".dk_container.SizeSelector").addClass("dk-disable");
                            }

                            let bandOptionArray = [];
                            let cupOptionArray = [];

                            var intermediateChipClass = '';
                            $.each(v.Options, function () {

                                fit = this;

                                var currencySymbol = Next.Settings.Channel.CurrencySymbol || "£";

                                var price = parseFloat(fit.Price.replace(currencySymbol, '')).toFixed(2);

                                var datatag = '';
                                var priceformatted = '';
                                var itemname = fit.Name;
                                var stockStatus = '';
                                var selectedItem = '';
                                var chipActive = '';
                                var sizeType = '';

                                if (fit.Number == selectedValue) {
                                    selectedItem = 'selected';
                                    chipActive = 'active';
                                }
                                var multiplePriceOptions = v.Options.find(x => x.Price !== fit.Price);

                                if (multiplePriceOptions && fit.Price !== undefined && fit.Price !== '') {
                                    itemname = itemname + ' - ' + fit.Price;
                                    priceformatted = fit.Price;
                                }

                                if (pdpSplitSizeEnabled || ProductPage.Styles.SplitSize.IsEnabled($style)) {
                                    datatag = 'data-splitsizes-'
                                } else {
                                    datatag = 'data-'
                                }

                                if (fit.StockStatus !== undefined) {
                                    stockStatus = fit.StockStatus;
                                }

                                if (fit.SizeType !== undefined && fit.SizeType !== '') {
                                    sizeType = '=' + fit.SizeType;
                                }

                                if (intermediateChipClass === '' && Next.Settings.Channel.pdpSizeChipsIntermediateCharLimit && Next.Settings.Channel.pdpSizeChipsIntermediateCharLimit > 0 && fit.Name.length > Next.Settings.Channel.pdpSizeChipsIntermediateCharLimit) {
                                    intermediateChipClass = " chipOval";
                                }

                                stylesection.find(".sizeChips").append('<li tabindex="0" class="chipItem ' + chipActive + intermediateChipClass + '" ' + datatag + 'value=' + fit.Number + ' ' + datatag + 'price=' + price + ' ' + datatag + 'stockstatus=' + stockStatus + ' ' + datatag + 'size=\"' + fit.Name + '\" ' + datatag + 'sizetype' + sizeType + ' ' + datatag + 'stockmessage=' + fit.StockStatus + ' ' + datatag + 'priceformatted=\"' + priceformatted + '\"><span>' + fit.Name + '</span></li>');

                                var datatagband = '';
                                var datatagcup = '';

                                if ((pdpSplitSizeEnabled || ProductPage.Styles.SplitSize.IsEnabled($style)) && fit.SplitSizes.length > 0) {

                                    let band;
                                    let cup;

                                    if (Next.Settings.Channel.EnableMinifyShotJsonData) {
                                            band = fit.SplitSizes
                                                .filter(x => x.Properties[0].Value === 'Band')
                                                .map(x => x.Properties[1])
                                                .find(x => x.Key === 'Value');

                                            cup = fit.SplitSizes
                                                .filter(x => x.Properties[0].Value === 'Cup')
                                                .map(x => x.Properties[1])
                                                .find(x => x.Key === 'Value');
                                    }
                                    else {                                        
                                        band = fit.SplitSizes.find(ss => ss.Key == 'Band');
                                        cup = fit.SplitSizes.find(ss => ss.Key == 'Cup');
                                    }

                                    if (band && cup) {
                                        if ($.inArray(band.Value, bandOptionArray) === -1) {
                                            bandOptionArray.push(band.Value);
                                        }

                                        if ($.inArray(cup.Value, cupOptionArray) === -1) {
                                            cupOptionArray.push(cup.Value);
                                        }

                                        if (Next.Settings.Channel.EnableMinifyShotJsonData) {
                                            datatagband = 'data-splitsizes-band=\"' + band.Value + '\" ';
                                            datatagcup = 'data-splitsizes-cup=\"' + cup.Value + '\" ';
                                        }
                                        else {
                                            datatagband = 'data-splitsizes-band=\"' + fit.SplitSizes.find(ss => ss.Key == 'Band').Value + '\" ';
                                            datatagcup = 'data-splitsizes-cup=\"' + fit.SplitSizes.find(ss => ss.Key == 'Cup').Value + '\" ';
                                        }
                                    }
                                }

                                sizeSelector.append('<option value=' + fit.Number + ' ' + datatag + 'price=' + price + ' ' + datatag + 'priceformatted=\"' + priceformatted + '\" ' + datatag + 'stockstatus=' + stockStatus + '  ' + datatag + 'size=\"' + fit.Name + '\" ' + datatag + 'sizetype' + sizeType + ' ' + datatagband + ' ' + datatagcup + ' ' + selectedItem + ' style="color: black;">' + itemname + '</option>');
                            });

                            sizeSelector.dropkick("refresh");
                            bandOptionArray.sort();
                            cupOptionArray.sort();

                            if ((pdpSplitSizeEnabled || ProductPage.Styles.SplitSize.IsEnabled($style)) && bandOptionArray.length > 0 && cupOptionArray.length > 0) {

                                splitSection.append("<div for=\"" + styleOptionId + "\" class=\"formControls splitSizeRow\"><label for=\"Band\" class=\"itemLabel\">Band</label><ul for=\"Band\" class=\"splitSizeChips\"></ul></div>");
                                $.each(bandOptionArray, function (i, band) {
                                    let bandClasses = 'splitSizeChip asmsizechip';
                                    if (band.length > 4) {
                                        bandClasses = bandClasses + ' chipoval';
                                    }
                                    bandClasses = bandClasses + ' Band';
                                    let bandOptionItem = $("<li class=\"" + bandClasses + "\" data-value=\"" + band + "\"><span>" + band + "</span></li>");
                                    splitSection.find(".splitSizeChips[for='Band']").append(bandOptionItem);
                                });

                                splitSection.append("<div for=\"" + styleOptionId + "\" class=\"formControls splitSizeRow\"><label for=\"Cup\" class=\"itemLabel\">Cup</label><ul for=\"Cup\" class=\"splitSizeChips\"></ul><div class=\"splitSizeMessage\" for=\"" + styleOptionId + "\" style=\"display: none\"></div></div>");
                                $.each(cupOptionArray, function (i, cup) {
                                    let cupClasses = 'splitSizeChip asmsizechip';
                                    if (cup.length > 4) {
                                        cupClasses = cupClasses + ' chipoval';
                                    }
                                    cupClasses = cupClasses + ' Cup';
                                    let cupOptionItem = $("<li class=\"" + cupClasses + "\" data-value=\"" + cup + "\"><span>" + cup + "</span></li>");
                                    splitSection.find(".splitSizeChips[for='Cup']").append(cupOptionItem);
                                });
                            }

                            return false;
                        }
                    });

                });

                var stockData = EarlyStock.FetchStatus(EarlyStock.vars.ajaxUrl, $itemnumber);

                if (!Next.Settings.Channel.EnablePdpStockApiIntegration || stockData != null) {

                    EarlyStock.UpdateStatus(stockData, $itemnumber);
                }

                ProductDetails.Styles.RefreshOptionStockStatus($style, $itemnumber);

                if (pdpSplitSizeEnabled || ProductPage.Styles.SplitSize.IsEnabled($style)) {
                    $style.find(".Chips.splitSizeContainer[for=Size-" + $itemnumber + "]")
                        .first()
                        .find(".splitSizeRow")
                        .each(function () {
                            ProductPage.Styles.SplitSize.BindClickEventForChips($(this).find("label").attr("for"), $style);
                        });
                    ProductPage.Styles.SplitSize.UpdateSplitSizeSelection($("select.SizeSelector"));
                }
            },
            UpdateSplitSizeSelection: function ($sizeSelector) {
                var $style = pdpChipsEnabled ? $sizeSelector.parents("article.Style") : ProductPage.Vars.GetCurrentStyleElement();
                $selectedOption = $sizeSelector.find("option:selected").first();
                var sizeId = $sizeSelector.attr('id');
                var $splitSizeContainer = $style.find(".splitSizeContainer[for=" + sizeId + "]");
                if (pdpSplitSizeEnabled &&  $splitSizeContainer.find(".splitSizeRow .splitSizeSelector").length > 0) {
                    $splitSizeContainer.find(".splitSizeRow .splitSizeSelector select").val('');
                    $splitSizeContainer.find(".splitSizeRow .splitSizeSelector .dk_options ul li").removeClass("dk_option_current");
                    $splitSizeContainer.find(".splitSizeRow .splitSizeSelector").find(".dk_label").text("Choose Size");
                }
                else {
                    $splitSizeContainer.find(".splitSizeRow .splitSizeChips .splitSizeChip").removeClass("active");
                }

                if (pdpChipsEnabled && ProductPage.Styles.SplitSize.IsEnabled($style)) {
                    if ($splitSizeContainer.find(".splitSizeRow .splitSizeChips:visible").length > 0) {
                        $splitSizeContainer.find(".splitSizeRow .splitSizeChips:visible").each(function () {
                            var splitSizeKey = $(this).attr("for");
                            var optionValueForKey = $selectedOption.data("splitsizes" + splitSizeKey);
                            $(this).find(".splitSizeChip").each(function () {
                                if ($(this).data("value") != undefined) {
                                    var chipValue = $(this).data("value").toString().replace(/("$)/g, '');
                                    if (optionValueForKey == chipValue) {
                                        $(this).addClass("active").siblings().removeClass("active");
                                        return false;
                                    }
                                }
                                else {
                                    var chipValue = $(this).data("value");
                                    if (optionValueForKey === chipValue) {
                                        $(this).addClass("active").siblings().removeClass("active");
                                        return false;
                                    }
                                }
                            });
                        });
                    }
                    $splitSizeContainer.find(".splitSizeRow:visible").each(function () {
                        var $SplitSizeddl = $splitSizeContainer.find("Select.splitSizeSelector");
                        $SplitSizeddl.each(function () {
                            var splitSizeKey = $(this).attr("for");
                            var optionValueForKey = $selectedOption.data("splitsizes" + splitSizeKey);
                            $(this).find("option").each(function () {
                                if ($(this).val() != "") {
                                    var optionValue = $(this).val().toString().replace(/("$)/g, '');
                                    if (optionValueForKey == optionValue) {
                                        $(this).parent().val(optionValueForKey);
                                        var $Optli = $(this).parent().parent();
                                        $Optli.find("ul li").each(function () {
                                            var Opt = $(this);
                                            if (Opt[0].innerText == optionValue) {
                                                Opt.addClass("dk_option_current");
                                                $Optli.find(".dk_label").text(optionValue);
                                                //Temp Error Border Fix
                                                var itemNumber = $style.find(".StyleMeta .ItemNumber").text();
                                                if ($style.find(".splitSizeMessage[for=Size-" + itemNumber + "]").hasClass("validationError")) {
                                                    $Optli.find(".dk_label").addClass("er_prompt");
                                                }
                                                else {
                                                    $Optli.find(".dk_label").removeClass("er_prompt");
                                                }
                                            }
                                        })
                                        return false;
                                    }
                                }
                                else {
                                    var optionValue = $(this).val();
                                    if (optionValueForKey === optionValue) {
                                        $(this).parent().val(optionValueForKey);
                                        return false;
                                    }
                                }
                            })
                        })
                    })

                }
                else {
                    $splitSizeContainer.find(".splitSizeRow .splitSizeChips").each(function () {
                        var splitSizeKey = $(this).attr("for");
                        var optionValueForKey = $selectedOption.data("splitsizes" + splitSizeKey);
                        $(this).find(".splitSizeChip").each(function () {
                            if ($(this).data("value") != undefined) {
                                var chipValue = $(this).data("value").toString().replace(/("$)/g, '');
                                if (optionValueForKey == chipValue) {
                                    $(this).addClass("active").siblings().removeClass("active");
                                    return false;
                                }
                            }
                            else {
                                var chipValue = $(this).data("value");
                                if (optionValueForKey === chipValue) {
                                    $(this).addClass("active").siblings().removeClass("active");
                                    return false;
                                }
                            }
                        });
                    });
                }

                this.UpdateSizesAvailability($sizeSelector);
                if (Next.Settings.Channel.SoldoutColourChipStyle !== "") {
                    var stockstatus = $selectedOption.data("stockstatus");
                    var $colourChipsElement = $style.find("ul.colourChips");
                    var isActiveChipSoldout = false;
                    if ($colourChipsElement.parents(".Chips").length > 0 && $colourChipsElement.parents(".Chips").is(":visible")) {
                        var $activeColourChip = $colourChipsElement.find("li.active");
                        if ($activeColourChip.length > 0) {
                            isActiveChipSoldout = $activeColourChip.hasClass("SoldoutChip");
                        }
                    }
                    var isSoldoutMessageOnScreen = $(".ItemSoldOutMessage").css("display") == "block";
                    if (stockstatus) {
                        if (stockstatus == "SoldOut" || isActiveChipSoldout || isSoldoutMessageOnScreen) {
                            ProductPage.TogglePDPDisplayForSoldoutItem(false);
                        } else {
                            ProductPage.TogglePDPDisplayForSoldoutItem(true);
                        }
                    }
                }
            },
            
           SetSplitSizeInitialSelection: function ($style) {
                var activeFit;
                var hasFitChip = $style.find(".fitChips").length > 0;
                var selectedSplitFit = $style.find(".fitChips .chipItem.active").attr("data-value");
                var itemNumber = $style.data("targetitem");
               var splitSizeOrder = Next.Settings.Channel.PdpChipsSplitSizeOrderKey;
               var splitSizeOrderArray = splitSizeOrder.split(",");
                if (!ProductPage.Styles.SplitSize.IsEnabled($style) && ProductPage.Styles.SplitSize.SplitFitEnabled()) {
                    var $currentSizeSelector = $("select.SizeSelector#Size-" + itemNumber + selectedSplitFit);
                }
                else {
                    var $currentSizeSelector = $("select.SizeSelector#Size-" + itemNumber);
                }
                var sizeId = $currentSizeSelector.attr('id');
                var $splitSizeContainer = $style.find(".splitSizeContainer[for=" + sizeId + "]");
              
                var $itemData = ProductPage.Styles.GetPageDataForItem(itemNumber);
               var fitList = [];
               var availableOrderList = [];
                var options = $itemData.item.Options;
                var fitName = $itemData.fit.Name;
                var key;
               var $activeChip;
               if (pdpSplitSizeEnabled) {
                   if (options[0].SplitSizes.length > 1 || ProductPage.Styles.SplitSize.IsSingleSplitSizeItem()) {
                       $.each(options, function (i, opt) {
                           var firstSplitValue = opt.SplitSizes[0].Value;
                           key = opt.SplitSizes[0].Key;
                           if (hasFitChip) {
                               if (opt.FitSizes[0] && opt.FitSizes[0].Value == selectedSplitFit) {
                                   if (opt.FitSizes[0].Value == selectedSplitFit && fitList.indexOf(firstSplitValue) == -1) {
                                       fitList.push(firstSplitValue);
                                   }
                               }
                               else if (fitName) {
                                   if (fitName == selectedSplitFit && fitList.indexOf(firstSplitValue) == -1) {
                                       fitList.push(firstSplitValue);
                                   }
                               }

                           }
                           else {
                               if (fitList.indexOf(firstSplitValue) == -1) {
                                   fitList.push(firstSplitValue);
                               }
                           }

                       });
                       if (fitList) {
                           availableOrderList = fitList.filter(x => splitSizeOrderArray.indexOf(x) !== -1);
                           if (availableOrderList.length > 0) {
                               if (availableOrderList.includes("Regular")) {
                                   activeFit = "Regular";
                               }
                               else {
                                   activeFit = availableOrderList[0];
                               }
                           }
                           else {
                               activeFit = fitList[0];
                           }
                       }

                       if ($splitSizeContainer.length > 0) {
                           $splitSizeContainer
                               .find(".splitSizeRow:visible .splitSizeChips[for=" + key + "] .splitSizeChip")
                               .each(function () {
                                   if ($(this).attr("data-value") == activeFit) {
                                       $activeChip = $(this);
                                   }
                               });
                       }

                       if ($activeChip != undefined) {
                           $activeChip.addClass("active").siblings().removeClass("active");
                               if ($activeChip.parent().siblings(".splitSizeSelector").length)
                                   $activeChip.parent().siblings(".splitSizeSelector").find("select").dropkick("setValue", $activeChip.data("value"));
                               ($activeChip.hasClass("unavailable")) ?
                                   $activeChip.parents(".splitSizeContainer").parent().find(".btn-addtobag").removeClass("Enabled").addClass("disabled") :
                                   $activeChip.parents(".splitSizeContainer").parent().find(".btn-addtobag").removeClass("disabled").addClass("Enabled");

                           ProductPage.Styles.SplitSize.UpdateSizesAvailability($currentSizeSelector);
                               if (ProductPage.Styles.SplitSize.IsResetDropdown(itemNumber))
                                   ProductPage.Styles.SplitSize.ResetDropDownChipVisibility(itemNumber, $activeChip);
                           if (ProductPage.Styles.SplitSize.SelectionComplete($currentSizeSelector)) {
                               var selectorValue = ProductPage.Styles.SplitSize.GetSizeSelectorValueForSplitSize($currentSizeSelector);
                               if (selectorValue) {
                                   $currentSizeSelector.dropkick("setValue", selectorValue);
                                   if (pdpChipsEnabled && ProductPage.Styles.SplitSize.IsEnabled($style)) {
                                       ProductPage.Styles.SplitSize.SetSplitSizeStockDisplay($currentSizeSelector);
                                   }
                               }
                           }
                           else {
                               $currentSizeSelector.prop("selectedIndex", 0);
                           }

                           // ProductPage.Styles.SplitSize.ResetDropDownChipVisibility(itemNumber, $clickedChip);
                       }

                       if (pdpSplitSizeEnabled) {
                           ProductPage.Styles.SplitSize.SetsplitSizeLabelValidation($currentSizeSelector);
                       }
                   }
               }
            },
            SelectedSplitSize: function ($sizeSelector) {
                var $style = pdpChipsEnabled ? $sizeSelector.parents("article.Style") : ProductPage.Vars.GetCurrentStyleElement();
                var sizeId = $sizeSelector.attr('id');
                var $splitSizeContainer = $style.find(".splitSizeContainer[for=" + sizeId + "]");

                var currentFilter = {};
                if (pdpChipsEnabled && ProductPage.Styles.SplitSize.IsEnabled($style)) {
                    $splitSizeContainer.find(".splitSizeRow:visible").each(function () {
                        $splitSizeChips = $(this).find(".splitSizeChips");
                        if ($splitSizeChips.length > 0) {
                            $splitSizeChips.each(function () {
                                var splitSizeKey = $(this).attr("for");
                                var $selectedChip = $(this).find(".splitSizeChip.active").first();
                                if ($selectedChip) {
                                    if (pdpChipsEnabled && ProductPage.Styles.SplitSize.IsEnabled($style) && $selectedChip.data("value") != undefined) {
                                        currentFilter[splitSizeKey] = $selectedChip.data("value").toString().replace(/("$)/g, ''); //.replace(/"/g, '');
                                    }
                                    else {
                                        currentFilter[splitSizeKey] = $selectedChip.data("value");
                                    }
                                }
                            });
                        }
                    });

                    $splitSizeContainer.find(".splitSizeRow:visible").each(function () {
                        var $SplitSizeddl = $(this).find("Select.splitSizeSelector");
                        var splitSizeKey = $SplitSizeddl.attr("for");
                        var $ddl = $(this);
                        var $style = $ddl.parents("article.Style");
                        if ($SplitSizeddl.length > 0) {
                            var $selectedOpt = $SplitSizeddl.find("option:selected");
                            if ($selectedOpt) {
                                if (pdpChipsEnabled && ProductPage.Styles.SplitSize.IsEnabled($style) && $selectedOpt.val() != undefined) {
                                    currentFilter[splitSizeKey] = $selectedOpt.val() == "" ? undefined : $selectedOpt.val().toString().replace(/("$)/g, '');
                                }
                                else {
                                    currentFilter[splitSizeKey] = $selectedOpt.val();
                                }
                            }
                        }
                    });
                    return currentFilter;
                }
                else {
                    $splitSizeContainer.find(".splitSizeRow .splitSizeChips").each(function () {
                        var splitSizeKey = $(this).attr("for");
                        var $selectedChip = $(this).find(".splitSizeChip.active").first();
                        if ($selectedChip) {
                            if (pdpChipsEnabled && ProductPage.Styles.SplitSize.IsEnabled($style) && $selectedChip.data("value") != undefined) {
                                currentFilter[splitSizeKey] = $selectedChip.data("value").toString().replace(/("$)/g, ''); //.replace(/"/g, '');
                            }
                            else {
                                currentFilter[splitSizeKey] = $selectedChip.data("value");
                            }
                        }
                    });
                    return currentFilter;
                }
            },
            GetAvailableKeys: function ($sizeSelector) {
                var $style = pdpChipsEnabled ? $sizeSelector.parents("article.Style") : ProductPage.Vars.GetCurrentStyleElement();
                var sizeId = $sizeSelector.attr('id');
                var $splitSizeContainer = $style.find(".splitSizeContainer[for=" + sizeId + "]");

                var splitSizeKeys = [];
                if (pdpChipsEnabled && ProductPage.Styles.SplitSize.IsEnabled($style)) {
                    $splitSizeContainer.find(".splitSizeRow").each(function () {
                        $splitSizeChips = $(this).find(".splitSizeChips");
                        if (splitSizeChips = $(this).find(".splitSizeChips").length > 0) {
                            $splitSizeChips.each(function () {
                                var splitSizeKey = $(this).attr("for");
                                splitSizeKeys.push(splitSizeKey);
                            });
                        }
                        if ($(this).find("Select.splitSizeSelector").length > 0) {
                            var $SplitSizeddl = $(this).find("Select.splitSizeSelector");
                            splitSizeKey = $SplitSizeddl.attr("for");
                            splitSizeKeys.push(splitSizeKey);
                        }
                    });
                }
                else {
                    $splitSizeContainer.find(".splitSizeRow .splitSizeChips").each(function () {
                        var splitSizeKey = $(this).attr("for");
                        splitSizeKeys.push(splitSizeKey);
                    });
                }
                return splitSizeKeys;
            },
            SelectionComplete: function ($sizeSelector) {
                var selection = this.SelectedSplitSize($sizeSelector);
                var keys = this.GetAvailableKeys($sizeSelector);
                var result = true;
                $.each(keys, function (_, key) {
                    if (!selection[key]) {
                        return result = false;
                    }
                });
                return result;
            },
            GetSizeSelectorValueForSplitSize: function ($sizeSelector) {
                var $style = pdpChipsEnabled ? $sizeSelector.parents("article.Style") : ProductPage.Vars.GetCurrentStyleElement();
                var sizeId = $sizeSelector.attr('id');
                var $splitSizeContainer = $style.find(".splitSizeContainer[for=" + sizeId + "]");
                var result = undefined;
                var selectedSplitSize = this.SelectedSplitSize($sizeSelector);
                var selectedSplitFit = $style.find(".fitChips .chipItem.active").attr("data-value");
                var keys = this.GetAvailableKeys($sizeSelector);
                var hasFitChipData = ProductPage.Vars.$itemsContainer.find("ul.fitChips li") != 0 &&
                    $splitSizeContainer.find("ul.splitSizeChips li").attr("data-fit") != "";
                if (selectedSplitSize && keys) {
                    $sizeSelector.find("option").each(function () {
                        $option = $(this);
                        var match = true;
                        $.each(keys, function (_, key) {
                            var value = $option.data("splitsizes" + key);
                            var splitFits = $option.data("splitfits");
                            if (value != selectedSplitSize[key] || (pdpSplitSizeEnabled &&  hasFitChipData && splitFits != selectedSplitFit)) {
                                return match = false;
                            }
                        });

                        if (match) {
                            result = $option.val();
                            return false;
                        }
                    });
                }
                return result;
            },
            DeselectChip: function ($chip, $sizeSelector) {
                if ($chip.hasClass("active")) {
                    $chip.removeClass("active")
                    $sizeSelector.dropkick("setValue", "");
                    ProductPage.Styles.SplitSize.ResetSplitSizeMessage($sizeSelector);
                }
            },
            UpdateSizesAvailability: function ($sizeSelector) {
                var $style = pdpChipsEnabled ? $sizeSelector.parents("article.Style") : ProductPage.Vars.GetCurrentStyleElement();
                var sizeId = $sizeSelector.attr('id');
                var $splitSizeContainer = $style.find(".splitSizeContainer[for=" + sizeId + "]");

                var currentFilter = this.SelectedSplitSize($sizeSelector);
                var splitSizeKeys = this.GetAvailableKeys($sizeSelector);
                var selectedFit = $style.find("ul.fitChips li.active").data("value");
                var options = [];
                $sizeSelector.find("option").each(function () {
                    $option = $(this);
                    var option = {
                        stockstatus: $option.data("stockstatus"),
                        fitSize: $option.data("splitfits")
                    };
                    splitSizeKeys.forEach(function (key) {
                        option[key] = $option.data("splitsizes" + key);
                    });
                    options.push(option);
                });

                splitSizeKeys.forEach(function (key) {
                    if (pdpChipsEnabled && ProductPage.Styles.SplitSize.IsEnabled($style)) {
                        if ($splitSizeContainer.length > 0) {
                            $splitSizeContainer
                                .find(".splitSizeRow .splitSizeChips[for=" + key + "] .splitSizeChip")
                                .each(function () {
                                    var $chip = $(this);
                                    var chipValue = $chip.data("value").toString().replace(/("$)/g, '');
                                    var shouldBeHiddenIfNoOption = false;
                                    var allChildOptionsUnavailable = undefined;
                                    var allOptionsUnavailable = true;
                                    var option = undefined;
                                    $.each(options, function (_, opt) {
                                        var result = false;
                                        $.each(currentFilter, function (filterField, filterValue) {
                                            if (filterField === key) {
                                                if (result) {
                                                    result = opt[key] == chipValue;
                                                }
                                                if (allChildOptionsUnavailable === undefined) {
                                                    allChildOptionsUnavailable = true;
                                                }
                                                if (pdpSplitSizeEnabled && ProductPage.Styles.SplitSize.SplitFitEnabled() && selectedFit !== undefined && opt.fitSize !== undefined) {
                                                    if (opt[key] == chipValue && opt.fitSize.trim() === selectedFit.trim() && opt.stockstatus !== "SoldOut") {
                                                        allChildOptionsUnavailable = false;
                                                    }
                                                }
                                                else {
                                                    if (opt[key] == chipValue && opt.stockstatus !== "SoldOut") {
                                                        allChildOptionsUnavailable = false;
                                                    }
                                                }
                                                return false;
                                            }
                                            if (filterValue) {
                                                result = opt[filterField] == filterValue;
                                                shouldBeHiddenIfNoOption = true;
                                            }
                                            else {
                                                return false;
                                            }
                                        });
                                        if (opt.stockstatus && opt.stockstatus != "" && opt.stockstatus !== "SoldOut") {
                                            allOptionsUnavailable = false;
                                        }

                                        if (result && option === undefined) {
                                            option = opt;
                                        }
                                    });
                                    if (option === undefined && shouldBeHiddenIfNoOption) {
                                        $chip.hide();
                                        ProductPage.Styles.SplitSize.DeselectChip($chip, $sizeSelector);
                                    }
                                    else if ((option && (option.stockstatus === "SoldOut" || (!Next.Settings.Channel.ModularPDPSplitSize && (pdpChipsEnabled && ProductPage.Styles.pdpChipsShow()) && option.stockstatus === "SaleSoldOut"))) || allChildOptionsUnavailable || allOptionsUnavailable) {
                                        $chip.show();
                                        $chip.addClass("unavailable");
                                    }
                                    else {
                                        $chip.show();
                                        $chip.removeClass("unavailable");
                                    }
                                });
                        }

                        $splitSizeContainer.find("Select.splitSizeSelector." + key).find("option").each(function () {
                            var $SplitSizeOption = $(this);
                            var SplitSizeValue = $SplitSizeOption.val() == "" ? undefined : $SplitSizeOption.val();
                            var shouldBeHiddenIfNoOption = false;
                            var allChildOptionsUnavailable = undefined;
                            var allOptionsUnavailable = true;
                            var option = undefined;
                            $.each(options, function (_, opt) {
                                var result = false;
                                $.each(currentFilter, function (filterField, filterValue) {
                                    if (filterField === key) {
                                        if (result) {
                                            result = opt[key] == SplitSizeValue;
                                        }
                                        if (allChildOptionsUnavailable === undefined) {
                                            allChildOptionsUnavailable = true;
                                        }
                                        if (opt[key] == SplitSizeValue && opt.stockstatus !== "SoldOut") {
                                            allChildOptionsUnavailable = false;
                                        }
                                        return false;
                                    }
                                    if (filterValue) {
                                        result = opt[filterField] == filterValue;
                                        shouldBeHiddenIfNoOption = true;
                                    }
                                    else {
                                        return false;
                                    }
                                });
                                if (opt.stockstatus && opt.stockstatus != "" && opt.stockstatus !== "SoldOut") {
                                    allOptionsUnavailable = false;
                                }

                                if (result && option === undefined) {
                                    option = opt;
                                }
                            });
                            if (option === undefined && shouldBeHiddenIfNoOption && $SplitSizeOption[0].index != 0) {
                                $SplitSizeOption.hide();
                                if ($SplitSizeOption.val() == $SplitSizeOption.parent().find("option:selected").val()) {
                                    $SplitSizeOption.parent().prop("selectedIndex", 0);
                                    $SplitSizeOption.parent().parent().find("ul li").removeClass("dk_option_current")
                                    $SplitSizeOption.parent().parent().find(".dk_label").text("Choose Size");
                                    $SplitSizeOption.parent().val("Choose Size");
                                    ProductPage.Styles.SplitSize.ResetSplitSizeMessage($SplitSizeOption);
                                }
                                var $SelectItemOptions = $SplitSizeOption.parent().parent().find('.dk_dropdown_option');
                                $SelectItemOptions.each(function () {
                                    var Opt = $(this);
                                    if (Opt[0].innerText == $SplitSizeOption[0].innerText) {
                                        Opt.parent().hide();
                                    }
                                })
                            }
                            else if ((option && (option.stockstatus === "SoldOut" || (!Next.Settings.Channel.ModularPDPSplitSize && (pdpChipsEnabled && ProductPage.Styles.pdpChipsShow()) && option.stockstatus === "SaleSoldOut"))) || allChildOptionsUnavailable || allOptionsUnavailable) {
                                $SplitSizeOption.show();
                                var $SelectItemOptions = $SplitSizeOption.parent().parent().find('.dk_dropdown_option');
                                $SelectItemOptions.each(function () {
                                    var Opt = $(this);
                                    if (Opt[0].innerText == $SplitSizeOption[0].innerText) {
                                        Opt.parent().show();
                                    }
                                })

                            }
                            else {
                                $SplitSizeOption.show();
                                var $SelectItemOptions = $SplitSizeOption.parent().parent().find('.dk_dropdown_option');
                                $SelectItemOptions.each(function () {
                                    var Opt = $(this);
                                    if (Opt[0].innerText == $SplitSizeOption[0].innerText) {
                                        Opt.parent().show();
                                    }
                                })
                            }
                        });
                    }
                    else {
                        $splitSizeContainer
                            .find(".splitSizeRow .splitSizeChips[for=" + key + "] .splitSizeChip")
                            .each(function () {
                                var $chip = $(this);
                                var chipValue = $chip.data("value");
                                var shouldBeHiddenIfNoOption = false;
                                var allChildOptionsUnavailable = undefined;
                                var allOptionsUnavailable = true;
                                var option = undefined;
                                $.each(options, function (_, opt) {
                                    var result = false;
                                    $.each(currentFilter, function (filterField, filterValue) {
                                        if (filterField === key) {
                                            if (result) {
                                                result = opt[key] == chipValue;
                                            }

                                            if (allChildOptionsUnavailable === undefined) {
                                                allChildOptionsUnavailable = true;
                                            }

                                            if (opt[key] == chipValue && opt.stockstatus !== "SoldOut") {
                                                allChildOptionsUnavailable = false;
                                            }

                                            return false;
                                        }

                                        if (filterValue) {
                                            result = opt[filterField] == filterValue;
                                            shouldBeHiddenIfNoOption = true;
                                        }
                                        else {
                                            return false;
                                        }
                                    });

                                    if (opt.stockstatus && opt.stockstatus != "" && opt.stockstatus !== "SoldOut") {
                                        allOptionsUnavailable = false;
                                    }

                                    if (result && option === undefined) {
                                        option = opt;
                                    }
                                });
                                if (option === undefined && shouldBeHiddenIfNoOption) {
                                    $chip.hide();
                                    ProductPage.Styles.SplitSize.DeselectChip($chip, $sizeSelector);
                                }
                                else if ((option && (option.stockstatus === "SoldOut" || (!Next.Settings.Channel.ModularPDPSplitSize && (pdpChipsEnabled && ProductPage.Styles.pdpChipsShow()) && option.stockstatus === "SaleSoldOut"))) || allChildOptionsUnavailable || allOptionsUnavailable) {
                                    $chip.show();
                                    $chip.addClass("unavailable");
                                }
                                else {
                                    $chip.show();
                                    $chip.removeClass("unavailable");
                                }
                            });
                    }
                });
            }
        },
        PDPStyleDescription: {
            SetTitleAsSearchDescription: function (clickedElement, itemData) {
                const titleElement = $(clickedElement).closest(".StyleCopy").find(".Title");
                const parentElement = $(clickedElement).closest(".StyleCopy");
                let itemSearchDescription = this.GetItemSearchDescription(itemData.item, itemData.style);
                if (itemSearchDescription) {
                    this.GetTitleDisplayElement(parentElement, titleElement).text(itemSearchDescription);
                    return true;
                }
                return false;
            },
            GetItemSearchDescription(item, style) {
                let searchDescription = this.TPSearchDescriptionEnabled() && item.TPSearchDescription ?
                    item.TPSearchDescription :
                    item.SearchDescription;
                if (ProductPage.Vars.IsChanelBrandPDPEnabled || Next.Settings.Channel.PDPStyleDescription.RemoveBrandFromSearchDescription) {
                    const brand = ProductPage.Vars.ItemData[0].Brand;
                    searchDescription = this.RemoveBrandFromSearchDescription(searchDescription, brand);
                }

                if (Next.Settings.Channel.PDPStyleDescription.RemoveProductNameFromSearchDescription) {
                    searchDescription = this.RemoveBrandFromSearchDescription(searchDescription, style.ProductName)
                }

                if (this.RangeEnabledAndNotInSeparateLineAndItemHasRange(item)) {
                    searchDescription = this.GetItemNameWithRange(searchDescription, item.Range);
                }

                return searchDescription;
            },
            RemoveBrandFromSearchDescription(searchDescription, brand) {
                if (!searchDescription.toLowerCase().includes(brand.toLowerCase())) {
                    return searchDescription;
                }
                let startIndex = searchDescription.toLowerCase().indexOf(brand.toLowerCase());
                let endIndex = searchDescription.toLowerCase().indexOf(brand.toLowerCase()) + brand.length;
                searchDescription = searchDescription.substring(0, startIndex) +
                    searchDescription.substring(endIndex, searchDescription.length);
                return searchDescription;
            },
            TPSearchDescriptionEnabled() {
                return Next.Settings.Channel.TotalPlatformFeatures.IsEnabled && Next.Settings.Channel.TotalPlatformFeatures.TPSearchDescriptionEnabled;
            },
            GetItemNameForReviews(itemData) {
                let itemName = this.GetItemSearchDescription(itemData.item, itemData.style);

                if (Next.Settings.Channel.TotalPlatformFeatures.PDPShowProductDetailsAsH1) {
                    itemName = this.GetItemNameWithProductName(itemName, itemData.style.ProductName);
                }

                if (this.RangeEnabledAndInSeparateLine() && itemData.item.Range) {
                    //if range should be in the separate line, then it won't be returned from GetItemSearchDescription.
                    itemName = this.GetItemNameWithRange(itemName, itemData.item.Range)

                }

                return itemName;
            },
            GetItemNameWithProductName(itemName, productName) {
                return productName + " " + itemName;
            },
            GetItemNameWithRange(itemName, range) {
                return range + " " + itemName;
            },
            GetTitleDisplayElement(parentElement, titleElement) {
                if (parentElement.find(".Title h1").length > 0)
                    return titleElement.find('h1');
                else if ($('.StyleCopy .StyleHeader .Title').length > 0)
                    return $('.StyleCopy .StyleHeader .Title h1').first();
                else if (parentElement.find(".Title h2").length > 0)
                    return titleElement.find('a');
                else if (parentElement.find(".chanelTitle").length > 0)
                    return titleElement.find('.subBrandName-upperCase');
            },
            SetUrlWhenColorFitTypeOrVolumeChanged: function (selectedItemData, wholeItemData, isSingleItem) {
                UpdateSelectedItemNumbers();
                SetUrl();

                function UpdateSelectedItemNumbers() {
                    let itemNumber = selectedItemData.item.ItemNumber.replace("-", "");

                    if (!this.itemNumbers || isSingleItem) {
                        this.itemNumbers = [itemNumber];
                    }
                    else if (!this.itemNumbers.includes(itemNumber)) {
                        const sameItemDifferentFitOrColourItems = wholeItemData.filter(
                            i => i.Fits.some(
                                f => f.Items.some(
                                    it => it.ItemNumber.replace("-", "") === itemNumber)));
                        const sameItemDifferentFitOrColourItemNumbers = sameItemDifferentFitOrColourItems
                            .flatMap(s => s.Fits)
                            .flatMap(f => f.Items)
                            .map(i => i.ItemNumber.replace("-", ""));

                        for (let numberToRemove of sameItemDifferentFitOrColourItemNumbers) {
                            let index = this.itemNumbers.indexOf(numberToRemove);
                            if (index > -1) {
                                this.itemNumbers.splice(index, 1);
                            }
                        }

                        this.itemNumbers.push(itemNumber);
                    }
                }

                function SetUrl() {
                    let hash = '';

                    if (isSingleItem) {
                        hash = "#" + this.itemNumbers[0];
                    }
                    else {
                        hash = "#" + this.itemNumbers[0] + "/" + this.itemNumbers.slice(1).join("-");
                    }
                    if (window.location.hash != hash) {
                        //Change Url
                        window.history.replaceState("#changed", null, Next.Settings.Channel.SiteUrl + ModularPDPHelper.getNewUrlWithHash(hash));
                    }
                }
            },
            RangeEnabledAndInSeparateLine() {
                return this.TPSearchDescriptionEnabled() &&
                    Next.Settings.Channel.TotalPlatformFeatures.RangeEnabled &&
                    Next.Settings.Channel.PDPStyleDescription.DisplayRangeOnSeparateLine;
            },
            RangeEnabledAndNotInSeparateLineAndItemHasRange(item) {
                return this.TPSearchDescriptionEnabled() &&
                    Next.Settings.Channel.TotalPlatformFeatures.RangeEnabled &&
                    !Next.Settings.Channel.PDPStyleDescription.DisplayRangeOnSeparateLine &&
                    (item.Range !== null && item.Range.trim() !== '');
            },
            HandleRange($currentStyle, currentItemData) {
                if (this.RangeEnabledAndInSeparateLine()) {
                    if (currentItemData.item.Range) {
                        this.SetRangeOnSeparateLine($currentStyle, currentItemData);
                    }
                    else {
                        this.RemoveRangeLine($currentStyle, currentItemData);
                    }
                }
            },
            SetRangeOnSeparateLine($currentStyle, currentItemData) {
                $titleDiv = $currentStyle.find("div.Title");
                $rangeh2 = $titleDiv.find("h2.range");
                if ($rangeh2.length == 0) {
                    $titleDiv.prepend($("<h2></h2>").addClass("range line-clamp").attr("data-line-clamp", "2"));
                    $rangeh2 = $titleDiv.find("h2.range");
                    $currentStyle.find(".Price").addClass("price-min-height");
                }
                $rangeh2.text(currentItemData.item.Range);
            },
            RemoveRangeLine($currentStyle, currentItemData) {
                $titleDiv = $currentStyle.find("div.Title");
                $rangeh2 = $titleDiv.find("h2.range").remove();
                $currentStyle.find(".Price").removeClass("price-min-height");
            }
        }
    },
    RecentlyViewed: {
        Init: function () {
            var _this = this;

            // Add the item to the Recently Viewed list
            _this.SaveOnLoad();
        },
        Vars: {
            HasGetSucceeded: false
        },
        SaveOnLoad: function () {

            var _this = this;

            function doSave() {
                if (typeof NextBasket === "undefined" || NextBasket.VisitorID === "") {
                    setTimeout(function () {
                        doSave();
                    }, 100);
                } else {
                    if (Next.Settings.Channel.RvDisplayInPage) {
                        _this.GetRecentlyViewedGlobal(NextBasket.VisitorID);
                    }
                }
            }

            function settingsReady() {
                var settings = Next.FeatureManager.FeatureSettings.RecentlyViewed;
                if (settings.DisplayInPage || settings.DisplayInFooter) {
                    doSave();
                }
            }

            if (FeatureSettingsLoaded) {
                settingsReady();
            } else {
                $(document).on("featureSettingsReady", function () {
                    settingsReady();
                });
            }
        },
        GetRecentlyViewedGlobal: function (visitorId) {
            //<summary>This method loads the recently viewed data and stores that returned data in a global</summary>

            var _this = this;

            RecentlyViewed.getRecentlyViewed(
                visitorId,
                function (data) {
                    recentlyViewedGlobal = data;

                    _this.Vars.HasGetSucceeded = true;

                    //Only save on load if we don't have a hash param - if there is a hash param, the save will be handled by selecting the item itself
                    if (window.location.hash === null || window.location.hash === "") {
                        _this.SaveViewedItem();
                    }

                    //But - if we've targeted a size option, setting the value wont trigger a click so we need to save an item selected by size
                    if (window.location.hash !== null && window.location.hash.indexOf('?i=') > -1) {
                        _this.SaveFromHashSelection();
                    }
                },
                function () {

                    //On error, we still need to set recentlyViewedGlobal to an empty array.
                    //This means the save RV method still passes the check to make sure we have something in recentlyViewedGlobal
                    recentlyViewedGlobal = [];
                });
        },
        SaveViewedItem: function (saveItemNumber, itemWrapper) {


            var _this = this;

            var fullItemNumber;

            if (!itemWrapper) {
                itemWrapper = ProductPage.Vars.$productDetail.find("article.Selected");
            }

            var $itemWrapper = $(itemWrapper);

            //Grab selected item number - this will either be the value of a hidden field or a select list
            if ($itemWrapper.find("input.hdnItmId").length) {
                fullItemNumber = $itemWrapper.find("input.hdnItmId").val();
            } else {
                fullItemNumber = $itemWrapper.find("select.subStyleList").val();
            }

            //Add the item to the interaction list
            interactionList.push(fullItemNumber);
            //Grab the current path to this page
            var path = window.location.pathname;
            //Create item json object and set p0ath
            var itemJson = {
                path: path
            };
            //If we have are adding the item from an item selection (rather than on page load), store the itemNumber
            if (saveItemNumber) {
                itemJson.itemNumber = fullItemNumber;
            }
            //Not sure if we'll need the page number any more - store it for now
            if (!saveItemNumber && pageNumber) {
                itemJson.pageNumber = pageNumber;
            }
            //If there's a size option, grab the value of the selected size if there is one
            var $sizeSelector = $itemWrapper.find("select.SizeSelector");
            if ($sizeSelector.length) {
                if ($sizeSelector.val()) {
                    itemJson.Size = $sizeSelector.val();
                }
            }
            _this.AddItem(itemJson);

        },
        AddItem: function (itemJson) {
            //<summary>Recursive check. Ensures adds are not made until get has returned successful. Therefore prevents an add appearing in the get results</summary>
            if (window.location.href.indexOf('shotonly') > -1) {
                return;
            }
            var _this = this;
            if (_this.Vars.HasGetSucceeded) {
                RecentlyViewed.addItem(itemJson);
            } else {
                setTimeout(function () {
                    _this.AddItem(itemJson);
                }, 100);
            }
        },
        SaveFromHashSelection: function () {
            var _this = this;
            if (!loadedItemFromHash) {
                setTimeout(function () {
                    _this.SaveFromHashSelection();
                }, 50);
            } else {
                _this.SaveViewedItem(true);
            }
        }
    },
    StoreStockSearch: {

        DisplayCistButtons: function () {
            $('a[data-cist-item="true"]').removeClass('nodisplay');
            $('span[data-cist-item="true"]').removeClass('nodisplay');
            $(".CollectInStoreLink").find('.cistText').removeClass('smallerCTA');
            $(".divFavouritesContainer").siblings(".favTexts").removeClass('smallerCTA');
            $('a[data-cist-item="true"]').parent().find(".favTexts").addClass('spacing');
        },

        CheckEligibility: function () {
            var isCistItem = $('a[data-cist-item="true"]').length || $('span[data-cist-item="true"]').length;

            //item is not CIST enabled or notify me is visible or CIST is hidden
            if (!isCistItem || Next.Settings.Mobile.CollectInStore.Config.CistFeatureHidden.toLowerCase() === "true") {
                return;
            }

            if (Next.Settings.Mobile.CollectInStore.Config.IsNewFeature.toLowerCase() === "true") {
                $(".CollectInStoreLink span").show();
            }
            Common.CollectInStoreAvailable($, Next.Settings.Mobile.CollectInStore.Config).done(function (result) {
                // If it's eligible, show all 'Cist Enabled' elements...
                _cistStoresOpen = result.Eligible;
                if (_cistStoresOpen) {
                    ProductPage.StoreStockSearch.DisplayCistButtons();
                }
            });
        },
        Get: function (url, successCallback, cacheFlag) {
            if (typeof (cacheFlag) !== typeof (true)) {
                cacheFlag = false;
            }
            $.ajax({
                url: url,
                cache: cacheFlag,
                success: function (data, textStatus, jqXhr) {
                    successCallback(data, textStatus, jqXhr);
                },
                error: function (data, textStatus, jqXhr) {
                    console.log(jqXhr);
                }
            });
        },
        GetProductData: function (link) {
            //<summary>Button to open Store Stock Search modal</summary>
            var $link = $(link);

            if ($link.hasClass("disabled")) {
                return false;
            }

            var $style = $link.parents("article.Style");
            var styleId = $style.data("styleid");
            var itemNumber = pdpChipsEnabled && ProductPage.Styles.pdpChipsShow() ? $style.data("targetitem") : $style.find(".StyleMeta .ItemNumber").text();
            //var styleItemNo = $style.find(".StyleMeta .ItemNumber");
            //if (pdpChipsEnabled && ProductPage.Styles.SplitSize.IsEnabled($style) && styleItemNo) {
            //    itemNumber = styleItemNo.text();
            //}
            var itemName = $style.data("itemname");
            var styleNumber = $style.data("stylenumber");
            var price = $style.find(".StyleCopy .Price span").text();
            var wasPrice = $style.find(".StyleCopy .Price div.wasPrice").text();
            var $fit = $style.find(".StyleForm select.fitList");
            var $colour = $style.find(".StyleForm select.colourList");
            var $sizeSelect = $style.find(".StyleForm select.SizeSelector#Size-" + itemNumber);
            var fitLabel = $fit.parent().parent().find("label.itemLabel").text();
            var colourLabel = $colour.parent().parent().find("label.itemLabel").text();
            var sizeLabel = $sizeSelect.parent().parent().find("label").text();
            var selectedFit = $fit.find("option:selected").val();
            var selectedColour = $colour.find("option:selected").text();
            var selectedSize = $sizeSelect.find("option:selected").val();
            var selectedSizeType = $sizeSelect.find("option:selected")[0].dataset.sizetype;
            var splitFitName = "";
            if (!selectedFit) {
                $fit = $style.find("ul.fitChips li.active");
                fitLabel = $fit.parent().parent().find("label.itemLabel").text();
                selectedFit = $fit.data("value");
                splitFitName = $fit.attr("data-fit");
            }
            if ($fit.hasClass("asmFitList")) {
                splitFitName = $fit.find("option:selected").data("fit");
            }

            if (!selectedColour) {
                $colour = $style.find("ul.colourChips li.active");
                colourLabel = $colour.parent().parent().find("label.itemLabel").text();
                selectedColour = $colour.data("value");
            }

            var style;
            $.each(ProductPage.Vars.ItemData, function () {
                if (this.StyleID == styleId) {
                    style = this;
                    return false;
                }
                return true;
            });

            return {
                SelectedItemNumber: itemNumber,
                SelectedStyleId: styleId,
                SelectedStyleNumber: styleNumber,
                SelectedItemName: itemName,
                SelectedPrice: price,
                SelectedWasPrice: wasPrice,
                SelectedFit: selectedFit,
                SelectedColour: selectedColour,
                SelectedSizeOptionNumber: selectedSize,
                SelectedSizeType: selectedSizeType,
                FitLabel: fitLabel,
                ColourLabel: colourLabel,
                SizeLabel: sizeLabel,
                StyleData: style,
                Page: "Productpage",
                SplitFitName: splitFitName
            };
        },
        FindInStore: function (link) {
            var product = this.GetProductData(link);

            if (product) {
                $.ajax({
                    url: "/SearchStoreStockTemplate/",
                    error: function () {
                        XHRCount--;
                    },
                    success: function (data, textStatus, jqXhr) {
                        checkAndRedirectForAjaxError(jqXhr, false, "modularpdp.js: ProductPage.StockSearch");
                        XHRCount--;

                        var $modal = ModalPopup.init({
                            width: 856,
                            height: 'auto',
                            fixedTopPosition: 85,
                            fullyLockBackgroundScroll: true, //overrides lockBackgroundScroll
                            modalDataSet: product,
                            onClose: function () {
                                TrackGAEvent("Find In Store", "Link Clicked", "Close Modal-ItemNumber:" + product.itemNumber);
                            }
                        });

                        TrackGAEvent("Find In Store", "Link Clicked", "Open Modal-ItemNumber:" + product.itemNumber);

                        $modal.html(data);
                        ModalPopup.show();

                        var ver = iOSversion();

                        //if iPad and ios version is less than 10, remove dk_mobile class to fix modal jumping issue
                        if (ver && ver[0] < 10) {
                            $('#dk_container_FitModal').removeClass("dk_mobile");
                            $('#dk_container_ColourModal').removeClass("dk_mobile");
                            $('#dk_container_SizeModal').removeClass("dk_mobile");
                        }
                    }
                });
            }

            function iOSversion() {
                if (/iPad/.test(navigator.platform)) {
                    var v = (navigator.appVersion).match(/OS (\d+)_(\d+)_?(\d+)?/);
                    return [parseInt(v[1], 10), parseInt(v[2], 10), parseInt(v[3] || 0, 10)];
                }
            }
        },
        CollectInStore: function (link) {
            var self = this;
            var $target = $(link);
            if ($target.attr("disabled") === "disabled") {
                return false;
            }
            $target.attr("disabled", "disabled").addClass("loading");
            var product = self.GetProductData(link);

            var sizeSelector = $("select#Size-" + product.SelectedItemNumber);
            if (!ProductPage.Styles.AddToBagCTA.ValidateControl(sizeSelector)) {
                if (pdpChipsEnabled && ProductPage.Styles.SplitSize.IsEnabled($target.parents("article.Style")) && ($target.parents("article.Style").find(".Chips.splitSizeContainer[for=Size-" + product.SelectedItemNumber + "]").find("li.splitSizeChip").length > 0)) {
                    ProductPage.Styles.SplitSize.SetValidationError(sizeSelector);
                }
                else if (ProductPage.Styles.SizeChipsEnabled(product.SelectedItemNumber)) {
                    ProductPage.Styles.DisplaySizeChipsValidationMessage(product.SelectedItemNumber);
                }
                $target.removeAttr("disabled").removeClass("loading");
                document.dispatchEvent(new CustomEvent("CistTrackingEvents", { detail: { id: "cte_40" } }));
                return false;
            }

            var overrideSoldOutSizeTypes = nxt.jstranslations.productpage.overridesoldoutsizetypes
                ? nxt.jstranslations.productpage.overridesoldoutsizetypes.toLowerCase().split(",")
                : ["tall"];
            var sizeTypeMatchOverride = product.SelectedSizeType
                ? overrideSoldOutSizeTypes.indexOf(product.SelectedSizeType.toLowerCase()) > -1
                : false;
            if (sizeTypeMatchOverride) {
                $target.removeAttr("disabled").removeClass("loading");
                document.dispatchEvent(new CustomEvent("CistTrackingEvents", { detail: { id: "cte_51" } }));
                var errorMessage = nxt.jstranslations.productpage.cistInvalidSoldOutSizeTypeText.replace("{0}", product.SelectedSizeType);
                $target.attr("data-description", errorMessage);

                var settings =
                {
                    customCSS: "height: 50px",
                    customClassName: "CollectInStoreToday",
                    errorMessage: false,
                    align: "top",
                    color: "#222222",
                    width: (Next.Settings.UI.ReskinPDP || Next.Settings.UI.IsInnovationDesktopResponsiveEnabled) ? 250 : 250,
                    marginTop: 44,
                    marginLeft: -50,
                    closeOnDialogueOut: true,
                    autoClose: true
                };
                showDialoguePopUp($target, settings);
                return false;
            }

            function startCollectInStore(data, textStatus, jqXhr) {
                checkAndRedirectForAjaxError(jqXhr, false, "modularpdp.js: ProductPage.StockSearch");
                XHRCount--;
                var $modal = ModalPopup.init({
                    width: 856,
                    height: 'auto',
                    fixedTopPosition: 85,
                    fullyLockBackgroundScroll: true, //overrides lockBackgroundScroll
                    modalDataSet: product,
                    onClose: function () {
                        TrackGAEvent("Collect In Store",
                            "Link Clicked",
                            "Close Modal-ItemNumber:" + product.itemNumber);
                    }
                });

                $modal.html(data);
                var StyleForm = $target.closest(".StyleForm");
                var $addToBagCTA = $(StyleForm).find(".addToBagCTA");
                var $cist_out_of_hours_add_to_bag = $modal.find(".cist-out-of-hours-add-to-bag");
                var isStock = !($("select#Size-" + product.SelectedItemNumber).find(":selected").hasClass("SoldOut")
                    || $("select#Size-" + product.SelectedItemNumber).find(":selected").hasClass("SaleSoldOut"));
                if ($cist_out_of_hours_add_to_bag.length > 0) {
                    if ($addToBagCTA.is(":visible") && isStock) {
                        $cist_out_of_hours_add_to_bag.on("click", function (e) { e.preventDefault(); ModalPopup.close(); $addToBagCTA.trigger("click"); });
                    }
                    else {
                        $cist_out_of_hours_add_to_bag.remove();
                    }
                }


                CollectInStore.Modal.initialiseModal(Next.Settings.Mobile.CollectInStore.Config);
                var location = document.getElementById("location");
                var collectInStore;

                if (location) {
                    if (pdpChipsEnabled && ProductPage.Styles.SplitSize.SplitFitEnabled()) {
                        var fitIndex = (product.SplitFitName) ? product.StyleData.Fits.map(function (e) { return e.Name; }).indexOf(product.SplitFitName) : 0;
                        var itemIndex = product.StyleData.Fits[fitIndex].Items.map(function (e) { return e.ItemNumber; }).indexOf(product.SelectedItemNumber);
                        var optionIndex = product.StyleData.Fits[fitIndex].Items[itemIndex].Options.map(function (e) { return e.Number; }).indexOf(product.SelectedSizeOptionNumber);
                    }
                    else {
                        var fitIndex = (product.SelectedFit) ? product.StyleData.Fits.map(function (e) { return e.Name; }).indexOf(product.SelectedFit) : 0;
                        var itemIndex = product.StyleData.Fits[fitIndex].Items.map(function (e) { return e.ItemNumber; }).indexOf(product.SelectedItemNumber);
                        var optionIndex = product.StyleData.Fits[fitIndex].Items[itemIndex].Options.map(function (e) { return e.Number; }).indexOf(product.SelectedSizeOptionNumber);
                    }
                    collectInStore = new CollectInStore.Search(Next.Settings.Mobile.CollectInStore.Config,
                        {
                            id: product.SelectedItemNumber.replace("-", ""),
                            itemName: product.SelectedItemName,
                            fit: product.SelectedFit,
                            colour: product.SelectedColour,
                            optionNumber: product.SelectedSizeOptionNumber,
                            optionName: product.StyleData.Fits[fitIndex].Items[itemIndex].Options[optionIndex].Name,
                            styleId: product.SelectedStyleId,
                            collectEligible: product.StyleData.Fits[fitIndex].Items[itemIndex].CollectInStoreTodayEnabled,
                            chain: ""
                        });
                    CollectInStore.Modal.attachEventHandlers(collectInStore);

                    CollectInStore.Modal.setInStockToggle($("#inStockToggle"), collectInStore.showAvailableStoresOnly);

                    setTimeout(function () {
                        location.focus();
                    }, 50);
                }

                if (collectInStore) {
                    CollectInStore.Modal.raiseGoogleAnalyticsEvent(collectInStore.isMobile, "CIST_PDP", null, "collect_today");
                }

                ModalPopup.show();
                setTimeout(function () { $target.removeAttr("disabled").removeClass("loading"); }, 50);
            }

            Common.CollectInStoreAvailable($, Next.Settings.Mobile.CollectInStore.Config).done(
                function (result) {
                    if (result.Eligible) {
                        self.Get("/CollectInStoreTemplate/", startCollectInStore, true);
                    } else if (!result.Eligible && result.OutsideOpeningTimes) {
                        self.Get("/CollectInStoreOutOfHours", startCollectInStore, true);
                        document.dispatchEvent(new CustomEvent("CistTrackingEvents", { detail: { id: "cte_42" } }));
                        _cistStoresOpen = false;
                    } else {
                        setTimeout(function () { $target.removeAttr("disabled").removeClass("loading"); }, 50);
                        _cistStoresOpen = false;
                    }
                });
        }
    },
    RemoveDashFromItemNumber: function (itemNumber) {
        var updatedItemNumber = itemNumber.replace(/-/g, "").substring(0, 6);
        return updatedItemNumber;
    },
    HideYMALContainers: function () {
        $('.next-intelrecs').hide();
        $('#3rdParty-intelrecs').hide();
        this.Vars.$backToTop.hide();
        this.Vars.$reviewsContainer.hide();
    },
    TogglePDPDisplayForSoldoutItem: function (display) {
        var $addToBagCTA = $(".BagHolder .addToBagCTA");
        var $countdownTimerElement = $(".cdt-promise-wrapper #countdownTimer");
        var $favIcon = $(".divFavouritesContainer");
        if (display) {
            $addToBagCTA.removeClass("SoldoutAddToBagCTA");
            $addToBagCTA.removeClass("disabled");
            $favIcon.removeClass("SoldoutFavIcon");
            if ($countdownTimerElement.css("display") == "block") {
                $countdownTimerElement.parent().removeClass("HiddenCDT");
            }
        } else {
            $addToBagCTA.addClass("SoldoutAddToBagCTA");
            $addToBagCTA.addClass("disabled");
            $favIcon.addClass("SoldoutFavIcon");
            if ($countdownTimerElement.css("display") == "block") {
                $countdownTimerElement.parent().addClass("HiddenCDT");
            }
        }
    },
    LoadShotJson: function (_tryLimit, _showError, _styleNumber, _previousItemNumber) {

        if (!Next.Settings.Channel.EnableProductAggregator && Next.Settings.Channel.EnableOptimisedJson) {
            jsonInitalTry = false;
            var getShotJsonUrl = "/getshotjson";
            if (Next.Settings.Channel.CountryCode != "GB" || (Next.Settings.Channel.ChannelTheme && (Next.Settings.Channel.ChannelTheme.toLowerCase() === "preview" || (Next.Settings.Channel.IsTotalPlatformLiteClient && Next.Settings.Channel.MainSiteAbsolutePath !== "/")))) {
                getShotJsonUrl = getShotJsonUrl + window.location.pathname.replace(Next.Settings.Channel.MainSiteAbsolutePath, "");
                getShotJsonUrl = Next.Settings.Channel.MainSiteAbsolutePath + getShotJsonUrl;
            }
            else {
                getShotJsonUrl = getShotJsonUrl + window.location.pathname;
            }
            $.ajax({
                type: 'GET',
                url: getShotJsonUrl,
                timeout: Next.Settings.UI.OptimisedShotJsonTimeoutInMilliseconds,
                tryCount: 0,
                tryLimit: _tryLimit,
                cache: true,
                async: true,
                success: function (response) {
                    var data = JSON.parse(response);
                    shotData.Styles = data.Styles
                    ProductPage.Vars.ItemData = data.Styles;
                    jsonLoaded = true;
                    $('.jsonerror').hide();
                },
                error: function (XMLHttpRequest, textStatus, errorThrown) {
                    if (textStatus === 'timeout') {
                        this.tryCount++;
                        if (this.tryCount < this.tryLimit) {
                            $.ajax(this);
                        } else {
                            if (_showError) {

                                $('.jsonerror[data-stylenumber=\"' + _styleNumber + '\"]').find('.content').text(nxt.jstranslations.productpage.jsonerror);
                                $('.jsonerror[data-stylenumber=\"' + _styleNumber + '\"]').show();

                                $('article[data-stylenumber=\"' + _styleNumber + '\"]').find('select').val(_previousItemNumber);

                            };
                        }
                    }
                }
            });
        }
    },
    GetShotForSingleItem: function (_async, _ajaxTryCount, itemNumber) {

        var result = false;

        var newPathName = window.location.pathname.substring(0, window.location.pathname.lastIndexOf('/') + 1);
        var updateitemnumber = ProductPage.RemoveDashFromItemNumber(itemNumber);
        newPathName = newPathName + updateitemnumber;

        var getSingleItemShotjJson = "/getshotjson" + newPathName;

        if (Next.Settings.Channel.CountryCode != "GB" || (Next.Settings.Channel.ChannelTheme && (Next.Settings.Channel.ChannelTheme.toLowerCase() === "preview" || (Next.Settings.Channel.IsTotalPlatformLiteClient && Next.Settings.Channel.MainSiteAbsolutePath !== "/")))) {
            getSingleItemShotjJson = Next.Settings.Channel.MainSiteAbsolutePath + getSingleItemShotjJson.replace(Next.Settings.Channel.MainSiteAbsolutePath, "");
        }

        $.ajax({
            type: 'GET',
            url: getSingleItemShotjJson,
            cache: true,
            timeout: Next.Settings.UI.ProductAggregatorTimeoutInMilliseconds,
            async: _async,
            tryCount: 0,
            tryLimit: _ajaxTryCount,
            success: function (response) {
                var data = JSON.parse(response);
                shotData.Styles = data.Styles;
                ProductPage.Vars.ItemData = data.Styles;
                EarlyStock.vars.itemData = data.Styles;
                jsonLoaded = true;
                $('.jsonerror').hide()
                result = true;
            },
            error: function (XMLHttpRequest, textStatus, errorThrown) {
                if (textStatus === 'timeout') {
                    this.tryCount++;
                    if (this.tryCount < this.tryLimit) {
                        $.ajax(this);
                    } 
                    console.log("req: " + XMLHttpRequest);
                    console.log("textStatus: " + textStatus);
                    console.log("error: " + errorThrown);
                    result = false;
                }
            }
        });

        return result;
    },
    GenerateV4UUID: function () {
        let d = new Date().getTime();
        return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function (c) {
            const r = (d + Math.random() * 16) % 16 | 0;
            d = Math.floor(d / 16);
            return (c === 'x' ? r : (r & 0x3 | 0x8)).toString(16);
        });
    }
};

//PLI (Publication Level Imagery)
var PLI = {
    HidePublicationImages: function (shotType) {
        ProductPage.Vars.$zoomComponent.ZoomComponent('hidePublicationImagesAndUpdateLiItems', shotType);
    },
    hidePublicationImagesAndUpdateLiItemsForAttribute: function (attributeName, attributeValue) {
        ProductPage.Vars.$zoomComponent.ZoomComponent('hidePublicationImagesAndUpdateLiItemsForAttribute', attributeName, attributeValue);
    },
    IsDefaultItem: function (currentItemNumber) {
        return ProductPage.Vars.$zoomComponent.ZoomComponent('IsDefaultItem', currentItemNumber);
    }
};

/*!

 handlebars v3.0.3

Copyright (C) 2011-2014 by Yehuda Katz

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.

@license
*/
(function webpackUniversalModuleDefinition(root, factory) {
	if(typeof exports === 'object' && typeof module === 'object')
		module.exports = factory();
	else if(typeof define === 'function' && define.amd)
		define(factory);
	else if(typeof exports === 'object')
		exports["Handlebars"] = factory();
	else
		root["Handlebars"] = factory();
})(this, function() {
return /******/ (function(modules) { // webpackBootstrap
/******/ 	// The module cache
/******/ 	var installedModules = {};

/******/ 	// The require function
/******/ 	function __webpack_require__(moduleId) {

/******/ 		// Check if module is in cache
/******/ 		if(installedModules[moduleId])
/******/ 			return installedModules[moduleId].exports;

/******/ 		// Create a new module (and put it into the cache)
/******/ 		var module = installedModules[moduleId] = {
/******/ 			exports: {},
/******/ 			id: moduleId,
/******/ 			loaded: false
/******/ 		};

/******/ 		// Execute the module function
/******/ 		modules[moduleId].call(module.exports, module, module.exports, __webpack_require__);

/******/ 		// Flag the module as loaded
/******/ 		module.loaded = true;

/******/ 		// Return the exports of the module
/******/ 		return module.exports;
/******/ 	}


/******/ 	// expose the modules object (__webpack_modules__)
/******/ 	__webpack_require__.m = modules;

/******/ 	// expose the module cache
/******/ 	__webpack_require__.c = installedModules;

/******/ 	// __webpack_public_path__
/******/ 	__webpack_require__.p = "";

/******/ 	// Load entry module and return exports
/******/ 	return __webpack_require__(0);
/******/ })
/************************************************************************/
/******/ ([
/* 0 */
/***/ function(module, exports, __webpack_require__) {

	'use strict';

	var _interopRequireDefault = __webpack_require__(8)['default'];

	exports.__esModule = true;

	var _runtime = __webpack_require__(1);

	var _runtime2 = _interopRequireDefault(_runtime);

	// Compiler imports

	var _AST = __webpack_require__(2);

	var _AST2 = _interopRequireDefault(_AST);

	var _Parser$parse = __webpack_require__(3);

	var _Compiler$compile$precompile = __webpack_require__(4);

	var _JavaScriptCompiler = __webpack_require__(5);

	var _JavaScriptCompiler2 = _interopRequireDefault(_JavaScriptCompiler);

	var _Visitor = __webpack_require__(6);

	var _Visitor2 = _interopRequireDefault(_Visitor);

	var _noConflict = __webpack_require__(7);

	var _noConflict2 = _interopRequireDefault(_noConflict);

	var _create = _runtime2['default'].create;
	function create() {
	  var hb = _create();

	  hb.compile = function (input, options) {
	    return _Compiler$compile$precompile.compile(input, options, hb);
	  };
	  hb.precompile = function (input, options) {
	    return _Compiler$compile$precompile.precompile(input, options, hb);
	  };

	  hb.AST = _AST2['default'];
	  hb.Compiler = _Compiler$compile$precompile.Compiler;
	  hb.JavaScriptCompiler = _JavaScriptCompiler2['default'];
	  hb.Parser = _Parser$parse.parser;
	  hb.parse = _Parser$parse.parse;

	  return hb;
	}

	var inst = create();
	inst.create = create;

	_noConflict2['default'](inst);

	inst.Visitor = _Visitor2['default'];

	inst['default'] = inst;

	exports['default'] = inst;
	module.exports = exports['default'];

/***/ },
/* 1 */
/***/ function(module, exports, __webpack_require__) {

	'use strict';

	var _interopRequireWildcard = __webpack_require__(9)['default'];

	var _interopRequireDefault = __webpack_require__(8)['default'];

	exports.__esModule = true;

	var _import = __webpack_require__(10);

	var base = _interopRequireWildcard(_import);

	// Each of these augment the Handlebars object. No need to setup here.
	// (This is done to easily share code between commonjs and browse envs)

	var _SafeString = __webpack_require__(11);

	var _SafeString2 = _interopRequireDefault(_SafeString);

	var _Exception = __webpack_require__(12);

	var _Exception2 = _interopRequireDefault(_Exception);

	var _import2 = __webpack_require__(13);

	var Utils = _interopRequireWildcard(_import2);

	var _import3 = __webpack_require__(14);

	var runtime = _interopRequireWildcard(_import3);

	var _noConflict = __webpack_require__(7);

	var _noConflict2 = _interopRequireDefault(_noConflict);

	// For compatibility and usage outside of module systems, make the Handlebars object a namespace
	function create() {
	  var hb = new base.HandlebarsEnvironment();

	  Utils.extend(hb, base);
	  hb.SafeString = _SafeString2['default'];
	  hb.Exception = _Exception2['default'];
	  hb.Utils = Utils;
	  hb.escapeExpression = Utils.escapeExpression;

	  hb.VM = runtime;
	  hb.template = function (spec) {
	    return runtime.template(spec, hb);
	  };

	  return hb;
	}

	var inst = create();
	inst.create = create;

	_noConflict2['default'](inst);

	inst['default'] = inst;

	exports['default'] = inst;
	module.exports = exports['default'];

/***/ },
/* 2 */
/***/ function(module, exports, __webpack_require__) {

	'use strict';

	exports.__esModule = true;
	var AST = {
	  Program: function Program(statements, blockParams, strip, locInfo) {
	    this.loc = locInfo;
	    this.type = 'Program';
	    this.body = statements;

	    this.blockParams = blockParams;
	    this.strip = strip;
	  },

	  MustacheStatement: function MustacheStatement(path, params, hash, escaped, strip, locInfo) {
	    this.loc = locInfo;
	    this.type = 'MustacheStatement';

	    this.path = path;
	    this.params = params || [];
	    this.hash = hash;
	    this.escaped = escaped;

	    this.strip = strip;
	  },

	  BlockStatement: function BlockStatement(path, params, hash, program, inverse, openStrip, inverseStrip, closeStrip, locInfo) {
	    this.loc = locInfo;
	    this.type = 'BlockStatement';

	    this.path = path;
	    this.params = params || [];
	    this.hash = hash;
	    this.program = program;
	    this.inverse = inverse;

	    this.openStrip = openStrip;
	    this.inverseStrip = inverseStrip;
	    this.closeStrip = closeStrip;
	  },

	  PartialStatement: function PartialStatement(name, params, hash, strip, locInfo) {
	    this.loc = locInfo;
	    this.type = 'PartialStatement';

	    this.name = name;
	    this.params = params || [];
	    this.hash = hash;

	    this.indent = '';
	    this.strip = strip;
	  },

	  ContentStatement: function ContentStatement(string, locInfo) {
	    this.loc = locInfo;
	    this.type = 'ContentStatement';
	    this.original = this.value = string;
	  },

	  CommentStatement: function CommentStatement(comment, strip, locInfo) {
	    this.loc = locInfo;
	    this.type = 'CommentStatement';
	    this.value = comment;

	    this.strip = strip;
	  },

	  SubExpression: function SubExpression(path, params, hash, locInfo) {
	    this.loc = locInfo;

	    this.type = 'SubExpression';
	    this.path = path;
	    this.params = params || [];
	    this.hash = hash;
	  },

	  PathExpression: function PathExpression(data, depth, parts, original, locInfo) {
	    this.loc = locInfo;
	    this.type = 'PathExpression';

	    this.data = data;
	    this.original = original;
	    this.parts = parts;
	    this.depth = depth;
	  },

	  StringLiteral: function StringLiteral(string, locInfo) {
	    this.loc = locInfo;
	    this.type = 'StringLiteral';
	    this.original = this.value = string;
	  },

	  NumberLiteral: function NumberLiteral(number, locInfo) {
	    this.loc = locInfo;
	    this.type = 'NumberLiteral';
	    this.original = this.value = Number(number);
	  },

	  BooleanLiteral: function BooleanLiteral(bool, locInfo) {
	    this.loc = locInfo;
	    this.type = 'BooleanLiteral';
	    this.original = this.value = bool === 'true';
	  },

	  UndefinedLiteral: function UndefinedLiteral(locInfo) {
	    this.loc = locInfo;
	    this.type = 'UndefinedLiteral';
	    this.original = this.value = undefined;
	  },

	  NullLiteral: function NullLiteral(locInfo) {
	    this.loc = locInfo;
	    this.type = 'NullLiteral';
	    this.original = this.value = null;
	  },

	  Hash: function Hash(pairs, locInfo) {
	    this.loc = locInfo;
	    this.type = 'Hash';
	    this.pairs = pairs;
	  },
	  HashPair: function HashPair(key, value, locInfo) {
	    this.loc = locInfo;
	    this.type = 'HashPair';
	    this.key = key;
	    this.value = value;
	  },

	  // Public API used to evaluate derived attributes regarding AST nodes
	  helpers: {
	    // a mustache is definitely a helper if:
	    // * it is an eligible helper, and
	    // * it has at least one parameter or hash segment
	    helperExpression: function helperExpression(node) {
	      return !!(node.type === 'SubExpression' || node.params.length || node.hash);
	    },

	    scopedId: function scopedId(path) {
	      return /^\.|this\b/.test(path.original);
	    },

	    // an ID is simple if it only has one part, and that part is not
	    // `..` or `this`.
	    simpleId: function simpleId(path) {
	      return path.parts.length === 1 && !AST.helpers.scopedId(path) && !path.depth;
	    }
	  }
	};

	// Must be exported as an object rather than the root of the module as the jison lexer
	// must modify the object to operate properly.
	exports['default'] = AST;
	module.exports = exports['default'];

/***/ },
/* 3 */
/***/ function(module, exports, __webpack_require__) {

	'use strict';

	var _interopRequireDefault = __webpack_require__(8)['default'];

	var _interopRequireWildcard = __webpack_require__(9)['default'];

	exports.__esModule = true;
	exports.parse = parse;

	var _parser = __webpack_require__(15);

	var _parser2 = _interopRequireDefault(_parser);

	var _AST = __webpack_require__(2);

	var _AST2 = _interopRequireDefault(_AST);

	var _WhitespaceControl = __webpack_require__(16);

	var _WhitespaceControl2 = _interopRequireDefault(_WhitespaceControl);

	var _import = __webpack_require__(17);

	var Helpers = _interopRequireWildcard(_import);

	var _extend = __webpack_require__(13);

	exports.parser = _parser2['default'];

	var yy = {};
	_extend.extend(yy, Helpers, _AST2['default']);

	function parse(input, options) {
	  // Just return if an already-compiled AST was passed in.
	  if (input.type === 'Program') {
	    return input;
	  }

	  _parser2['default'].yy = yy;

	  // Altering the shared object here, but this is ok as parser is a sync operation
	  yy.locInfo = function (locInfo) {
	    return new yy.SourceLocation(options && options.srcName, locInfo);
	  };

	  var strip = new _WhitespaceControl2['default']();
	  return strip.accept(_parser2['default'].parse(input));
	}

/***/ },
/* 4 */
/***/ function(module, exports, __webpack_require__) {

	'use strict';

	var _interopRequireDefault = __webpack_require__(8)['default'];

	exports.__esModule = true;
	exports.Compiler = Compiler;
	exports.precompile = precompile;
	exports.compile = compile;

	var _Exception = __webpack_require__(12);

	var _Exception2 = _interopRequireDefault(_Exception);

	var _isArray$indexOf = __webpack_require__(13);

	var _AST = __webpack_require__(2);

	var _AST2 = _interopRequireDefault(_AST);

	var slice = [].slice;

	function Compiler() {}

	// the foundHelper register will disambiguate helper lookup from finding a
	// function in a context. This is necessary for mustache compatibility, which
	// requires that context functions in blocks are evaluated by blockHelperMissing,
	// and then proceed as if the resulting value was provided to blockHelperMissing.

	Compiler.prototype = {
	  compiler: Compiler,

	  equals: function equals(other) {
	    var len = this.opcodes.length;
	    if (other.opcodes.length !== len) {
	      return false;
	    }

	    for (var i = 0; i < len; i++) {
	      var opcode = this.opcodes[i],
	          otherOpcode = other.opcodes[i];
	      if (opcode.opcode !== otherOpcode.opcode || !argEquals(opcode.args, otherOpcode.args)) {
	        return false;
	      }
	    }

	    // We know that length is the same between the two arrays because they are directly tied
	    // to the opcode behavior above.
	    len = this.children.length;
	    for (var i = 0; i < len; i++) {
	      if (!this.children[i].equals(other.children[i])) {
	        return false;
	      }
	    }

	    return true;
	  },

	  guid: 0,

	  compile: function compile(program, options) {
	    this.sourceNode = [];
	    this.opcodes = [];
	    this.children = [];
	    this.options = options;
	    this.stringParams = options.stringParams;
	    this.trackIds = options.trackIds;

	    options.blockParams = options.blockParams || [];

	    // These changes will propagate to the other compiler components
	    var knownHelpers = options.knownHelpers;
	    options.knownHelpers = {
	      helperMissing: true,
	      blockHelperMissing: true,
	      each: true,
	      'if': true,
	      unless: true,
	      'with': true,
	      log: true,
	      lookup: true
	    };
	    if (knownHelpers) {
	      for (var _name in knownHelpers) {
	        if (_name in knownHelpers) {
	          options.knownHelpers[_name] = knownHelpers[_name];
	        }
	      }
	    }

	    return this.accept(program);
	  },

	  compileProgram: function compileProgram(program) {
	    var childCompiler = new this.compiler(),
	        // eslint-disable-line new-cap
	    result = childCompiler.compile(program, this.options),
	        guid = this.guid++;

	    this.usePartial = this.usePartial || result.usePartial;

	    this.children[guid] = result;
	    this.useDepths = this.useDepths || result.useDepths;

	    return guid;
	  },

	  accept: function accept(node) {
	    this.sourceNode.unshift(node);
	    var ret = this[node.type](node);
	    this.sourceNode.shift();
	    return ret;
	  },

	  Program: function Program(program) {
	    this.options.blockParams.unshift(program.blockParams);

	    var body = program.body,
	        bodyLength = body.length;
	    for (var i = 0; i < bodyLength; i++) {
	      this.accept(body[i]);
	    }

	    this.options.blockParams.shift();

	    this.isSimple = bodyLength === 1;
	    this.blockParams = program.blockParams ? program.blockParams.length : 0;

	    return this;
	  },

	  BlockStatement: function BlockStatement(block) {
	    transformLiteralToPath(block);

	    var program = block.program,
	        inverse = block.inverse;

	    program = program && this.compileProgram(program);
	    inverse = inverse && this.compileProgram(inverse);

	    var type = this.classifySexpr(block);

	    if (type === 'helper') {
	      this.helperSexpr(block, program, inverse);
	    } else if (type === 'simple') {
	      this.simpleSexpr(block);

	      // now that the simple mustache is resolved, we need to
	      // evaluate it by executing `blockHelperMissing`
	      this.opcode('pushProgram', program);
	      this.opcode('pushProgram', inverse);
	      this.opcode('emptyHash');
	      this.opcode('blockValue', block.path.original);
	    } else {
	      this.ambiguousSexpr(block, program, inverse);

	      // now that the simple mustache is resolved, we need to
	      // evaluate it by executing `blockHelperMissing`
	      this.opcode('pushProgram', program);
	      this.opcode('pushProgram', inverse);
	      this.opcode('emptyHash');
	      this.opcode('ambiguousBlockValue');
	    }

	    this.opcode('append');
	  },

	  PartialStatement: function PartialStatement(partial) {
	    this.usePartial = true;

	    var params = partial.params;
	    if (params.length > 1) {
	      throw new _Exception2['default']('Unsupported number of partial arguments: ' + params.length, partial);
	    } else if (!params.length) {
	      params.push({ type: 'PathExpression', parts: [], depth: 0 });
	    }

	    var partialName = partial.name.original,
	        isDynamic = partial.name.type === 'SubExpression';
	    if (isDynamic) {
	      this.accept(partial.name);
	    }

	    this.setupFullMustacheParams(partial, undefined, undefined, true);

	    var indent = partial.indent || '';
	    if (this.options.preventIndent && indent) {
	      this.opcode('appendContent', indent);
	      indent = '';
	    }

	    this.opcode('invokePartial', isDynamic, partialName, indent);
	    this.opcode('append');
	  },

	  MustacheStatement: function MustacheStatement(mustache) {
	    this.SubExpression(mustache); // eslint-disable-line new-cap

	    if (mustache.escaped && !this.options.noEscape) {
	      this.opcode('appendEscaped');
	    } else {
	      this.opcode('append');
	    }
	  },

	  ContentStatement: function ContentStatement(content) {
	    if (content.value) {
	      this.opcode('appendContent', content.value);
	    }
	  },

	  CommentStatement: function CommentStatement() {},

	  SubExpression: function SubExpression(sexpr) {
	    transformLiteralToPath(sexpr);
	    var type = this.classifySexpr(sexpr);

	    if (type === 'simple') {
	      this.simpleSexpr(sexpr);
	    } else if (type === 'helper') {
	      this.helperSexpr(sexpr);
	    } else {
	      this.ambiguousSexpr(sexpr);
	    }
	  },
	  ambiguousSexpr: function ambiguousSexpr(sexpr, program, inverse) {
	    var path = sexpr.path,
	        name = path.parts[0],
	        isBlock = program != null || inverse != null;

	    this.opcode('getContext', path.depth);

	    this.opcode('pushProgram', program);
	    this.opcode('pushProgram', inverse);

	    this.accept(path);

	    this.opcode('invokeAmbiguous', name, isBlock);
	  },

	  simpleSexpr: function simpleSexpr(sexpr) {
	    this.accept(sexpr.path);
	    this.opcode('resolvePossibleLambda');
	  },

	  helperSexpr: function helperSexpr(sexpr, program, inverse) {
	    var params = this.setupFullMustacheParams(sexpr, program, inverse),
	        path = sexpr.path,
	        name = path.parts[0];

	    if (this.options.knownHelpers[name]) {
	      this.opcode('invokeKnownHelper', params.length, name);
	    } else if (this.options.knownHelpersOnly) {
	      throw new _Exception2['default']('You specified knownHelpersOnly, but used the unknown helper ' + name, sexpr);
	    } else {
	      path.falsy = true;

	      this.accept(path);
	      this.opcode('invokeHelper', params.length, path.original, _AST2['default'].helpers.simpleId(path));
	    }
	  },

	  PathExpression: function PathExpression(path) {
	    this.addDepth(path.depth);
	    this.opcode('getContext', path.depth);

	    var name = path.parts[0],
	        scoped = _AST2['default'].helpers.scopedId(path),
	        blockParamId = !path.depth && !scoped && this.blockParamIndex(name);

	    if (blockParamId) {
	      this.opcode('lookupBlockParam', blockParamId, path.parts);
	    } else if (!name) {
	      // Context reference, i.e. `{{foo .}}` or `{{foo ..}}`
	      this.opcode('pushContext');
	    } else if (path.data) {
	      this.options.data = true;
	      this.opcode('lookupData', path.depth, path.parts);
	    } else {
	      this.opcode('lookupOnContext', path.parts, path.falsy, scoped);
	    }
	  },

	  StringLiteral: function StringLiteral(string) {
	    this.opcode('pushString', string.value);
	  },

	  NumberLiteral: function NumberLiteral(number) {
	    this.opcode('pushLiteral', number.value);
	  },

	  BooleanLiteral: function BooleanLiteral(bool) {
	    this.opcode('pushLiteral', bool.value);
	  },

	  UndefinedLiteral: function UndefinedLiteral() {
	    this.opcode('pushLiteral', 'undefined');
	  },

	  NullLiteral: function NullLiteral() {
	    this.opcode('pushLiteral', 'null');
	  },

	  Hash: function Hash(hash) {
	    var pairs = hash.pairs,
	        i = 0,
	        l = pairs.length;

	    this.opcode('pushHash');

	    for (; i < l; i++) {
	      this.pushParam(pairs[i].value);
	    }
	    while (i--) {
	      this.opcode('assignToHash', pairs[i].key);
	    }
	    this.opcode('popHash');
	  },

	  // HELPERS
	  opcode: function opcode(name) {
	    this.opcodes.push({ opcode: name, args: slice.call(arguments, 1), loc: this.sourceNode[0].loc });
	  },

	  addDepth: function addDepth(depth) {
	    if (!depth) {
	      return;
	    }

	    this.useDepths = true;
	  },

	  classifySexpr: function classifySexpr(sexpr) {
	    var isSimple = _AST2['default'].helpers.simpleId(sexpr.path);

	    var isBlockParam = isSimple && !!this.blockParamIndex(sexpr.path.parts[0]);

	    // a mustache is an eligible helper if:
	    // * its id is simple (a single part, not `this` or `..`)
	    var isHelper = !isBlockParam && _AST2['default'].helpers.helperExpression(sexpr);

	    // if a mustache is an eligible helper but not a definite
	    // helper, it is ambiguous, and will be resolved in a later
	    // pass or at runtime.
	    var isEligible = !isBlockParam && (isHelper || isSimple);

	    // if ambiguous, we can possibly resolve the ambiguity now
	    // An eligible helper is one that does not have a complex path, i.e. `this.foo`, `../foo` etc.
	    if (isEligible && !isHelper) {
	      var _name2 = sexpr.path.parts[0],
	          options = this.options;

	      if (options.knownHelpers[_name2]) {
	        isHelper = true;
	      } else if (options.knownHelpersOnly) {
	        isEligible = false;
	      }
	    }

	    if (isHelper) {
	      return 'helper';
	    } else if (isEligible) {
	      return 'ambiguous';
	    } else {
	      return 'simple';
	    }
	  },

	  pushParams: function pushParams(params) {
	    for (var i = 0, l = params.length; i < l; i++) {
	      this.pushParam(params[i]);
	    }
	  },

	  pushParam: function pushParam(val) {
	    var value = val.value != null ? val.value : val.original || '';

	    if (this.stringParams) {
	      if (value.replace) {
	        value = value.replace(/^(\.?\.\/)*/g, '').replace(/\//g, '.');
	      }

	      if (val.depth) {
	        this.addDepth(val.depth);
	      }
	      this.opcode('getContext', val.depth || 0);
	      this.opcode('pushStringParam', value, val.type);

	      if (val.type === 'SubExpression') {
	        // SubExpressions get evaluated and passed in
	        // in string params mode.
	        this.accept(val);
	      }
	    } else {
	      if (this.trackIds) {
	        var blockParamIndex = undefined;
	        if (val.parts && !_AST2['default'].helpers.scopedId(val) && !val.depth) {
	          blockParamIndex = this.blockParamIndex(val.parts[0]);
	        }
	        if (blockParamIndex) {
	          var blockParamChild = val.parts.slice(1).join('.');
	          this.opcode('pushId', 'BlockParam', blockParamIndex, blockParamChild);
	        } else {
	          value = val.original || value;
	          if (value.replace) {
	            value = value.replace(/^\.\//g, '').replace(/^\.$/g, '');
	          }

	          this.opcode('pushId', val.type, value);
	        }
	      }
	      this.accept(val);
	    }
	  },

	  setupFullMustacheParams: function setupFullMustacheParams(sexpr, program, inverse, omitEmpty) {
	    var params = sexpr.params;
	    this.pushParams(params);

	    this.opcode('pushProgram', program);
	    this.opcode('pushProgram', inverse);

	    if (sexpr.hash) {
	      this.accept(sexpr.hash);
	    } else {
	      this.opcode('emptyHash', omitEmpty);
	    }

	    return params;
	  },

	  blockParamIndex: function blockParamIndex(name) {
	    for (var depth = 0, len = this.options.blockParams.length; depth < len; depth++) {
	      var blockParams = this.options.blockParams[depth],
	          param = blockParams && _isArray$indexOf.indexOf(blockParams, name);
	      if (blockParams && param >= 0) {
	        return [depth, param];
	      }
	    }
	  }
	};

	function precompile(input, options, env) {
	  if (input == null || typeof input !== 'string' && input.type !== 'Program') {
	    throw new _Exception2['default']('You must pass a string or Handlebars AST to Handlebars.precompile. You passed ' + input);
	  }

	  options = options || {};
	  if (!('data' in options)) {
	    options.data = true;
	  }
	  if (options.compat) {
	    options.useDepths = true;
	  }

	  var ast = env.parse(input, options),
	      environment = new env.Compiler().compile(ast, options);
	  return new env.JavaScriptCompiler().compile(environment, options);
	}

	function compile(input, _x, env) {
	  var options = arguments[1] === undefined ? {} : arguments[1];

	  if (input == null || typeof input !== 'string' && input.type !== 'Program') {
	    throw new _Exception2['default']('You must pass a string or Handlebars AST to Handlebars.compile. You passed ' + input);
	  }

	  if (!('data' in options)) {
	    options.data = true;
	  }
	  if (options.compat) {
	    options.useDepths = true;
	  }

	  var compiled = undefined;

	  function compileInput() {
	    var ast = env.parse(input, options),
	        environment = new env.Compiler().compile(ast, options),
	        templateSpec = new env.JavaScriptCompiler().compile(environment, options, undefined, true);
	    return env.template(templateSpec);
	  }

	  // Template is only compiled on first use and cached after that point.
	  function ret(context, execOptions) {
	    if (!compiled) {
	      compiled = compileInput();
	    }
	    return compiled.call(this, context, execOptions);
	  }
	  ret._setup = function (setupOptions) {
	    if (!compiled) {
	      compiled = compileInput();
	    }
	    return compiled._setup(setupOptions);
	  };
	  ret._child = function (i, data, blockParams, depths) {
	    if (!compiled) {
	      compiled = compileInput();
	    }
	    return compiled._child(i, data, blockParams, depths);
	  };
	  return ret;
	}

	function argEquals(a, b) {
	  if (a === b) {
	    return true;
	  }

	  if (_isArray$indexOf.isArray(a) && _isArray$indexOf.isArray(b) && a.length === b.length) {
	    for (var i = 0; i < a.length; i++) {
	      if (!argEquals(a[i], b[i])) {
	        return false;
	      }
	    }
	    return true;
	  }
	}

	function transformLiteralToPath(sexpr) {
	  if (!sexpr.path.parts) {
	    var literal = sexpr.path;
	    // Casting to string here to make false and 0 literal values play nicely with the rest
	    // of the system.
	    sexpr.path = new _AST2['default'].PathExpression(false, 0, [literal.original + ''], literal.original + '', literal.loc);
	  }
	}

/***/ },
/* 5 */
/***/ function(module, exports, __webpack_require__) {

	'use strict';

	var _interopRequireDefault = __webpack_require__(8)['default'];

	exports.__esModule = true;

	var _COMPILER_REVISION$REVISION_CHANGES = __webpack_require__(10);

	var _Exception = __webpack_require__(12);

	var _Exception2 = _interopRequireDefault(_Exception);

	var _isArray = __webpack_require__(13);

	var _CodeGen = __webpack_require__(18);

	var _CodeGen2 = _interopRequireDefault(_CodeGen);

	function Literal(value) {
	  this.value = value;
	}

	function JavaScriptCompiler() {}

	JavaScriptCompiler.prototype = {
	  // PUBLIC API: You can override these methods in a subclass to provide
	  // alternative compiled forms for name lookup and buffering semantics
	  nameLookup: function nameLookup(parent, name /* , type*/) {
	    if (JavaScriptCompiler.isValidJavaScriptVariableName(name)) {
	      return [parent, '.', name];
	    } else {
	      return [parent, '[\'', name, '\']'];
	    }
	  },
	  depthedLookup: function depthedLookup(name) {
	    return [this.aliasable('this.lookup'), '(depths, "', name, '")'];
	  },

	  compilerInfo: function compilerInfo() {
	    var revision = _COMPILER_REVISION$REVISION_CHANGES.COMPILER_REVISION,
	        versions = _COMPILER_REVISION$REVISION_CHANGES.REVISION_CHANGES[revision];
	    return [revision, versions];
	  },

	  appendToBuffer: function appendToBuffer(source, location, explicit) {
	    // Force a source as this simplifies the merge logic.
	    if (!_isArray.isArray(source)) {
	      source = [source];
	    }
	    source = this.source.wrap(source, location);

	    if (this.environment.isSimple) {
	      return ['return ', source, ';'];
	    } else if (explicit) {
	      // This is a case where the buffer operation occurs as a child of another
	      // construct, generally braces. We have to explicitly output these buffer
	      // operations to ensure that the emitted code goes in the correct location.
	      return ['buffer += ', source, ';'];
	    } else {
	      source.appendToBuffer = true;
	      return source;
	    }
	  },

	  initializeBuffer: function initializeBuffer() {
	    return this.quotedString('');
	  },
	  // END PUBLIC API

	  compile: function compile(environment, options, context, asObject) {
	    this.environment = environment;
	    this.options = options;
	    this.stringParams = this.options.stringParams;
	    this.trackIds = this.options.trackIds;
	    this.precompile = !asObject;

	    this.name = this.environment.name;
	    this.isChild = !!context;
	    this.context = context || {
	      programs: [],
	      environments: []
	    };

	    this.preamble();

	    this.stackSlot = 0;
	    this.stackVars = [];
	    this.aliases = {};
	    this.registers = { list: [] };
	    this.hashes = [];
	    this.compileStack = [];
	    this.inlineStack = [];
	    this.blockParams = [];

	    this.compileChildren(environment, options);

	    this.useDepths = this.useDepths || environment.useDepths || this.options.compat;
	    this.useBlockParams = this.useBlockParams || environment.useBlockParams;

	    var opcodes = environment.opcodes,
	        opcode = undefined,
	        firstLoc = undefined,
	        i = undefined,
	        l = undefined;

	    for (i = 0, l = opcodes.length; i < l; i++) {
	      opcode = opcodes[i];

	      this.source.currentLocation = opcode.loc;
	      firstLoc = firstLoc || opcode.loc;
	      this[opcode.opcode].apply(this, opcode.args);
	    }

	    // Flush any trailing content that might be pending.
	    this.source.currentLocation = firstLoc;
	    this.pushSource('');

	    /* istanbul ignore next */
	    if (this.stackSlot || this.inlineStack.length || this.compileStack.length) {
	      throw new _Exception2['default']('Compile completed with content left on stack');
	    }

	    var fn = this.createFunctionContext(asObject);
	    if (!this.isChild) {
	      var ret = {
	        compiler: this.compilerInfo(),
	        main: fn
	      };
	      var programs = this.context.programs;
	      for (i = 0, l = programs.length; i < l; i++) {
	        if (programs[i]) {
	          ret[i] = programs[i];
	        }
	      }

	      if (this.environment.usePartial) {
	        ret.usePartial = true;
	      }
	      if (this.options.data) {
	        ret.useData = true;
	      }
	      if (this.useDepths) {
	        ret.useDepths = true;
	      }
	      if (this.useBlockParams) {
	        ret.useBlockParams = true;
	      }
	      if (this.options.compat) {
	        ret.compat = true;
	      }

	      if (!asObject) {
	        ret.compiler = JSON.stringify(ret.compiler);

	        this.source.currentLocation = { start: { line: 1, column: 0 } };
	        ret = this.objectLiteral(ret);

	        if (options.srcName) {
	          ret = ret.toStringWithSourceMap({ file: options.destName });
	          ret.map = ret.map && ret.map.toString();
	        } else {
	          ret = ret.toString();
	        }
	      } else {
	        ret.compilerOptions = this.options;
	      }

	      return ret;
	    } else {
	      return fn;
	    }
	  },

	  preamble: function preamble() {
	    // track the last context pushed into place to allow skipping the
	    // getContext opcode when it would be a noop
	    this.lastContext = 0;
	    this.source = new _CodeGen2['default'](this.options.srcName);
	  },

	  createFunctionContext: function createFunctionContext(asObject) {
	    var varDeclarations = '';

	    var locals = this.stackVars.concat(this.registers.list);
	    if (locals.length > 0) {
	      varDeclarations += ', ' + locals.join(', ');
	    }

	    // Generate minimizer alias mappings
	    //
	    // When using true SourceNodes, this will update all references to the given alias
	    // as the source nodes are reused in situ. For the non-source node compilation mode,
	    // aliases will not be used, but this case is already being run on the client and
	    // we aren't concern about minimizing the template size.
	    var aliasCount = 0;
	    for (var alias in this.aliases) {
	      // eslint-disable-line guard-for-in
	      var node = this.aliases[alias];

	      if (this.aliases.hasOwnProperty(alias) && node.children && node.referenceCount > 1) {
	        varDeclarations += ', alias' + ++aliasCount + '=' + alias;
	        node.children[0] = 'alias' + aliasCount;
	      }
	    }

	    var params = ['depth0', 'helpers', 'partials', 'data'];

	    if (this.useBlockParams || this.useDepths) {
	      params.push('blockParams');
	    }
	    if (this.useDepths) {
	      params.push('depths');
	    }

	    // Perform a second pass over the output to merge content when possible
	    var source = this.mergeSource(varDeclarations);

	    if (asObject) {
	      params.push(source);

	      return Function.apply(this, params);
	    } else {
	      return this.source.wrap(['function(', params.join(','), ') {\n  ', source, '}']);
	    }
	  },
	  mergeSource: function mergeSource(varDeclarations) {
	    var isSimple = this.environment.isSimple,
	        appendOnly = !this.forceBuffer,
	        appendFirst = undefined,
	        sourceSeen = undefined,
	        bufferStart = undefined,
	        bufferEnd = undefined;
	    this.source.each(function (line) {
	      if (line.appendToBuffer) {
	        if (bufferStart) {
	          line.prepend('  + ');
	        } else {
	          bufferStart = line;
	        }
	        bufferEnd = line;
	      } else {
	        if (bufferStart) {
	          if (!sourceSeen) {
	            appendFirst = true;
	          } else {
	            bufferStart.prepend('buffer += ');
	          }
	          bufferEnd.add(';');
	          bufferStart = bufferEnd = undefined;
	        }

	        sourceSeen = true;
	        if (!isSimple) {
	          appendOnly = false;
	        }
	      }
	    });

	    if (appendOnly) {
	      if (bufferStart) {
	        bufferStart.prepend('return ');
	        bufferEnd.add(';');
	      } else if (!sourceSeen) {
	        this.source.push('return "";');
	      }
	    } else {
	      varDeclarations += ', buffer = ' + (appendFirst ? '' : this.initializeBuffer());

	      if (bufferStart) {
	        bufferStart.prepend('return buffer + ');
	        bufferEnd.add(';');
	      } else {
	        this.source.push('return buffer;');
	      }
	    }

	    if (varDeclarations) {
	      this.source.prepend('var ' + varDeclarations.substring(2) + (appendFirst ? '' : ';\n'));
	    }

	    return this.source.merge();
	  },

	  // [blockValue]
	  //
	  // On stack, before: hash, inverse, program, value
	  // On stack, after: return value of blockHelperMissing
	  //
	  // The purpose of this opcode is to take a block of the form
	  // `{{#this.foo}}...{{/this.foo}}`, resolve the value of `foo`, and
	  // replace it on the stack with the result of properly
	  // invoking blockHelperMissing.
	  blockValue: function blockValue(name) {
	    var blockHelperMissing = this.aliasable('helpers.blockHelperMissing'),
	        params = [this.contextName(0)];
	    this.setupHelperArgs(name, 0, params);

	    var blockName = this.popStack();
	    params.splice(1, 0, blockName);

	    this.push(this.source.functionCall(blockHelperMissing, 'call', params));
	  },

	  // [ambiguousBlockValue]
	  //
	  // On stack, before: hash, inverse, program, value
	  // Compiler value, before: lastHelper=value of last found helper, if any
	  // On stack, after, if no lastHelper: same as [blockValue]
	  // On stack, after, if lastHelper: value
	  ambiguousBlockValue: function ambiguousBlockValue() {
	    // We're being a bit cheeky and reusing the options value from the prior exec
	    var blockHelperMissing = this.aliasable('helpers.blockHelperMissing'),
	        params = [this.contextName(0)];
	    this.setupHelperArgs('', 0, params, true);

	    this.flushInline();

	    var current = this.topStack();
	    params.splice(1, 0, current);

	    this.pushSource(['if (!', this.lastHelper, ') { ', current, ' = ', this.source.functionCall(blockHelperMissing, 'call', params), '}']);
	  },

	  // [appendContent]
	  //
	  // On stack, before: ...
	  // On stack, after: ...
	  //
	  // Appends the string value of `content` to the current buffer
	  appendContent: function appendContent(content) {
	    if (this.pendingContent) {
	      content = this.pendingContent + content;
	    } else {
	      this.pendingLocation = this.source.currentLocation;
	    }

	    this.pendingContent = content;
	  },

	  // [append]
	  //
	  // On stack, before: value, ...
	  // On stack, after: ...
	  //
	  // Coerces `value` to a String and appends it to the current buffer.
	  //
	  // If `value` is truthy, or 0, it is coerced into a string and appended
	  // Otherwise, the empty string is appended
	  append: function append() {
	    if (this.isInline()) {
	      this.replaceStack(function (current) {
	        return [' != null ? ', current, ' : ""'];
	      });

	      this.pushSource(this.appendToBuffer(this.popStack()));
	    } else {
	      var local = this.popStack();
	      this.pushSource(['if (', local, ' != null) { ', this.appendToBuffer(local, undefined, true), ' }']);
	      if (this.environment.isSimple) {
	        this.pushSource(['else { ', this.appendToBuffer('\'\'', undefined, true), ' }']);
	      }
	    }
	  },

	  // [appendEscaped]
	  //
	  // On stack, before: value, ...
	  // On stack, after: ...
	  //
	  // Escape `value` and append it to the buffer
	  appendEscaped: function appendEscaped() {
	    this.pushSource(this.appendToBuffer([this.aliasable('this.escapeExpression'), '(', this.popStack(), ')']));
	  },

	  // [getContext]
	  //
	  // On stack, before: ...
	  // On stack, after: ...
	  // Compiler value, after: lastContext=depth
	  //
	  // Set the value of the `lastContext` compiler value to the depth
	  getContext: function getContext(depth) {
	    this.lastContext = depth;
	  },

	  // [pushContext]
	  //
	  // On stack, before: ...
	  // On stack, after: currentContext, ...
	  //
	  // Pushes the value of the current context onto the stack.
	  pushContext: function pushContext() {
	    this.pushStackLiteral(this.contextName(this.lastContext));
	  },

	  // [lookupOnContext]
	  //
	  // On stack, before: ...
	  // On stack, after: currentContext[name], ...
	  //
	  // Looks up the value of `name` on the current context and pushes
	  // it onto the stack.
	  lookupOnContext: function lookupOnContext(parts, falsy, scoped) {
	    var i = 0;

	    if (!scoped && this.options.compat && !this.lastContext) {
	      // The depthed query is expected to handle the undefined logic for the root level that
	      // is implemented below, so we evaluate that directly in compat mode
	      this.push(this.depthedLookup(parts[i++]));
	    } else {
	      this.pushContext();
	    }

	    this.resolvePath('context', parts, i, falsy);
	  },

	  // [lookupBlockParam]
	  //
	  // On stack, before: ...
	  // On stack, after: blockParam[name], ...
	  //
	  // Looks up the value of `parts` on the given block param and pushes
	  // it onto the stack.
	  lookupBlockParam: function lookupBlockParam(blockParamId, parts) {
	    this.useBlockParams = true;

	    this.push(['blockParams[', blockParamId[0], '][', blockParamId[1], ']']);
	    this.resolvePath('context', parts, 1);
	  },

	  // [lookupData]
	  //
	  // On stack, before: ...
	  // On stack, after: data, ...
	  //
	  // Push the data lookup operator
	  lookupData: function lookupData(depth, parts) {
	    if (!depth) {
	      this.pushStackLiteral('data');
	    } else {
	      this.pushStackLiteral('this.data(data, ' + depth + ')');
	    }

	    this.resolvePath('data', parts, 0, true);
	  },

	  resolvePath: function resolvePath(type, parts, i, falsy) {
	    var _this = this;

	    if (this.options.strict || this.options.assumeObjects) {
	      this.push(strictLookup(this.options.strict, this, parts, type));
	      return;
	    }

	    var len = parts.length;
	    for (; i < len; i++) {
	      /*eslint-disable no-loop-func */
	      this.replaceStack(function (current) {
	        var lookup = _this.nameLookup(current, parts[i], type);
	        // We want to ensure that zero and false are handled properly if the context (falsy flag)
	        // needs to have the special handling for these values.
	        if (!falsy) {
	          return [' != null ? ', lookup, ' : ', current];
	        } else {
	          // Otherwise we can use generic falsy handling
	          return [' && ', lookup];
	        }
	      });
	      /*eslint-enable no-loop-func */
	    }
	  },

	  // [resolvePossibleLambda]
	  //
	  // On stack, before: value, ...
	  // On stack, after: resolved value, ...
	  //
	  // If the `value` is a lambda, replace it on the stack by
	  // the return value of the lambda
	  resolvePossibleLambda: function resolvePossibleLambda() {
	    this.push([this.aliasable('this.lambda'), '(', this.popStack(), ', ', this.contextName(0), ')']);
	  },

	  // [pushStringParam]
	  //
	  // On stack, before: ...
	  // On stack, after: string, currentContext, ...
	  //
	  // This opcode is designed for use in string mode, which
	  // provides the string value of a parameter along with its
	  // depth rather than resolving it immediately.
	  pushStringParam: function pushStringParam(string, type) {
	    this.pushContext();
	    this.pushString(type);

	    // If it's a subexpression, the string result
	    // will be pushed after this opcode.
	    if (type !== 'SubExpression') {
	      if (typeof string === 'string') {
	        this.pushString(string);
	      } else {
	        this.pushStackLiteral(string);
	      }
	    }
	  },

	  emptyHash: function emptyHash(omitEmpty) {
	    if (this.trackIds) {
	      this.push('{}'); // hashIds
	    }
	    if (this.stringParams) {
	      this.push('{}'); // hashContexts
	      this.push('{}'); // hashTypes
	    }
	    this.pushStackLiteral(omitEmpty ? 'undefined' : '{}');
	  },
	  pushHash: function pushHash() {
	    if (this.hash) {
	      this.hashes.push(this.hash);
	    }
	    this.hash = { values: [], types: [], contexts: [], ids: [] };
	  },
	  popHash: function popHash() {
	    var hash = this.hash;
	    this.hash = this.hashes.pop();

	    if (this.trackIds) {
	      this.push(this.objectLiteral(hash.ids));
	    }
	    if (this.stringParams) {
	      this.push(this.objectLiteral(hash.contexts));
	      this.push(this.objectLiteral(hash.types));
	    }

	    this.push(this.objectLiteral(hash.values));
	  },

	  // [pushString]
	  //
	  // On stack, before: ...
	  // On stack, after: quotedString(string), ...
	  //
	  // Push a quoted version of `string` onto the stack
	  pushString: function pushString(string) {
	    this.pushStackLiteral(this.quotedString(string));
	  },

	  // [pushLiteral]
	  //
	  // On stack, before: ...
	  // On stack, after: value, ...
	  //
	  // Pushes a value onto the stack. This operation prevents
	  // the compiler from creating a temporary variable to hold
	  // it.
	  pushLiteral: function pushLiteral(value) {
	    this.pushStackLiteral(value);
	  },

	  // [pushProgram]
	  //
	  // On stack, before: ...
	  // On stack, after: program(guid), ...
	  //
	  // Push a program expression onto the stack. This takes
	  // a compile-time guid and converts it into a runtime-accessible
	  // expression.
	  pushProgram: function pushProgram(guid) {
	    if (guid != null) {
	      this.pushStackLiteral(this.programExpression(guid));
	    } else {
	      this.pushStackLiteral(null);
	    }
	  },

	  // [invokeHelper]
	  //
	  // On stack, before: hash, inverse, program, params..., ...
	  // On stack, after: result of helper invocation
	  //
	  // Pops off the helper's parameters, invokes the helper,
	  // and pushes the helper's return value onto the stack.
	  //
	  // If the helper is not found, `helperMissing` is called.
	  invokeHelper: function invokeHelper(paramSize, name, isSimple) {
	    var nonHelper = this.popStack(),
	        helper = this.setupHelper(paramSize, name),
	        simple = isSimple ? [helper.name, ' || '] : '';

	    var lookup = ['('].concat(simple, nonHelper);
	    if (!this.options.strict) {
	      lookup.push(' || ', this.aliasable('helpers.helperMissing'));
	    }
	    lookup.push(')');

	    this.push(this.source.functionCall(lookup, 'call', helper.callParams));
	  },

	  // [invokeKnownHelper]
	  //
	  // On stack, before: hash, inverse, program, params..., ...
	  // On stack, after: result of helper invocation
	  //
	  // This operation is used when the helper is known to exist,
	  // so a `helperMissing` fallback is not required.
	  invokeKnownHelper: function invokeKnownHelper(paramSize, name) {
	    var helper = this.setupHelper(paramSize, name);
	    this.push(this.source.functionCall(helper.name, 'call', helper.callParams));
	  },

	  // [invokeAmbiguous]
	  //
	  // On stack, before: hash, inverse, program, params..., ...
	  // On stack, after: result of disambiguation
	  //
	  // This operation is used when an expression like `{{foo}}`
	  // is provided, but we don't know at compile-time whether it
	  // is a helper or a path.
	  //
	  // This operation emits more code than the other options,
	  // and can be avoided by passing the `knownHelpers` and
	  // `knownHelpersOnly` flags at compile-time.
	  invokeAmbiguous: function invokeAmbiguous(name, helperCall) {
	    this.useRegister('helper');

	    var nonHelper = this.popStack();

	    this.emptyHash();
	    var helper = this.setupHelper(0, name, helperCall);

	    var helperName = this.lastHelper = this.nameLookup('helpers', name, 'helper');

	    var lookup = ['(', '(helper = ', helperName, ' || ', nonHelper, ')'];
	    if (!this.options.strict) {
	      lookup[0] = '(helper = ';
	      lookup.push(' != null ? helper : ', this.aliasable('helpers.helperMissing'));
	    }

	    this.push(['(', lookup, helper.paramsInit ? ['),(', helper.paramsInit] : [], '),', '(typeof helper === ', this.aliasable('"function"'), ' ? ', this.source.functionCall('helper', 'call', helper.callParams), ' : helper))']);
	  },

	  // [invokePartial]
	  //
	  // On stack, before: context, ...
	  // On stack after: result of partial invocation
	  //
	  // This operation pops off a context, invokes a partial with that context,
	  // and pushes the result of the invocation back.
	  invokePartial: function invokePartial(isDynamic, name, indent) {
	    var params = [],
	        options = this.setupParams(name, 1, params, false);

	    if (isDynamic) {
	      name = this.popStack();
	      delete options.name;
	    }

	    if (indent) {
	      options.indent = JSON.stringify(indent);
	    }
	    options.helpers = 'helpers';
	    options.partials = 'partials';

	    if (!isDynamic) {
	      params.unshift(this.nameLookup('partials', name, 'partial'));
	    } else {
	      params.unshift(name);
	    }

	    if (this.options.compat) {
	      options.depths = 'depths';
	    }
	    options = this.objectLiteral(options);
	    params.push(options);

	    this.push(this.source.functionCall('this.invokePartial', '', params));
	  },

	  // [assignToHash]
	  //
	  // On stack, before: value, ..., hash, ...
	  // On stack, after: ..., hash, ...
	  //
	  // Pops a value off the stack and assigns it to the current hash
	  assignToHash: function assignToHash(key) {
	    var value = this.popStack(),
	        context = undefined,
	        type = undefined,
	        id = undefined;

	    if (this.trackIds) {
	      id = this.popStack();
	    }
	    if (this.stringParams) {
	      type = this.popStack();
	      context = this.popStack();
	    }

	    var hash = this.hash;
	    if (context) {
	      hash.contexts[key] = context;
	    }
	    if (type) {
	      hash.types[key] = type;
	    }
	    if (id) {
	      hash.ids[key] = id;
	    }
	    hash.values[key] = value;
	  },

	  pushId: function pushId(type, name, child) {
	    if (type === 'BlockParam') {
	      this.pushStackLiteral('blockParams[' + name[0] + '].path[' + name[1] + ']' + (child ? ' + ' + JSON.stringify('.' + child) : ''));
	    } else if (type === 'PathExpression') {
	      this.pushString(name);
	    } else if (type === 'SubExpression') {
	      this.pushStackLiteral('true');
	    } else {
	      this.pushStackLiteral('null');
	    }
	  },

	  // HELPERS

	  compiler: JavaScriptCompiler,

	  compileChildren: function compileChildren(environment, options) {
	    var children = environment.children,
	        child = undefined,
	        compiler = undefined;

	    for (var i = 0, l = children.length; i < l; i++) {
	      child = children[i];
	      compiler = new this.compiler(); // eslint-disable-line new-cap

	      var index = this.matchExistingProgram(child);

	      if (index == null) {
	        this.context.programs.push(''); // Placeholder to prevent name conflicts for nested children
	        index = this.context.programs.length;
	        child.index = index;
	        child.name = 'program' + index;
	        this.context.programs[index] = compiler.compile(child, options, this.context, !this.precompile);
	        this.context.environments[index] = child;

	        this.useDepths = this.useDepths || compiler.useDepths;
	        this.useBlockParams = this.useBlockParams || compiler.useBlockParams;
	      } else {
	        child.index = index;
	        child.name = 'program' + index;

	        this.useDepths = this.useDepths || child.useDepths;
	        this.useBlockParams = this.useBlockParams || child.useBlockParams;
	      }
	    }
	  },
	  matchExistingProgram: function matchExistingProgram(child) {
	    for (var i = 0, len = this.context.environments.length; i < len; i++) {
	      var environment = this.context.environments[i];
	      if (environment && environment.equals(child)) {
	        return i;
	      }
	    }
	  },

	  programExpression: function programExpression(guid) {
	    var child = this.environment.children[guid],
	        programParams = [child.index, 'data', child.blockParams];

	    if (this.useBlockParams || this.useDepths) {
	      programParams.push('blockParams');
	    }
	    if (this.useDepths) {
	      programParams.push('depths');
	    }

	    return 'this.program(' + programParams.join(', ') + ')';
	  },

	  useRegister: function useRegister(name) {
	    if (!this.registers[name]) {
	      this.registers[name] = true;
	      this.registers.list.push(name);
	    }
	  },

	  push: function push(expr) {
	    if (!(expr instanceof Literal)) {
	      expr = this.source.wrap(expr);
	    }

	    this.inlineStack.push(expr);
	    return expr;
	  },

	  pushStackLiteral: function pushStackLiteral(item) {
	    this.push(new Literal(item));
	  },

	  pushSource: function pushSource(source) {
	    if (this.pendingContent) {
	      this.source.push(this.appendToBuffer(this.source.quotedString(this.pendingContent), this.pendingLocation));
	      this.pendingContent = undefined;
	    }

	    if (source) {
	      this.source.push(source);
	    }
	  },

	  replaceStack: function replaceStack(callback) {
	    var prefix = ['('],
	        stack = undefined,
	        createdStack = undefined,
	        usedLiteral = undefined;

	    /* istanbul ignore next */
	    if (!this.isInline()) {
	      throw new _Exception2['default']('replaceStack on non-inline');
	    }

	    // We want to merge the inline statement into the replacement statement via ','
	    var top = this.popStack(true);

	    if (top instanceof Literal) {
	      // Literals do not need to be inlined
	      stack = [top.value];
	      prefix = ['(', stack];
	      usedLiteral = true;
	    } else {
	      // Get or create the current stack name for use by the inline
	      createdStack = true;
	      var _name = this.incrStack();

	      prefix = ['((', this.push(_name), ' = ', top, ')'];
	      stack = this.topStack();
	    }

	    var item = callback.call(this, stack);

	    if (!usedLiteral) {
	      this.popStack();
	    }
	    if (createdStack) {
	      this.stackSlot--;
	    }
	    this.push(prefix.concat(item, ')'));
	  },

	  incrStack: function incrStack() {
	    this.stackSlot++;
	    if (this.stackSlot > this.stackVars.length) {
	      this.stackVars.push('stack' + this.stackSlot);
	    }
	    return this.topStackName();
	  },
	  topStackName: function topStackName() {
	    return 'stack' + this.stackSlot;
	  },
	  flushInline: function flushInline() {
	    var inlineStack = this.inlineStack;
	    this.inlineStack = [];
	    for (var i = 0, len = inlineStack.length; i < len; i++) {
	      var entry = inlineStack[i];
	      /* istanbul ignore if */
	      if (entry instanceof Literal) {
	        this.compileStack.push(entry);
	      } else {
	        var stack = this.incrStack();
	        this.pushSource([stack, ' = ', entry, ';']);
	        this.compileStack.push(stack);
	      }
	    }
	  },
	  isInline: function isInline() {
	    return this.inlineStack.length;
	  },

	  popStack: function popStack(wrapped) {
	    var inline = this.isInline(),
	        item = (inline ? this.inlineStack : this.compileStack).pop();

	    if (!wrapped && item instanceof Literal) {
	      return item.value;
	    } else {
	      if (!inline) {
	        /* istanbul ignore next */
	        if (!this.stackSlot) {
	          throw new _Exception2['default']('Invalid stack pop');
	        }
	        this.stackSlot--;
	      }
	      return item;
	    }
	  },

	  topStack: function topStack() {
	    var stack = this.isInline() ? this.inlineStack : this.compileStack,
	        item = stack[stack.length - 1];

	    /* istanbul ignore if */
	    if (item instanceof Literal) {
	      return item.value;
	    } else {
	      return item;
	    }
	  },

	  contextName: function contextName(context) {
	    if (this.useDepths && context) {
	      return 'depths[' + context + ']';
	    } else {
	      return 'depth' + context;
	    }
	  },

	  quotedString: function quotedString(str) {
	    return this.source.quotedString(str);
	  },

	  objectLiteral: function objectLiteral(obj) {
	    return this.source.objectLiteral(obj);
	  },

	  aliasable: function aliasable(name) {
	    var ret = this.aliases[name];
	    if (ret) {
	      ret.referenceCount++;
	      return ret;
	    }

	    ret = this.aliases[name] = this.source.wrap(name);
	    ret.aliasable = true;
	    ret.referenceCount = 1;

	    return ret;
	  },

	  setupHelper: function setupHelper(paramSize, name, blockHelper) {
	    var params = [],
	        paramsInit = this.setupHelperArgs(name, paramSize, params, blockHelper);
	    var foundHelper = this.nameLookup('helpers', name, 'helper');

	    return {
	      params: params,
	      paramsInit: paramsInit,
	      name: foundHelper,
	      callParams: [this.contextName(0)].concat(params)
	    };
	  },

	  setupParams: function setupParams(helper, paramSize, params) {
	    var options = {},
	        contexts = [],
	        types = [],
	        ids = [],
	        param = undefined;

	    options.name = this.quotedString(helper);
	    options.hash = this.popStack();

	    if (this.trackIds) {
	      options.hashIds = this.popStack();
	    }
	    if (this.stringParams) {
	      options.hashTypes = this.popStack();
	      options.hashContexts = this.popStack();
	    }

	    var inverse = this.popStack(),
	        program = this.popStack();

	    // Avoid setting fn and inverse if neither are set. This allows
	    // helpers to do a check for `if (options.fn)`
	    if (program || inverse) {
	      options.fn = program || 'this.noop';
	      options.inverse = inverse || 'this.noop';
	    }

	    // The parameters go on to the stack in order (making sure that they are evaluated in order)
	    // so we need to pop them off the stack in reverse order
	    var i = paramSize;
	    while (i--) {
	      param = this.popStack();
	      params[i] = param;

	      if (this.trackIds) {
	        ids[i] = this.popStack();
	      }
	      if (this.stringParams) {
	        types[i] = this.popStack();
	        contexts[i] = this.popStack();
	      }
	    }

	    if (this.trackIds) {
	      options.ids = this.source.generateArray(ids);
	    }
	    if (this.stringParams) {
	      options.types = this.source.generateArray(types);
	      options.contexts = this.source.generateArray(contexts);
	    }

	    if (this.options.data) {
	      options.data = 'data';
	    }
	    if (this.useBlockParams) {
	      options.blockParams = 'blockParams';
	    }
	    return options;
	  },

	  setupHelperArgs: function setupHelperArgs(helper, paramSize, params, useRegister) {
	    var options = this.setupParams(helper, paramSize, params, true);
	    options = this.objectLiteral(options);
	    if (useRegister) {
	      this.useRegister('options');
	      params.push('options');
	      return ['options=', options];
	    } else {
	      params.push(options);
	      return '';
	    }
	  }
	};

	(function () {
	  var reservedWords = ('break else new var' + ' case finally return void' + ' catch for switch while' + ' continue function this with' + ' default if throw' + ' delete in try' + ' do instanceof typeof' + ' abstract enum int short' + ' boolean export interface static' + ' byte extends long super' + ' char final native synchronized' + ' class float package throws' + ' const goto private transient' + ' debugger implements protected volatile' + ' double import public let yield await' + ' null true false').split(' ');

	  var compilerWords = JavaScriptCompiler.RESERVED_WORDS = {};

	  for (var i = 0, l = reservedWords.length; i < l; i++) {
	    compilerWords[reservedWords[i]] = true;
	  }
	})();

	JavaScriptCompiler.isValidJavaScriptVariableName = function (name) {
	  return !JavaScriptCompiler.RESERVED_WORDS[name] && /^[a-zA-Z_$][0-9a-zA-Z_$]*$/.test(name);
	};

	function strictLookup(requireTerminal, compiler, parts, type) {
	  var stack = compiler.popStack(),
	      i = 0,
	      len = parts.length;
	  if (requireTerminal) {
	    len--;
	  }

	  for (; i < len; i++) {
	    stack = compiler.nameLookup(stack, parts[i], type);
	  }

	  if (requireTerminal) {
	    return [compiler.aliasable('this.strict'), '(', stack, ', ', compiler.quotedString(parts[i]), ')'];
	  } else {
	    return stack;
	  }
	}

	exports['default'] = JavaScriptCompiler;
	module.exports = exports['default'];

/***/ },
/* 6 */
/***/ function(module, exports, __webpack_require__) {

	'use strict';

	var _interopRequireDefault = __webpack_require__(8)['default'];

	exports.__esModule = true;

	var _Exception = __webpack_require__(12);

	var _Exception2 = _interopRequireDefault(_Exception);

	var _AST = __webpack_require__(2);

	var _AST2 = _interopRequireDefault(_AST);

	function Visitor() {
	  this.parents = [];
	}

	Visitor.prototype = {
	  constructor: Visitor,
	  mutating: false,

	  // Visits a given value. If mutating, will replace the value if necessary.
	  acceptKey: function acceptKey(node, name) {
	    var value = this.accept(node[name]);
	    if (this.mutating) {
	      // Hacky sanity check:
	      if (value && (!value.type || !_AST2['default'][value.type])) {
	        throw new _Exception2['default']('Unexpected node type "' + value.type + '" found when accepting ' + name + ' on ' + node.type);
	      }
	      node[name] = value;
	    }
	  },

	  // Performs an accept operation with added sanity check to ensure
	  // required keys are not removed.
	  acceptRequired: function acceptRequired(node, name) {
	    this.acceptKey(node, name);

	    if (!node[name]) {
	      throw new _Exception2['default'](node.type + ' requires ' + name);
	    }
	  },

	  // Traverses a given array. If mutating, empty respnses will be removed
	  // for child elements.
	  acceptArray: function acceptArray(array) {
	    for (var i = 0, l = array.length; i < l; i++) {
	      this.acceptKey(array, i);

	      if (!array[i]) {
	        array.splice(i, 1);
	        i--;
	        l--;
	      }
	    }
	  },

	  accept: function accept(object) {
	    if (!object) {
	      return;
	    }

	    if (this.current) {
	      this.parents.unshift(this.current);
	    }
	    this.current = object;

	    var ret = this[object.type](object);

	    this.current = this.parents.shift();

	    if (!this.mutating || ret) {
	      return ret;
	    } else if (ret !== false) {
	      return object;
	    }
	  },

	  Program: function Program(program) {
	    this.acceptArray(program.body);
	  },

	  MustacheStatement: function MustacheStatement(mustache) {
	    this.acceptRequired(mustache, 'path');
	    this.acceptArray(mustache.params);
	    this.acceptKey(mustache, 'hash');
	  },

	  BlockStatement: function BlockStatement(block) {
	    this.acceptRequired(block, 'path');
	    this.acceptArray(block.params);
	    this.acceptKey(block, 'hash');

	    this.acceptKey(block, 'program');
	    this.acceptKey(block, 'inverse');
	  },

	  PartialStatement: function PartialStatement(partial) {
	    this.acceptRequired(partial, 'name');
	    this.acceptArray(partial.params);
	    this.acceptKey(partial, 'hash');
	  },

	  ContentStatement: function ContentStatement() {},
	  CommentStatement: function CommentStatement() {},

	  SubExpression: function SubExpression(sexpr) {
	    this.acceptRequired(sexpr, 'path');
	    this.acceptArray(sexpr.params);
	    this.acceptKey(sexpr, 'hash');
	  },

	  PathExpression: function PathExpression() {},

	  StringLiteral: function StringLiteral() {},
	  NumberLiteral: function NumberLiteral() {},
	  BooleanLiteral: function BooleanLiteral() {},
	  UndefinedLiteral: function UndefinedLiteral() {},
	  NullLiteral: function NullLiteral() {},

	  Hash: function Hash(hash) {
	    this.acceptArray(hash.pairs);
	  },
	  HashPair: function HashPair(pair) {
	    this.acceptRequired(pair, 'value');
	  }
	};

	exports['default'] = Visitor;
	module.exports = exports['default'];
	/* content */ /* comment */ /* path */ /* string */ /* number */ /* bool */ /* literal */ /* literal */

/***/ },
/* 7 */
/***/ function(module, exports, __webpack_require__) {

	/* WEBPACK VAR INJECTION */(function(global) {'use strict';

	exports.__esModule = true;
	/*global window */

	exports['default'] = function (Handlebars) {
	  /* istanbul ignore next */
	  var root = typeof global !== 'undefined' ? global : window,
	      $Handlebars = root.Handlebars;
	  /* istanbul ignore next */
	  Handlebars.noConflict = function () {
	    if (root.Handlebars === Handlebars) {
	      root.Handlebars = $Handlebars;
	    }
	  };
	};

	module.exports = exports['default'];
	/* WEBPACK VAR INJECTION */}.call(exports, (function() { return this; }())))

/***/ },
/* 8 */
/***/ function(module, exports, __webpack_require__) {

	"use strict";

	exports["default"] = function (obj) {
	  return obj && obj.__esModule ? obj : {
	    "default": obj
	  };
	};

	exports.__esModule = true;

/***/ },
/* 9 */
/***/ function(module, exports, __webpack_require__) {

	"use strict";

	exports["default"] = function (obj) {
	  if (obj && obj.__esModule) {
	    return obj;
	  } else {
	    var newObj = {};

	    if (typeof obj === "object" && obj !== null) {
	      for (var key in obj) {
	        if (Object.prototype.hasOwnProperty.call(obj, key)) newObj[key] = obj[key];
	      }
	    }

	    newObj["default"] = obj;
	    return newObj;
	  }
	};

	exports.__esModule = true;

/***/ },
/* 10 */
/***/ function(module, exports, __webpack_require__) {

	'use strict';

	var _interopRequireWildcard = __webpack_require__(9)['default'];

	var _interopRequireDefault = __webpack_require__(8)['default'];

	exports.__esModule = true;
	exports.HandlebarsEnvironment = HandlebarsEnvironment;
	exports.createFrame = createFrame;

	var _import = __webpack_require__(13);

	var Utils = _interopRequireWildcard(_import);

	var _Exception = __webpack_require__(12);

	var _Exception2 = _interopRequireDefault(_Exception);

	var VERSION = '3.0.1';
	exports.VERSION = VERSION;
	var COMPILER_REVISION = 6;

	exports.COMPILER_REVISION = COMPILER_REVISION;
	var REVISION_CHANGES = {
	  1: '<= 1.0.rc.2', // 1.0.rc.2 is actually rev2 but doesn't report it
	  2: '== 1.0.0-rc.3',
	  3: '== 1.0.0-rc.4',
	  4: '== 1.x.x',
	  5: '== 2.0.0-alpha.x',
	  6: '>= 2.0.0-beta.1'
	};

	exports.REVISION_CHANGES = REVISION_CHANGES;
	var isArray = Utils.isArray,
	    isFunction = Utils.isFunction,
	    toString = Utils.toString,
	    objectType = '[object Object]';

	function HandlebarsEnvironment(helpers, partials) {
	  this.helpers = helpers || {};
	  this.partials = partials || {};

	  registerDefaultHelpers(this);
	}

	HandlebarsEnvironment.prototype = {
	  constructor: HandlebarsEnvironment,

	  logger: logger,
	  log: log,

	  registerHelper: function registerHelper(name, fn) {
	    if (toString.call(name) === objectType) {
	      if (fn) {
	        throw new _Exception2['default']('Arg not supported with multiple helpers');
	      }
	      Utils.extend(this.helpers, name);
	    } else {
	      this.helpers[name] = fn;
	    }
	  },
	  unregisterHelper: function unregisterHelper(name) {
	    delete this.helpers[name];
	  },

	  registerPartial: function registerPartial(name, partial) {
	    if (toString.call(name) === objectType) {
	      Utils.extend(this.partials, name);
	    } else {
	      if (typeof partial === 'undefined') {
	        throw new _Exception2['default']('Attempting to register a partial as undefined');
	      }
	      this.partials[name] = partial;
	    }
	  },
	  unregisterPartial: function unregisterPartial(name) {
	    delete this.partials[name];
	  }
	};

	function registerDefaultHelpers(instance) {
	  instance.registerHelper('helperMissing', function () {
	    if (arguments.length === 1) {
	      // A missing field in a {{foo}} constuct.
	      return undefined;
	    } else {
	      // Someone is actually trying to call something, blow up.
	      throw new _Exception2['default']('Missing helper: "' + arguments[arguments.length - 1].name + '"');
	    }
	  });

	  instance.registerHelper('blockHelperMissing', function (context, options) {
	    var inverse = options.inverse,
	        fn = options.fn;

	    if (context === true) {
	      return fn(this);
	    } else if (context === false || context == null) {
	      return inverse(this);
	    } else if (isArray(context)) {
	      if (context.length > 0) {
	        if (options.ids) {
	          options.ids = [options.name];
	        }

	        return instance.helpers.each(context, options);
	      } else {
	        return inverse(this);
	      }
	    } else {
	      if (options.data && options.ids) {
	        var data = createFrame(options.data);
	        data.contextPath = Utils.appendContextPath(options.data.contextPath, options.name);
	        options = { data: data };
	      }

	      return fn(context, options);
	    }
	  });

	  instance.registerHelper('each', function (context, options) {
	    if (!options) {
	      throw new _Exception2['default']('Must pass iterator to #each');
	    }

	    var fn = options.fn,
	        inverse = options.inverse,
	        i = 0,
	        ret = '',
	        data = undefined,
	        contextPath = undefined;

	    if (options.data && options.ids) {
	      contextPath = Utils.appendContextPath(options.data.contextPath, options.ids[0]) + '.';
	    }

	    if (isFunction(context)) {
	      context = context.call(this);
	    }

	    if (options.data) {
	      data = createFrame(options.data);
	    }

	    function execIteration(field, index, last) {
	      if (data) {
	        data.key = field;
	        data.index = index;
	        data.first = index === 0;
	        data.last = !!last;

	        if (contextPath) {
	          data.contextPath = contextPath + field;
	        }
	      }

	      ret = ret + fn(context[field], {
	        data: data,
	        blockParams: Utils.blockParams([context[field], field], [contextPath + field, null])
	      });
	    }

	    if (context && typeof context === 'object') {
	      if (isArray(context)) {
	        for (var j = context.length; i < j; i++) {
	          execIteration(i, i, i === context.length - 1);
	        }
	      } else {
	        var priorKey = undefined;

	        for (var key in context) {
	          if (context.hasOwnProperty(key)) {
	            // We're running the iterations one step out of sync so we can detect
	            // the last iteration without have to scan the object twice and create
	            // an itermediate keys array.
	            if (priorKey) {
	              execIteration(priorKey, i - 1);
	            }
	            priorKey = key;
	            i++;
	          }
	        }
	        if (priorKey) {
	          execIteration(priorKey, i - 1, true);
	        }
	      }
	    }

	    if (i === 0) {
	      ret = inverse(this);
	    }

	    return ret;
	  });

	  instance.registerHelper('if', function (conditional, options) {
	    if (isFunction(conditional)) {
	      conditional = conditional.call(this);
	    }

	    // Default behavior is to render the positive path if the value is truthy and not empty.
	    // The `includeZero` option may be set to treat the condtional as purely not empty based on the
	    // behavior of isEmpty. Effectively this determines if 0 is handled by the positive path or negative.
	    if (!options.hash.includeZero && !conditional || Utils.isEmpty(conditional)) {
	      return options.inverse(this);
	    } else {
	      return options.fn(this);
	    }
	  });

	  instance.registerHelper('unless', function (conditional, options) {
	    return instance.helpers['if'].call(this, conditional, { fn: options.inverse, inverse: options.fn, hash: options.hash });
	  });

	  instance.registerHelper('with', function (context, options) {
	    if (isFunction(context)) {
	      context = context.call(this);
	    }

	    var fn = options.fn;

	    if (!Utils.isEmpty(context)) {
	      if (options.data && options.ids) {
	        var data = createFrame(options.data);
	        data.contextPath = Utils.appendContextPath(options.data.contextPath, options.ids[0]);
	        options = { data: data };
	      }

	      return fn(context, options);
	    } else {
	      return options.inverse(this);
	    }
	  });

	  instance.registerHelper('log', function (message, options) {
	    var level = options.data && options.data.level != null ? parseInt(options.data.level, 10) : 1;
	    instance.log(level, message);
	  });

	  instance.registerHelper('lookup', function (obj, field) {
	    return obj && obj[field];
	  });
	}

	var logger = {
	  methodMap: { 0: 'debug', 1: 'info', 2: 'warn', 3: 'error' },

	  // State enum
	  DEBUG: 0,
	  INFO: 1,
	  WARN: 2,
	  ERROR: 3,
	  level: 1,

	  // Can be overridden in the host environment
	  log: function log(level, message) {
	    if (typeof console !== 'undefined' && logger.level <= level) {
	      var method = logger.methodMap[level];
	      (console[method] || console.log).call(console, message); // eslint-disable-line no-console
	    }
	  }
	};

	exports.logger = logger;
	var log = logger.log;

	exports.log = log;

	function createFrame(object) {
	  var frame = Utils.extend({}, object);
	  frame._parent = object;
	  return frame;
	}

	/* [args, ]options */

/***/ },
/* 11 */
/***/ function(module, exports, __webpack_require__) {

	'use strict';

	exports.__esModule = true;
	// Build out our basic SafeString type
	function SafeString(string) {
	  this.string = string;
	}

	SafeString.prototype.toString = SafeString.prototype.toHTML = function () {
	  return '' + this.string;
	};

	exports['default'] = SafeString;
	module.exports = exports['default'];

/***/ },
/* 12 */
/***/ function(module, exports, __webpack_require__) {

	'use strict';

	exports.__esModule = true;

	var errorProps = ['description', 'fileName', 'lineNumber', 'message', 'name', 'number', 'stack'];

	function Exception(message, node) {
	  var loc = node && node.loc,
	      line = undefined,
	      column = undefined;
	  if (loc) {
	    line = loc.start.line;
	    column = loc.start.column;

	    message += ' - ' + line + ':' + column;
	  }

	  var tmp = Error.prototype.constructor.call(this, message);

	  // Unfortunately errors are not enumerable in Chrome (at least), so `for prop in tmp` doesn't work.
	  for (var idx = 0; idx < errorProps.length; idx++) {
	    this[errorProps[idx]] = tmp[errorProps[idx]];
	  }

	  if (Error.captureStackTrace) {
	    Error.captureStackTrace(this, Exception);
	  }

	  if (loc) {
	    this.lineNumber = line;
	    this.column = column;
	  }
	}

	Exception.prototype = new Error();

	exports['default'] = Exception;
	module.exports = exports['default'];

/***/ },
/* 13 */
/***/ function(module, exports, __webpack_require__) {

	'use strict';

	exports.__esModule = true;
	exports.extend = extend;

	// Older IE versions do not directly support indexOf so we must implement our own, sadly.
	exports.indexOf = indexOf;
	exports.escapeExpression = escapeExpression;
	exports.isEmpty = isEmpty;
	exports.blockParams = blockParams;
	exports.appendContextPath = appendContextPath;
	var escape = {
	  '&': '&amp;',
	  '<': '&lt;',
	  '>': '&gt;',
	  '"': '&quot;',
	  '\'': '&#x27;',
	  '`': '&#x60;'
	};

	var badChars = /[&<>"'`]/g,
	    possible = /[&<>"'`]/;

	function escapeChar(chr) {
	  return escape[chr];
	}

	function extend(obj /* , ...source */) {
	  for (var i = 1; i < arguments.length; i++) {
	    for (var key in arguments[i]) {
	      if (Object.prototype.hasOwnProperty.call(arguments[i], key)) {
	        obj[key] = arguments[i][key];
	      }
	    }
	  }

	  return obj;
	}

	var toString = Object.prototype.toString;

	exports.toString = toString;
	// Sourced from lodash
	// https://github.com/bestiejs/lodash/blob/master/LICENSE.txt
	/*eslint-disable func-style, no-var */
	var isFunction = function isFunction(value) {
	  return typeof value === 'function';
	};
	// fallback for older versions of Chrome and Safari
	/* istanbul ignore next */
	if (isFunction(/x/)) {
	  exports.isFunction = isFunction = function (value) {
	    return typeof value === 'function' && toString.call(value) === '[object Function]';
	  };
	}
	var isFunction;
	exports.isFunction = isFunction;
	/*eslint-enable func-style, no-var */

	/* istanbul ignore next */
	var isArray = Array.isArray || function (value) {
	  return value && typeof value === 'object' ? toString.call(value) === '[object Array]' : false;
	};exports.isArray = isArray;

	function indexOf(array, value) {
	  for (var i = 0, len = array.length; i < len; i++) {
	    if (array[i] === value) {
	      return i;
	    }
	  }
	  return -1;
	}

	function escapeExpression(string) {
	  if (typeof string !== 'string') {
	    // don't escape SafeStrings, since they're already safe
	    if (string && string.toHTML) {
	      return string.toHTML();
	    } else if (string == null) {
	      return '';
	    } else if (!string) {
	      return string + '';
	    }

	    // Force a string conversion as this will be done by the append regardless and
	    // the regex test will do this transparently behind the scenes, causing issues if
	    // an object's to string has escaped characters in it.
	    string = '' + string;
	  }

	  if (!possible.test(string)) {
	    return string;
	  }
	  return string.replace(badChars, escapeChar);
	}

	function isEmpty(value) {
	  if (!value && value !== 0) {
	    return true;
	  } else if (isArray(value) && value.length === 0) {
	    return true;
	  } else {
	    return false;
	  }
	}

	function blockParams(params, ids) {
	  params.path = ids;
	  return params;
	}

	function appendContextPath(contextPath, id) {
	  return (contextPath ? contextPath + '.' : '') + id;
	}

/***/ },
/* 14 */
/***/ function(module, exports, __webpack_require__) {

	'use strict';

	var _interopRequireWildcard = __webpack_require__(9)['default'];

	var _interopRequireDefault = __webpack_require__(8)['default'];

	exports.__esModule = true;
	exports.checkRevision = checkRevision;

	// TODO: Remove this line and break up compilePartial

	exports.template = template;
	exports.wrapProgram = wrapProgram;
	exports.resolvePartial = resolvePartial;
	exports.invokePartial = invokePartial;
	exports.noop = noop;

	var _import = __webpack_require__(13);

	var Utils = _interopRequireWildcard(_import);

	var _Exception = __webpack_require__(12);

	var _Exception2 = _interopRequireDefault(_Exception);

	var _COMPILER_REVISION$REVISION_CHANGES$createFrame = __webpack_require__(10);

	function checkRevision(compilerInfo) {
	  var compilerRevision = compilerInfo && compilerInfo[0] || 1,
	      currentRevision = _COMPILER_REVISION$REVISION_CHANGES$createFrame.COMPILER_REVISION;

	  if (compilerRevision !== currentRevision) {
	    if (compilerRevision < currentRevision) {
	      var runtimeVersions = _COMPILER_REVISION$REVISION_CHANGES$createFrame.REVISION_CHANGES[currentRevision],
	          compilerVersions = _COMPILER_REVISION$REVISION_CHANGES$createFrame.REVISION_CHANGES[compilerRevision];
	      throw new _Exception2['default']('Template was precompiled with an older version of Handlebars than the current runtime. ' + 'Please update your precompiler to a newer version (' + runtimeVersions + ') or downgrade your runtime to an older version (' + compilerVersions + ').');
	    } else {
	      // Use the embedded version info since the runtime doesn't know about this revision yet
	      throw new _Exception2['default']('Template was precompiled with a newer version of Handlebars than the current runtime. ' + 'Please update your runtime to a newer version (' + compilerInfo[1] + ').');
	    }
	  }
	}

	function template(templateSpec, env) {
	  /* istanbul ignore next */
	  if (!env) {
	    throw new _Exception2['default']('No environment passed to template');
	  }
	  if (!templateSpec || !templateSpec.main) {
	    throw new _Exception2['default']('Unknown template object: ' + typeof templateSpec);
	  }

	  // Note: Using env.VM references rather than local var references throughout this section to allow
	  // for external users to override these as psuedo-supported APIs.
	  env.VM.checkRevision(templateSpec.compiler);

	  function invokePartialWrapper(partial, context, options) {
	    if (options.hash) {
	      context = Utils.extend({}, context, options.hash);
	    }

	    partial = env.VM.resolvePartial.call(this, partial, context, options);
	    var result = env.VM.invokePartial.call(this, partial, context, options);

	    if (result == null && env.compile) {
	      options.partials[options.name] = env.compile(partial, templateSpec.compilerOptions, env);
	      result = options.partials[options.name](context, options);
	    }
	    if (result != null) {
	      if (options.indent) {
	        var lines = result.split('\n');
	        for (var i = 0, l = lines.length; i < l; i++) {
	          if (!lines[i] && i + 1 === l) {
	            break;
	          }

	          lines[i] = options.indent + lines[i];
	        }
	        result = lines.join('\n');
	      }
	      return result;
	    } else {
	      throw new _Exception2['default']('The partial ' + options.name + ' could not be compiled when running in runtime-only mode');
	    }
	  }

	  // Just add water
	  var container = {
	    strict: function strict(obj, name) {
	      if (!(name in obj)) {
	        throw new _Exception2['default']('"' + name + '" not defined in ' + obj);
	      }
	      return obj[name];
	    },
	    lookup: function lookup(depths, name) {
	      var len = depths.length;
	      for (var i = 0; i < len; i++) {
	        if (depths[i] && depths[i][name] != null) {
	          return depths[i][name];
	        }
	      }
	    },
	    lambda: function lambda(current, context) {
	      return typeof current === 'function' ? current.call(context) : current;
	    },

	    escapeExpression: Utils.escapeExpression,
	    invokePartial: invokePartialWrapper,

	    fn: function fn(i) {
	      return templateSpec[i];
	    },

	    programs: [],
	    program: function program(i, data, declaredBlockParams, blockParams, depths) {
	      var programWrapper = this.programs[i],
	          fn = this.fn(i);
	      if (data || depths || blockParams || declaredBlockParams) {
	        programWrapper = wrapProgram(this, i, fn, data, declaredBlockParams, blockParams, depths);
	      } else if (!programWrapper) {
	        programWrapper = this.programs[i] = wrapProgram(this, i, fn);
	      }
	      return programWrapper;
	    },

	    data: function data(value, depth) {
	      while (value && depth--) {
	        value = value._parent;
	      }
	      return value;
	    },
	    merge: function merge(param, common) {
	      var obj = param || common;

	      if (param && common && param !== common) {
	        obj = Utils.extend({}, common, param);
	      }

	      return obj;
	    },

	    noop: env.VM.noop,
	    compilerInfo: templateSpec.compiler
	  };

	  function ret(context) {
	    var options = arguments[1] === undefined ? {} : arguments[1];

	    var data = options.data;

	    ret._setup(options);
	    if (!options.partial && templateSpec.useData) {
	      data = initData(context, data);
	    }
	    var depths = undefined,
	        blockParams = templateSpec.useBlockParams ? [] : undefined;
	    if (templateSpec.useDepths) {
	      depths = options.depths ? [context].concat(options.depths) : [context];
	    }

	    return templateSpec.main.call(container, context, container.helpers, container.partials, data, blockParams, depths);
	  }
	  ret.isTop = true;

	  ret._setup = function (options) {
	    if (!options.partial) {
	      container.helpers = container.merge(options.helpers, env.helpers);

	      if (templateSpec.usePartial) {
	        container.partials = container.merge(options.partials, env.partials);
	      }
	    } else {
	      container.helpers = options.helpers;
	      container.partials = options.partials;
	    }
	  };

	  ret._child = function (i, data, blockParams, depths) {
	    if (templateSpec.useBlockParams && !blockParams) {
	      throw new _Exception2['default']('must pass block params');
	    }
	    if (templateSpec.useDepths && !depths) {
	      throw new _Exception2['default']('must pass parent depths');
	    }

	    return wrapProgram(container, i, templateSpec[i], data, 0, blockParams, depths);
	  };
	  return ret;
	}

	function wrapProgram(container, i, fn, data, declaredBlockParams, blockParams, depths) {
	  function prog(context) {
	    var options = arguments[1] === undefined ? {} : arguments[1];

	    return fn.call(container, context, container.helpers, container.partials, options.data || data, blockParams && [options.blockParams].concat(blockParams), depths && [context].concat(depths));
	  }
	  prog.program = i;
	  prog.depth = depths ? depths.length : 0;
	  prog.blockParams = declaredBlockParams || 0;
	  return prog;
	}

	function resolvePartial(partial, context, options) {
	  if (!partial) {
	    partial = options.partials[options.name];
	  } else if (!partial.call && !options.name) {
	    // This is a dynamic partial that returned a string
	    options.name = partial;
	    partial = options.partials[partial];
	  }
	  return partial;
	}

	function invokePartial(partial, context, options) {
	  options.partial = true;

	  if (partial === undefined) {
	    throw new _Exception2['default']('The partial ' + options.name + ' could not be found');
	  } else if (partial instanceof Function) {
	    return partial(context, options);
	  }
	}

	function noop() {
	  return '';
	}

	function initData(context, data) {
	  if (!data || !('root' in data)) {
	    data = data ? _COMPILER_REVISION$REVISION_CHANGES$createFrame.createFrame(data) : {};
	    data.root = context;
	  }
	  return data;
	}

/***/ },
/* 15 */
/***/ function(module, exports, __webpack_require__) {

	"use strict";

	exports.__esModule = true;
	/* istanbul ignore next */
	/* Jison generated parser */
	var handlebars = (function () {
	    var parser = { trace: function trace() {},
	        yy: {},
	        symbols_: { error: 2, root: 3, program: 4, EOF: 5, program_repetition0: 6, statement: 7, mustache: 8, block: 9, rawBlock: 10, partial: 11, content: 12, COMMENT: 13, CONTENT: 14, openRawBlock: 15, END_RAW_BLOCK: 16, OPEN_RAW_BLOCK: 17, helperName: 18, openRawBlock_repetition0: 19, openRawBlock_option0: 20, CLOSE_RAW_BLOCK: 21, openBlock: 22, block_option0: 23, closeBlock: 24, openInverse: 25, block_option1: 26, OPEN_BLOCK: 27, openBlock_repetition0: 28, openBlock_option0: 29, openBlock_option1: 30, CLOSE: 31, OPEN_INVERSE: 32, openInverse_repetition0: 33, openInverse_option0: 34, openInverse_option1: 35, openInverseChain: 36, OPEN_INVERSE_CHAIN: 37, openInverseChain_repetition0: 38, openInverseChain_option0: 39, openInverseChain_option1: 40, inverseAndProgram: 41, INVERSE: 42, inverseChain: 43, inverseChain_option0: 44, OPEN_ENDBLOCK: 45, OPEN: 46, mustache_repetition0: 47, mustache_option0: 48, OPEN_UNESCAPED: 49, mustache_repetition1: 50, mustache_option1: 51, CLOSE_UNESCAPED: 52, OPEN_PARTIAL: 53, partialName: 54, partial_repetition0: 55, partial_option0: 56, param: 57, sexpr: 58, OPEN_SEXPR: 59, sexpr_repetition0: 60, sexpr_option0: 61, CLOSE_SEXPR: 62, hash: 63, hash_repetition_plus0: 64, hashSegment: 65, ID: 66, EQUALS: 67, blockParams: 68, OPEN_BLOCK_PARAMS: 69, blockParams_repetition_plus0: 70, CLOSE_BLOCK_PARAMS: 71, path: 72, dataName: 73, STRING: 74, NUMBER: 75, BOOLEAN: 76, UNDEFINED: 77, NULL: 78, DATA: 79, pathSegments: 80, SEP: 81, $accept: 0, $end: 1 },
	        terminals_: { 2: "error", 5: "EOF", 13: "COMMENT", 14: "CONTENT", 16: "END_RAW_BLOCK", 17: "OPEN_RAW_BLOCK", 21: "CLOSE_RAW_BLOCK", 27: "OPEN_BLOCK", 31: "CLOSE", 32: "OPEN_INVERSE", 37: "OPEN_INVERSE_CHAIN", 42: "INVERSE", 45: "OPEN_ENDBLOCK", 46: "OPEN", 49: "OPEN_UNESCAPED", 52: "CLOSE_UNESCAPED", 53: "OPEN_PARTIAL", 59: "OPEN_SEXPR", 62: "CLOSE_SEXPR", 66: "ID", 67: "EQUALS", 69: "OPEN_BLOCK_PARAMS", 71: "CLOSE_BLOCK_PARAMS", 74: "STRING", 75: "NUMBER", 76: "BOOLEAN", 77: "UNDEFINED", 78: "NULL", 79: "DATA", 81: "SEP" },
	        productions_: [0, [3, 2], [4, 1], [7, 1], [7, 1], [7, 1], [7, 1], [7, 1], [7, 1], [12, 1], [10, 3], [15, 5], [9, 4], [9, 4], [22, 6], [25, 6], [36, 6], [41, 2], [43, 3], [43, 1], [24, 3], [8, 5], [8, 5], [11, 5], [57, 1], [57, 1], [58, 5], [63, 1], [65, 3], [68, 3], [18, 1], [18, 1], [18, 1], [18, 1], [18, 1], [18, 1], [18, 1], [54, 1], [54, 1], [73, 2], [72, 1], [80, 3], [80, 1], [6, 0], [6, 2], [19, 0], [19, 2], [20, 0], [20, 1], [23, 0], [23, 1], [26, 0], [26, 1], [28, 0], [28, 2], [29, 0], [29, 1], [30, 0], [30, 1], [33, 0], [33, 2], [34, 0], [34, 1], [35, 0], [35, 1], [38, 0], [38, 2], [39, 0], [39, 1], [40, 0], [40, 1], [44, 0], [44, 1], [47, 0], [47, 2], [48, 0], [48, 1], [50, 0], [50, 2], [51, 0], [51, 1], [55, 0], [55, 2], [56, 0], [56, 1], [60, 0], [60, 2], [61, 0], [61, 1], [64, 1], [64, 2], [70, 1], [70, 2]],
	        performAction: function anonymous(yytext, yyleng, yylineno, yy, yystate, $$, _$) {

	            var $0 = $$.length - 1;
	            switch (yystate) {
	                case 1:
	                    return $$[$0 - 1];
	                    break;
	                case 2:
	                    this.$ = new yy.Program($$[$0], null, {}, yy.locInfo(this._$));
	                    break;
	                case 3:
	                    this.$ = $$[$0];
	                    break;
	                case 4:
	                    this.$ = $$[$0];
	                    break;
	                case 5:
	                    this.$ = $$[$0];
	                    break;
	                case 6:
	                    this.$ = $$[$0];
	                    break;
	                case 7:
	                    this.$ = $$[$0];
	                    break;
	                case 8:
	                    this.$ = new yy.CommentStatement(yy.stripComment($$[$0]), yy.stripFlags($$[$0], $$[$0]), yy.locInfo(this._$));
	                    break;
	                case 9:
	                    this.$ = new yy.ContentStatement($$[$0], yy.locInfo(this._$));
	                    break;
	                case 10:
	                    this.$ = yy.prepareRawBlock($$[$0 - 2], $$[$0 - 1], $$[$0], this._$);
	                    break;
	                case 11:
	                    this.$ = { path: $$[$0 - 3], params: $$[$0 - 2], hash: $$[$0 - 1] };
	                    break;
	                case 12:
	                    this.$ = yy.prepareBlock($$[$0 - 3], $$[$0 - 2], $$[$0 - 1], $$[$0], false, this._$);
	                    break;
	                case 13:
	                    this.$ = yy.prepareBlock($$[$0 - 3], $$[$0 - 2], $$[$0 - 1], $$[$0], true, this._$);
	                    break;
	                case 14:
	                    this.$ = { path: $$[$0 - 4], params: $$[$0 - 3], hash: $$[$0 - 2], blockParams: $$[$0 - 1], strip: yy.stripFlags($$[$0 - 5], $$[$0]) };
	                    break;
	                case 15:
	                    this.$ = { path: $$[$0 - 4], params: $$[$0 - 3], hash: $$[$0 - 2], blockParams: $$[$0 - 1], strip: yy.stripFlags($$[$0 - 5], $$[$0]) };
	                    break;
	                case 16:
	                    this.$ = { path: $$[$0 - 4], params: $$[$0 - 3], hash: $$[$0 - 2], blockParams: $$[$0 - 1], strip: yy.stripFlags($$[$0 - 5], $$[$0]) };
	                    break;
	                case 17:
	                    this.$ = { strip: yy.stripFlags($$[$0 - 1], $$[$0 - 1]), program: $$[$0] };
	                    break;
	                case 18:
	                    var inverse = yy.prepareBlock($$[$0 - 2], $$[$0 - 1], $$[$0], $$[$0], false, this._$),
	                        program = new yy.Program([inverse], null, {}, yy.locInfo(this._$));
	                    program.chained = true;

	                    this.$ = { strip: $$[$0 - 2].strip, program: program, chain: true };

	                    break;
	                case 19:
	                    this.$ = $$[$0];
	                    break;
	                case 20:
	                    this.$ = { path: $$[$0 - 1], strip: yy.stripFlags($$[$0 - 2], $$[$0]) };
	                    break;
	                case 21:
	                    this.$ = yy.prepareMustache($$[$0 - 3], $$[$0 - 2], $$[$0 - 1], $$[$0 - 4], yy.stripFlags($$[$0 - 4], $$[$0]), this._$);
	                    break;
	                case 22:
	                    this.$ = yy.prepareMustache($$[$0 - 3], $$[$0 - 2], $$[$0 - 1], $$[$0 - 4], yy.stripFlags($$[$0 - 4], $$[$0]), this._$);
	                    break;
	                case 23:
	                    this.$ = new yy.PartialStatement($$[$0 - 3], $$[$0 - 2], $$[$0 - 1], yy.stripFlags($$[$0 - 4], $$[$0]), yy.locInfo(this._$));
	                    break;
	                case 24:
	                    this.$ = $$[$0];
	                    break;
	                case 25:
	                    this.$ = $$[$0];
	                    break;
	                case 26:
	                    this.$ = new yy.SubExpression($$[$0 - 3], $$[$0 - 2], $$[$0 - 1], yy.locInfo(this._$));
	                    break;
	                case 27:
	                    this.$ = new yy.Hash($$[$0], yy.locInfo(this._$));
	                    break;
	                case 28:
	                    this.$ = new yy.HashPair(yy.id($$[$0 - 2]), $$[$0], yy.locInfo(this._$));
	                    break;
	                case 29:
	                    this.$ = yy.id($$[$0 - 1]);
	                    break;
	                case 30:
	                    this.$ = $$[$0];
	                    break;
	                case 31:
	                    this.$ = $$[$0];
	                    break;
	                case 32:
	                    this.$ = new yy.StringLiteral($$[$0], yy.locInfo(this._$));
	                    break;
	                case 33:
	                    this.$ = new yy.NumberLiteral($$[$0], yy.locInfo(this._$));
	                    break;
	                case 34:
	                    this.$ = new yy.BooleanLiteral($$[$0], yy.locInfo(this._$));
	                    break;
	                case 35:
	                    this.$ = new yy.UndefinedLiteral(yy.locInfo(this._$));
	                    break;
	                case 36:
	                    this.$ = new yy.NullLiteral(yy.locInfo(this._$));
	                    break;
	                case 37:
	                    this.$ = $$[$0];
	                    break;
	                case 38:
	                    this.$ = $$[$0];
	                    break;
	                case 39:
	                    this.$ = yy.preparePath(true, $$[$0], this._$);
	                    break;
	                case 40:
	                    this.$ = yy.preparePath(false, $$[$0], this._$);
	                    break;
	                case 41:
	                    $$[$0 - 2].push({ part: yy.id($$[$0]), original: $$[$0], separator: $$[$0 - 1] });this.$ = $$[$0 - 2];
	                    break;
	                case 42:
	                    this.$ = [{ part: yy.id($$[$0]), original: $$[$0] }];
	                    break;
	                case 43:
	                    this.$ = [];
	                    break;
	                case 44:
	                    $$[$0 - 1].push($$[$0]);
	                    break;
	                case 45:
	                    this.$ = [];
	                    break;
	                case 46:
	                    $$[$0 - 1].push($$[$0]);
	                    break;
	                case 53:
	                    this.$ = [];
	                    break;
	                case 54:
	                    $$[$0 - 1].push($$[$0]);
	                    break;
	                case 59:
	                    this.$ = [];
	                    break;
	                case 60:
	                    $$[$0 - 1].push($$[$0]);
	                    break;
	                case 65:
	                    this.$ = [];
	                    break;
	                case 66:
	                    $$[$0 - 1].push($$[$0]);
	                    break;
	                case 73:
	                    this.$ = [];
	                    break;
	                case 74:
	                    $$[$0 - 1].push($$[$0]);
	                    break;
	                case 77:
	                    this.$ = [];
	                    break;
	                case 78:
	                    $$[$0 - 1].push($$[$0]);
	                    break;
	                case 81:
	                    this.$ = [];
	                    break;
	                case 82:
	                    $$[$0 - 1].push($$[$0]);
	                    break;
	                case 85:
	                    this.$ = [];
	                    break;
	                case 86:
	                    $$[$0 - 1].push($$[$0]);
	                    break;
	                case 89:
	                    this.$ = [$$[$0]];
	                    break;
	                case 90:
	                    $$[$0 - 1].push($$[$0]);
	                    break;
	                case 91:
	                    this.$ = [$$[$0]];
	                    break;
	                case 92:
	                    $$[$0 - 1].push($$[$0]);
	                    break;
	            }
	        },
	        table: [{ 3: 1, 4: 2, 5: [2, 43], 6: 3, 13: [2, 43], 14: [2, 43], 17: [2, 43], 27: [2, 43], 32: [2, 43], 46: [2, 43], 49: [2, 43], 53: [2, 43] }, { 1: [3] }, { 5: [1, 4] }, { 5: [2, 2], 7: 5, 8: 6, 9: 7, 10: 8, 11: 9, 12: 10, 13: [1, 11], 14: [1, 18], 15: 16, 17: [1, 21], 22: 14, 25: 15, 27: [1, 19], 32: [1, 20], 37: [2, 2], 42: [2, 2], 45: [2, 2], 46: [1, 12], 49: [1, 13], 53: [1, 17] }, { 1: [2, 1] }, { 5: [2, 44], 13: [2, 44], 14: [2, 44], 17: [2, 44], 27: [2, 44], 32: [2, 44], 37: [2, 44], 42: [2, 44], 45: [2, 44], 46: [2, 44], 49: [2, 44], 53: [2, 44] }, { 5: [2, 3], 13: [2, 3], 14: [2, 3], 17: [2, 3], 27: [2, 3], 32: [2, 3], 37: [2, 3], 42: [2, 3], 45: [2, 3], 46: [2, 3], 49: [2, 3], 53: [2, 3] }, { 5: [2, 4], 13: [2, 4], 14: [2, 4], 17: [2, 4], 27: [2, 4], 32: [2, 4], 37: [2, 4], 42: [2, 4], 45: [2, 4], 46: [2, 4], 49: [2, 4], 53: [2, 4] }, { 5: [2, 5], 13: [2, 5], 14: [2, 5], 17: [2, 5], 27: [2, 5], 32: [2, 5], 37: [2, 5], 42: [2, 5], 45: [2, 5], 46: [2, 5], 49: [2, 5], 53: [2, 5] }, { 5: [2, 6], 13: [2, 6], 14: [2, 6], 17: [2, 6], 27: [2, 6], 32: [2, 6], 37: [2, 6], 42: [2, 6], 45: [2, 6], 46: [2, 6], 49: [2, 6], 53: [2, 6] }, { 5: [2, 7], 13: [2, 7], 14: [2, 7], 17: [2, 7], 27: [2, 7], 32: [2, 7], 37: [2, 7], 42: [2, 7], 45: [2, 7], 46: [2, 7], 49: [2, 7], 53: [2, 7] }, { 5: [2, 8], 13: [2, 8], 14: [2, 8], 17: [2, 8], 27: [2, 8], 32: [2, 8], 37: [2, 8], 42: [2, 8], 45: [2, 8], 46: [2, 8], 49: [2, 8], 53: [2, 8] }, { 18: 22, 66: [1, 32], 72: 23, 73: 24, 74: [1, 25], 75: [1, 26], 76: [1, 27], 77: [1, 28], 78: [1, 29], 79: [1, 31], 80: 30 }, { 18: 33, 66: [1, 32], 72: 23, 73: 24, 74: [1, 25], 75: [1, 26], 76: [1, 27], 77: [1, 28], 78: [1, 29], 79: [1, 31], 80: 30 }, { 4: 34, 6: 3, 13: [2, 43], 14: [2, 43], 17: [2, 43], 27: [2, 43], 32: [2, 43], 37: [2, 43], 42: [2, 43], 45: [2, 43], 46: [2, 43], 49: [2, 43], 53: [2, 43] }, { 4: 35, 6: 3, 13: [2, 43], 14: [2, 43], 17: [2, 43], 27: [2, 43], 32: [2, 43], 42: [2, 43], 45: [2, 43], 46: [2, 43], 49: [2, 43], 53: [2, 43] }, { 12: 36, 14: [1, 18] }, { 18: 38, 54: 37, 58: 39, 59: [1, 40], 66: [1, 32], 72: 23, 73: 24, 74: [1, 25], 75: [1, 26], 76: [1, 27], 77: [1, 28], 78: [1, 29], 79: [1, 31], 80: 30 }, { 5: [2, 9], 13: [2, 9], 14: [2, 9], 16: [2, 9], 17: [2, 9], 27: [2, 9], 32: [2, 9], 37: [2, 9], 42: [2, 9], 45: [2, 9], 46: [2, 9], 49: [2, 9], 53: [2, 9] }, { 18: 41, 66: [1, 32], 72: 23, 73: 24, 74: [1, 25], 75: [1, 26], 76: [1, 27], 77: [1, 28], 78: [1, 29], 79: [1, 31], 80: 30 }, { 18: 42, 66: [1, 32], 72: 23, 73: 24, 74: [1, 25], 75: [1, 26], 76: [1, 27], 77: [1, 28], 78: [1, 29], 79: [1, 31], 80: 30 }, { 18: 43, 66: [1, 32], 72: 23, 73: 24, 74: [1, 25], 75: [1, 26], 76: [1, 27], 77: [1, 28], 78: [1, 29], 79: [1, 31], 80: 30 }, { 31: [2, 73], 47: 44, 59: [2, 73], 66: [2, 73], 74: [2, 73], 75: [2, 73], 76: [2, 73], 77: [2, 73], 78: [2, 73], 79: [2, 73] }, { 21: [2, 30], 31: [2, 30], 52: [2, 30], 59: [2, 30], 62: [2, 30], 66: [2, 30], 69: [2, 30], 74: [2, 30], 75: [2, 30], 76: [2, 30], 77: [2, 30], 78: [2, 30], 79: [2, 30] }, { 21: [2, 31], 31: [2, 31], 52: [2, 31], 59: [2, 31], 62: [2, 31], 66: [2, 31], 69: [2, 31], 74: [2, 31], 75: [2, 31], 76: [2, 31], 77: [2, 31], 78: [2, 31], 79: [2, 31] }, { 21: [2, 32], 31: [2, 32], 52: [2, 32], 59: [2, 32], 62: [2, 32], 66: [2, 32], 69: [2, 32], 74: [2, 32], 75: [2, 32], 76: [2, 32], 77: [2, 32], 78: [2, 32], 79: [2, 32] }, { 21: [2, 33], 31: [2, 33], 52: [2, 33], 59: [2, 33], 62: [2, 33], 66: [2, 33], 69: [2, 33], 74: [2, 33], 75: [2, 33], 76: [2, 33], 77: [2, 33], 78: [2, 33], 79: [2, 33] }, { 21: [2, 34], 31: [2, 34], 52: [2, 34], 59: [2, 34], 62: [2, 34], 66: [2, 34], 69: [2, 34], 74: [2, 34], 75: [2, 34], 76: [2, 34], 77: [2, 34], 78: [2, 34], 79: [2, 34] }, { 21: [2, 35], 31: [2, 35], 52: [2, 35], 59: [2, 35], 62: [2, 35], 66: [2, 35], 69: [2, 35], 74: [2, 35], 75: [2, 35], 76: [2, 35], 77: [2, 35], 78: [2, 35], 79: [2, 35] }, { 21: [2, 36], 31: [2, 36], 52: [2, 36], 59: [2, 36], 62: [2, 36], 66: [2, 36], 69: [2, 36], 74: [2, 36], 75: [2, 36], 76: [2, 36], 77: [2, 36], 78: [2, 36], 79: [2, 36] }, { 21: [2, 40], 31: [2, 40], 52: [2, 40], 59: [2, 40], 62: [2, 40], 66: [2, 40], 69: [2, 40], 74: [2, 40], 75: [2, 40], 76: [2, 40], 77: [2, 40], 78: [2, 40], 79: [2, 40], 81: [1, 45] }, { 66: [1, 32], 80: 46 }, { 21: [2, 42], 31: [2, 42], 52: [2, 42], 59: [2, 42], 62: [2, 42], 66: [2, 42], 69: [2, 42], 74: [2, 42], 75: [2, 42], 76: [2, 42], 77: [2, 42], 78: [2, 42], 79: [2, 42], 81: [2, 42] }, { 50: 47, 52: [2, 77], 59: [2, 77], 66: [2, 77], 74: [2, 77], 75: [2, 77], 76: [2, 77], 77: [2, 77], 78: [2, 77], 79: [2, 77] }, { 23: 48, 36: 50, 37: [1, 52], 41: 51, 42: [1, 53], 43: 49, 45: [2, 49] }, { 26: 54, 41: 55, 42: [1, 53], 45: [2, 51] }, { 16: [1, 56] }, { 31: [2, 81], 55: 57, 59: [2, 81], 66: [2, 81], 74: [2, 81], 75: [2, 81], 76: [2, 81], 77: [2, 81], 78: [2, 81], 79: [2, 81] }, { 31: [2, 37], 59: [2, 37], 66: [2, 37], 74: [2, 37], 75: [2, 37], 76: [2, 37], 77: [2, 37], 78: [2, 37], 79: [2, 37] }, { 31: [2, 38], 59: [2, 38], 66: [2, 38], 74: [2, 38], 75: [2, 38], 76: [2, 38], 77: [2, 38], 78: [2, 38], 79: [2, 38] }, { 18: 58, 66: [1, 32], 72: 23, 73: 24, 74: [1, 25], 75: [1, 26], 76: [1, 27], 77: [1, 28], 78: [1, 29], 79: [1, 31], 80: 30 }, { 28: 59, 31: [2, 53], 59: [2, 53], 66: [2, 53], 69: [2, 53], 74: [2, 53], 75: [2, 53], 76: [2, 53], 77: [2, 53], 78: [2, 53], 79: [2, 53] }, { 31: [2, 59], 33: 60, 59: [2, 59], 66: [2, 59], 69: [2, 59], 74: [2, 59], 75: [2, 59], 76: [2, 59], 77: [2, 59], 78: [2, 59], 79: [2, 59] }, { 19: 61, 21: [2, 45], 59: [2, 45], 66: [2, 45], 74: [2, 45], 75: [2, 45], 76: [2, 45], 77: [2, 45], 78: [2, 45], 79: [2, 45] }, { 18: 65, 31: [2, 75], 48: 62, 57: 63, 58: 66, 59: [1, 40], 63: 64, 64: 67, 65: 68, 66: [1, 69], 72: 23, 73: 24, 74: [1, 25], 75: [1, 26], 76: [1, 27], 77: [1, 28], 78: [1, 29], 79: [1, 31], 80: 30 }, { 66: [1, 70] }, { 21: [2, 39], 31: [2, 39], 52: [2, 39], 59: [2, 39], 62: [2, 39], 66: [2, 39], 69: [2, 39], 74: [2, 39], 75: [2, 39], 76: [2, 39], 77: [2, 39], 78: [2, 39], 79: [2, 39], 81: [1, 45] }, { 18: 65, 51: 71, 52: [2, 79], 57: 72, 58: 66, 59: [1, 40], 63: 73, 64: 67, 65: 68, 66: [1, 69], 72: 23, 73: 24, 74: [1, 25], 75: [1, 26], 76: [1, 27], 77: [1, 28], 78: [1, 29], 79: [1, 31], 80: 30 }, { 24: 74, 45: [1, 75] }, { 45: [2, 50] }, { 4: 76, 6: 3, 13: [2, 43], 14: [2, 43], 17: [2, 43], 27: [2, 43], 32: [2, 43], 37: [2, 43], 42: [2, 43], 45: [2, 43], 46: [2, 43], 49: [2, 43], 53: [2, 43] }, { 45: [2, 19] }, { 18: 77, 66: [1, 32], 72: 23, 73: 24, 74: [1, 25], 75: [1, 26], 76: [1, 27], 77: [1, 28], 78: [1, 29], 79: [1, 31], 80: 30 }, { 4: 78, 6: 3, 13: [2, 43], 14: [2, 43], 17: [2, 43], 27: [2, 43], 32: [2, 43], 45: [2, 43], 46: [2, 43], 49: [2, 43], 53: [2, 43] }, { 24: 79, 45: [1, 75] }, { 45: [2, 52] }, { 5: [2, 10], 13: [2, 10], 14: [2, 10], 17: [2, 10], 27: [2, 10], 32: [2, 10], 37: [2, 10], 42: [2, 10], 45: [2, 10], 46: [2, 10], 49: [2, 10], 53: [2, 10] }, { 18: 65, 31: [2, 83], 56: 80, 57: 81, 58: 66, 59: [1, 40], 63: 82, 64: 67, 65: 68, 66: [1, 69], 72: 23, 73: 24, 74: [1, 25], 75: [1, 26], 76: [1, 27], 77: [1, 28], 78: [1, 29], 79: [1, 31], 80: 30 }, { 59: [2, 85], 60: 83, 62: [2, 85], 66: [2, 85], 74: [2, 85], 75: [2, 85], 76: [2, 85], 77: [2, 85], 78: [2, 85], 79: [2, 85] }, { 18: 65, 29: 84, 31: [2, 55], 57: 85, 58: 66, 59: [1, 40], 63: 86, 64: 67, 65: 68, 66: [1, 69], 69: [2, 55], 72: 23, 73: 24, 74: [1, 25], 75: [1, 26], 76: [1, 27], 77: [1, 28], 78: [1, 29], 79: [1, 31], 80: 30 }, { 18: 65, 31: [2, 61], 34: 87, 57: 88, 58: 66, 59: [1, 40], 63: 89, 64: 67, 65: 68, 66: [1, 69], 69: [2, 61], 72: 23, 73: 24, 74: [1, 25], 75: [1, 26], 76: [1, 27], 77: [1, 28], 78: [1, 29], 79: [1, 31], 80: 30 }, { 18: 65, 20: 90, 21: [2, 47], 57: 91, 58: 66, 59: [1, 40], 63: 92, 64: 67, 65: 68, 66: [1, 69], 72: 23, 73: 24, 74: [1, 25], 75: [1, 26], 76: [1, 27], 77: [1, 28], 78: [1, 29], 79: [1, 31], 80: 30 }, { 31: [1, 93] }, { 31: [2, 74], 59: [2, 74], 66: [2, 74], 74: [2, 74], 75: [2, 74], 76: [2, 74], 77: [2, 74], 78: [2, 74], 79: [2, 74] }, { 31: [2, 76] }, { 21: [2, 24], 31: [2, 24], 52: [2, 24], 59: [2, 24], 62: [2, 24], 66: [2, 24], 69: [2, 24], 74: [2, 24], 75: [2, 24], 76: [2, 24], 77: [2, 24], 78: [2, 24], 79: [2, 24] }, { 21: [2, 25], 31: [2, 25], 52: [2, 25], 59: [2, 25], 62: [2, 25], 66: [2, 25], 69: [2, 25], 74: [2, 25], 75: [2, 25], 76: [2, 25], 77: [2, 25], 78: [2, 25], 79: [2, 25] }, { 21: [2, 27], 31: [2, 27], 52: [2, 27], 62: [2, 27], 65: 94, 66: [1, 95], 69: [2, 27] }, { 21: [2, 89], 31: [2, 89], 52: [2, 89], 62: [2, 89], 66: [2, 89], 69: [2, 89] }, { 21: [2, 42], 31: [2, 42], 52: [2, 42], 59: [2, 42], 62: [2, 42], 66: [2, 42], 67: [1, 96], 69: [2, 42], 74: [2, 42], 75: [2, 42], 76: [2, 42], 77: [2, 42], 78: [2, 42], 79: [2, 42], 81: [2, 42] }, { 21: [2, 41], 31: [2, 41], 52: [2, 41], 59: [2, 41], 62: [2, 41], 66: [2, 41], 69: [2, 41], 74: [2, 41], 75: [2, 41], 76: [2, 41], 77: [2, 41], 78: [2, 41], 79: [2, 41], 81: [2, 41] }, { 52: [1, 97] }, { 52: [2, 78], 59: [2, 78], 66: [2, 78], 74: [2, 78], 75: [2, 78], 76: [2, 78], 77: [2, 78], 78: [2, 78], 79: [2, 78] }, { 52: [2, 80] }, { 5: [2, 12], 13: [2, 12], 14: [2, 12], 17: [2, 12], 27: [2, 12], 32: [2, 12], 37: [2, 12], 42: [2, 12], 45: [2, 12], 46: [2, 12], 49: [2, 12], 53: [2, 12] }, { 18: 98, 66: [1, 32], 72: 23, 73: 24, 74: [1, 25], 75: [1, 26], 76: [1, 27], 77: [1, 28], 78: [1, 29], 79: [1, 31], 80: 30 }, { 36: 50, 37: [1, 52], 41: 51, 42: [1, 53], 43: 100, 44: 99, 45: [2, 71] }, { 31: [2, 65], 38: 101, 59: [2, 65], 66: [2, 65], 69: [2, 65], 74: [2, 65], 75: [2, 65], 76: [2, 65], 77: [2, 65], 78: [2, 65], 79: [2, 65] }, { 45: [2, 17] }, { 5: [2, 13], 13: [2, 13], 14: [2, 13], 17: [2, 13], 27: [2, 13], 32: [2, 13], 37: [2, 13], 42: [2, 13], 45: [2, 13], 46: [2, 13], 49: [2, 13], 53: [2, 13] }, { 31: [1, 102] }, { 31: [2, 82], 59: [2, 82], 66: [2, 82], 74: [2, 82], 75: [2, 82], 76: [2, 82], 77: [2, 82], 78: [2, 82], 79: [2, 82] }, { 31: [2, 84] }, { 18: 65, 57: 104, 58: 66, 59: [1, 40], 61: 103, 62: [2, 87], 63: 105, 64: 67, 65: 68, 66: [1, 69], 72: 23, 73: 24, 74: [1, 25], 75: [1, 26], 76: [1, 27], 77: [1, 28], 78: [1, 29], 79: [1, 31], 80: 30 }, { 30: 106, 31: [2, 57], 68: 107, 69: [1, 108] }, { 31: [2, 54], 59: [2, 54], 66: [2, 54], 69: [2, 54], 74: [2, 54], 75: [2, 54], 76: [2, 54], 77: [2, 54], 78: [2, 54], 79: [2, 54] }, { 31: [2, 56], 69: [2, 56] }, { 31: [2, 63], 35: 109, 68: 110, 69: [1, 108] }, { 31: [2, 60], 59: [2, 60], 66: [2, 60], 69: [2, 60], 74: [2, 60], 75: [2, 60], 76: [2, 60], 77: [2, 60], 78: [2, 60], 79: [2, 60] }, { 31: [2, 62], 69: [2, 62] }, { 21: [1, 111] }, { 21: [2, 46], 59: [2, 46], 66: [2, 46], 74: [2, 46], 75: [2, 46], 76: [2, 46], 77: [2, 46], 78: [2, 46], 79: [2, 46] }, { 21: [2, 48] }, { 5: [2, 21], 13: [2, 21], 14: [2, 21], 17: [2, 21], 27: [2, 21], 32: [2, 21], 37: [2, 21], 42: [2, 21], 45: [2, 21], 46: [2, 21], 49: [2, 21], 53: [2, 21] }, { 21: [2, 90], 31: [2, 90], 52: [2, 90], 62: [2, 90], 66: [2, 90], 69: [2, 90] }, { 67: [1, 96] }, { 18: 65, 57: 112, 58: 66, 59: [1, 40], 66: [1, 32], 72: 23, 73: 24, 74: [1, 25], 75: [1, 26], 76: [1, 27], 77: [1, 28], 78: [1, 29], 79: [1, 31], 80: 30 }, { 5: [2, 22], 13: [2, 22], 14: [2, 22], 17: [2, 22], 27: [2, 22], 32: [2, 22], 37: [2, 22], 42: [2, 22], 45: [2, 22], 46: [2, 22], 49: [2, 22], 53: [2, 22] }, { 31: [1, 113] }, { 45: [2, 18] }, { 45: [2, 72] }, { 18: 65, 31: [2, 67], 39: 114, 57: 115, 58: 66, 59: [1, 40], 63: 116, 64: 67, 65: 68, 66: [1, 69], 69: [2, 67], 72: 23, 73: 24, 74: [1, 25], 75: [1, 26], 76: [1, 27], 77: [1, 28], 78: [1, 29], 79: [1, 31], 80: 30 }, { 5: [2, 23], 13: [2, 23], 14: [2, 23], 17: [2, 23], 27: [2, 23], 32: [2, 23], 37: [2, 23], 42: [2, 23], 45: [2, 23], 46: [2, 23], 49: [2, 23], 53: [2, 23] }, { 62: [1, 117] }, { 59: [2, 86], 62: [2, 86], 66: [2, 86], 74: [2, 86], 75: [2, 86], 76: [2, 86], 77: [2, 86], 78: [2, 86], 79: [2, 86] }, { 62: [2, 88] }, { 31: [1, 118] }, { 31: [2, 58] }, { 66: [1, 120], 70: 119 }, { 31: [1, 121] }, { 31: [2, 64] }, { 14: [2, 11] }, { 21: [2, 28], 31: [2, 28], 52: [2, 28], 62: [2, 28], 66: [2, 28], 69: [2, 28] }, { 5: [2, 20], 13: [2, 20], 14: [2, 20], 17: [2, 20], 27: [2, 20], 32: [2, 20], 37: [2, 20], 42: [2, 20], 45: [2, 20], 46: [2, 20], 49: [2, 20], 53: [2, 20] }, { 31: [2, 69], 40: 122, 68: 123, 69: [1, 108] }, { 31: [2, 66], 59: [2, 66], 66: [2, 66], 69: [2, 66], 74: [2, 66], 75: [2, 66], 76: [2, 66], 77: [2, 66], 78: [2, 66], 79: [2, 66] }, { 31: [2, 68], 69: [2, 68] }, { 21: [2, 26], 31: [2, 26], 52: [2, 26], 59: [2, 26], 62: [2, 26], 66: [2, 26], 69: [2, 26], 74: [2, 26], 75: [2, 26], 76: [2, 26], 77: [2, 26], 78: [2, 26], 79: [2, 26] }, { 13: [2, 14], 14: [2, 14], 17: [2, 14], 27: [2, 14], 32: [2, 14], 37: [2, 14], 42: [2, 14], 45: [2, 14], 46: [2, 14], 49: [2, 14], 53: [2, 14] }, { 66: [1, 125], 71: [1, 124] }, { 66: [2, 91], 71: [2, 91] }, { 13: [2, 15], 14: [2, 15], 17: [2, 15], 27: [2, 15], 32: [2, 15], 42: [2, 15], 45: [2, 15], 46: [2, 15], 49: [2, 15], 53: [2, 15] }, { 31: [1, 126] }, { 31: [2, 70] }, { 31: [2, 29] }, { 66: [2, 92], 71: [2, 92] }, { 13: [2, 16], 14: [2, 16], 17: [2, 16], 27: [2, 16], 32: [2, 16], 37: [2, 16], 42: [2, 16], 45: [2, 16], 46: [2, 16], 49: [2, 16], 53: [2, 16] }],
	        defaultActions: { 4: [2, 1], 49: [2, 50], 51: [2, 19], 55: [2, 52], 64: [2, 76], 73: [2, 80], 78: [2, 17], 82: [2, 84], 92: [2, 48], 99: [2, 18], 100: [2, 72], 105: [2, 88], 107: [2, 58], 110: [2, 64], 111: [2, 11], 123: [2, 70], 124: [2, 29] },
	        parseError: function parseError(str, hash) {
	            throw new Error(str);
	        },
	        parse: function parse(input) {
	            var self = this,
	                stack = [0],
	                vstack = [null],
	                lstack = [],
	                table = this.table,
	                yytext = "",
	                yylineno = 0,
	                yyleng = 0,
	                recovering = 0,
	                TERROR = 2,
	                EOF = 1;
	            this.lexer.setInput(input);
	            this.lexer.yy = this.yy;
	            this.yy.lexer = this.lexer;
	            this.yy.parser = this;
	            if (typeof this.lexer.yylloc == "undefined") this.lexer.yylloc = {};
	            var yyloc = this.lexer.yylloc;
	            lstack.push(yyloc);
	            var ranges = this.lexer.options && this.lexer.options.ranges;
	            if (typeof this.yy.parseError === "function") this.parseError = this.yy.parseError;
	            function popStack(n) {
	                stack.length = stack.length - 2 * n;
	                vstack.length = vstack.length - n;
	                lstack.length = lstack.length - n;
	            }
	            function lex() {
	                var token;
	                token = self.lexer.lex() || 1;
	                if (typeof token !== "number") {
	                    token = self.symbols_[token] || token;
	                }
	                return token;
	            }
	            var symbol,
	                preErrorSymbol,
	                state,
	                action,
	                a,
	                r,
	                yyval = {},
	                p,
	                len,
	                newState,
	                expected;
	            while (true) {
	                state = stack[stack.length - 1];
	                if (this.defaultActions[state]) {
	                    action = this.defaultActions[state];
	                } else {
	                    if (symbol === null || typeof symbol == "undefined") {
	                        symbol = lex();
	                    }
	                    action = table[state] && table[state][symbol];
	                }
	                if (typeof action === "undefined" || !action.length || !action[0]) {
	                    var errStr = "";
	                    if (!recovering) {
	                        expected = [];
	                        for (p in table[state]) if (this.terminals_[p] && p > 2) {
	                            expected.push("'" + this.terminals_[p] + "'");
	                        }
	                        if (this.lexer.showPosition) {
	                            errStr = "Parse error on line " + (yylineno + 1) + ":\n" + this.lexer.showPosition() + "\nExpecting " + expected.join(", ") + ", got '" + (this.terminals_[symbol] || symbol) + "'";
	                        } else {
	                            errStr = "Parse error on line " + (yylineno + 1) + ": Unexpected " + (symbol == 1 ? "end of input" : "'" + (this.terminals_[symbol] || symbol) + "'");
	                        }
	                        this.parseError(errStr, { text: this.lexer.match, token: this.terminals_[symbol] || symbol, line: this.lexer.yylineno, loc: yyloc, expected: expected });
	                    }
	                }
	                if (action[0] instanceof Array && action.length > 1) {
	                    throw new Error("Parse Error: multiple actions possible at state: " + state + ", token: " + symbol);
	                }
	                switch (action[0]) {
	                    case 1:
	                        stack.push(symbol);
	                        vstack.push(this.lexer.yytext);
	                        lstack.push(this.lexer.yylloc);
	                        stack.push(action[1]);
	                        symbol = null;
	                        if (!preErrorSymbol) {
	                            yyleng = this.lexer.yyleng;
	                            yytext = this.lexer.yytext;
	                            yylineno = this.lexer.yylineno;
	                            yyloc = this.lexer.yylloc;
	                            if (recovering > 0) recovering--;
	                        } else {
	                            symbol = preErrorSymbol;
	                            preErrorSymbol = null;
	                        }
	                        break;
	                    case 2:
	                        len = this.productions_[action[1]][1];
	                        yyval.$ = vstack[vstack.length - len];
	                        yyval._$ = { first_line: lstack[lstack.length - (len || 1)].first_line, last_line: lstack[lstack.length - 1].last_line, first_column: lstack[lstack.length - (len || 1)].first_column, last_column: lstack[lstack.length - 1].last_column };
	                        if (ranges) {
	                            yyval._$.range = [lstack[lstack.length - (len || 1)].range[0], lstack[lstack.length - 1].range[1]];
	                        }
	                        r = this.performAction.call(yyval, yytext, yyleng, yylineno, this.yy, action[1], vstack, lstack);
	                        if (typeof r !== "undefined") {
	                            return r;
	                        }
	                        if (len) {
	                            stack = stack.slice(0, -1 * len * 2);
	                            vstack = vstack.slice(0, -1 * len);
	                            lstack = lstack.slice(0, -1 * len);
	                        }
	                        stack.push(this.productions_[action[1]][0]);
	                        vstack.push(yyval.$);
	                        lstack.push(yyval._$);
	                        newState = table[stack[stack.length - 2]][stack[stack.length - 1]];
	                        stack.push(newState);
	                        break;
	                    case 3:
	                        return true;
	                }
	            }
	            return true;
	        }
	    };
	    /* Jison generated lexer */
	    var lexer = (function () {
	        var lexer = { EOF: 1,
	            parseError: function parseError(str, hash) {
	                if (this.yy.parser) {
	                    this.yy.parser.parseError(str, hash);
	                } else {
	                    throw new Error(str);
	                }
	            },
	            setInput: function setInput(input) {
	                this._input = input;
	                this._more = this._less = this.done = false;
	                this.yylineno = this.yyleng = 0;
	                this.yytext = this.matched = this.match = "";
	                this.conditionStack = ["INITIAL"];
	                this.yylloc = { first_line: 1, first_column: 0, last_line: 1, last_column: 0 };
	                if (this.options.ranges) this.yylloc.range = [0, 0];
	                this.offset = 0;
	                return this;
	            },
	            input: function input() {
	                var ch = this._input[0];
	                this.yytext += ch;
	                this.yyleng++;
	                this.offset++;
	                this.match += ch;
	                this.matched += ch;
	                var lines = ch.match(/(?:\r\n?|\n).*/g);
	                if (lines) {
	                    this.yylineno++;
	                    this.yylloc.last_line++;
	                } else {
	                    this.yylloc.last_column++;
	                }
	                if (this.options.ranges) this.yylloc.range[1]++;

	                this._input = this._input.slice(1);
	                return ch;
	            },
	            unput: function unput(ch) {
	                var len = ch.length;
	                var lines = ch.split(/(?:\r\n?|\n)/g);

	                this._input = ch + this._input;
	                this.yytext = this.yytext.substr(0, this.yytext.length - len - 1);
	                //this.yyleng -= len;
	                this.offset -= len;
	                var oldLines = this.match.split(/(?:\r\n?|\n)/g);
	                this.match = this.match.substr(0, this.match.length - 1);
	                this.matched = this.matched.substr(0, this.matched.length - 1);

	                if (lines.length - 1) this.yylineno -= lines.length - 1;
	                var r = this.yylloc.range;

	                this.yylloc = { first_line: this.yylloc.first_line,
	                    last_line: this.yylineno + 1,
	                    first_column: this.yylloc.first_column,
	                    last_column: lines ? (lines.length === oldLines.length ? this.yylloc.first_column : 0) + oldLines[oldLines.length - lines.length].length - lines[0].length : this.yylloc.first_column - len
	                };

	                if (this.options.ranges) {
	                    this.yylloc.range = [r[0], r[0] + this.yyleng - len];
	                }
	                return this;
	            },
	            more: function more() {
	                this._more = true;
	                return this;
	            },
	            less: function less(n) {
	                this.unput(this.match.slice(n));
	            },
	            pastInput: function pastInput() {
	                var past = this.matched.substr(0, this.matched.length - this.match.length);
	                return (past.length > 20 ? "..." : "") + past.substr(-20).replace(/\n/g, "");
	            },
	            upcomingInput: function upcomingInput() {
	                var next = this.match;
	                if (next.length < 20) {
	                    next += this._input.substr(0, 20 - next.length);
	                }
	                return (next.substr(0, 20) + (next.length > 20 ? "..." : "")).replace(/\n/g, "");
	            },
	            showPosition: function showPosition() {
	                var pre = this.pastInput();
	                var c = new Array(pre.length + 1).join("-");
	                return pre + this.upcomingInput() + "\n" + c + "^";
	            },
	            next: function next() {
	                if (this.done) {
	                    return this.EOF;
	                }
	                if (!this._input) this.done = true;

	                var token, match, tempMatch, index, col, lines;
	                if (!this._more) {
	                    this.yytext = "";
	                    this.match = "";
	                }
	                var rules = this._currentRules();
	                for (var i = 0; i < rules.length; i++) {
	                    tempMatch = this._input.match(this.rules[rules[i]]);
	                    if (tempMatch && (!match || tempMatch[0].length > match[0].length)) {
	                        match = tempMatch;
	                        index = i;
	                        if (!this.options.flex) break;
	                    }
	                }
	                if (match) {
	                    lines = match[0].match(/(?:\r\n?|\n).*/g);
	                    if (lines) this.yylineno += lines.length;
	                    this.yylloc = { first_line: this.yylloc.last_line,
	                        last_line: this.yylineno + 1,
	                        first_column: this.yylloc.last_column,
	                        last_column: lines ? lines[lines.length - 1].length - lines[lines.length - 1].match(/\r?\n?/)[0].length : this.yylloc.last_column + match[0].length };
	                    this.yytext += match[0];
	                    this.match += match[0];
	                    this.matches = match;
	                    this.yyleng = this.yytext.length;
	                    if (this.options.ranges) {
	                        this.yylloc.range = [this.offset, this.offset += this.yyleng];
	                    }
	                    this._more = false;
	                    this._input = this._input.slice(match[0].length);
	                    this.matched += match[0];
	                    token = this.performAction.call(this, this.yy, this, rules[index], this.conditionStack[this.conditionStack.length - 1]);
	                    if (this.done && this._input) this.done = false;
	                    if (token) {
	                        return token;
	                    } else {
	                        return;
	                    }
	                }
	                if (this._input === "") {
	                    return this.EOF;
	                } else {
	                    return this.parseError("Lexical error on line " + (this.yylineno + 1) + ". Unrecognized text.\n" + this.showPosition(), { text: "", token: null, line: this.yylineno });
	                }
	            },
	            lex: function lex() {
	                var r = this.next();
	                if (typeof r !== "undefined") {
	                    return r;
	                } else {
	                    return this.lex();
	                }
	            },
	            begin: function begin(condition) {
	                this.conditionStack.push(condition);
	            },
	            popState: function popState() {
	                return this.conditionStack.pop();
	            },
	            _currentRules: function _currentRules() {
	                return this.conditions[this.conditionStack[this.conditionStack.length - 1]].rules;
	            },
	            topState: function topState() {
	                return this.conditionStack[this.conditionStack.length - 2];
	            },
	            pushState: function begin(condition) {
	                this.begin(condition);
	            } };
	        lexer.options = {};
	        lexer.performAction = function anonymous(yy, yy_, $avoiding_name_collisions, YY_START) {

	            function strip(start, end) {
	                return yy_.yytext = yy_.yytext.substr(start, yy_.yyleng - end);
	            }

	            var YYSTATE = YY_START;
	            switch ($avoiding_name_collisions) {
	                case 0:
	                    if (yy_.yytext.slice(-2) === "\\\\") {
	                        strip(0, 1);
	                        this.begin("mu");
	                    } else if (yy_.yytext.slice(-1) === "\\") {
	                        strip(0, 1);
	                        this.begin("emu");
	                    } else {
	                        this.begin("mu");
	                    }
	                    if (yy_.yytext) {
	                        return 14;
	                    }break;
	                case 1:
	                    return 14;
	                    break;
	                case 2:
	                    this.popState();
	                    return 14;

	                    break;
	                case 3:
	                    yy_.yytext = yy_.yytext.substr(5, yy_.yyleng - 9);
	                    this.popState();
	                    return 16;

	                    break;
	                case 4:
	                    return 14;
	                    break;
	                case 5:
	                    this.popState();
	                    return 13;

	                    break;
	                case 6:
	                    return 59;
	                    break;
	                case 7:
	                    return 62;
	                    break;
	                case 8:
	                    return 17;
	                    break;
	                case 9:
	                    this.popState();
	                    this.begin("raw");
	                    return 21;

	                    break;
	                case 10:
	                    return 53;
	                    break;
	                case 11:
	                    return 27;
	                    break;
	                case 12:
	                    return 45;
	                    break;
	                case 13:
	                    this.popState();return 42;
	                    break;
	                case 14:
	                    this.popState();return 42;
	                    break;
	                case 15:
	                    return 32;
	                    break;
	                case 16:
	                    return 37;
	                    break;
	                case 17:
	                    return 49;
	                    break;
	                case 18:
	                    return 46;
	                    break;
	                case 19:
	                    this.unput(yy_.yytext);
	                    this.popState();
	                    this.begin("com");

	                    break;
	                case 20:
	                    this.popState();
	                    return 13;

	                    break;
	                case 21:
	                    return 46;
	                    break;
	                case 22:
	                    return 67;
	                    break;
	                case 23:
	                    return 66;
	                    break;
	                case 24:
	                    return 66;
	                    break;
	                case 25:
	                    return 81;
	                    break;
	                case 26:
	                    // ignore whitespace
	                    break;
	                case 27:
	                    this.popState();return 52;
	                    break;
	                case 28:
	                    this.popState();return 31;
	                    break;
	                case 29:
	                    yy_.yytext = strip(1, 2).replace(/\\"/g, "\"");return 74;
	                    break;
	                case 30:
	                    yy_.yytext = strip(1, 2).replace(/\\'/g, "'");return 74;
	                    break;
	                case 31:
	                    return 79;
	                    break;
	                case 32:
	                    return 76;
	                    break;
	                case 33:
	                    return 76;
	                    break;
	                case 34:
	                    return 77;
	                    break;
	                case 35:
	                    return 78;
	                    break;
	                case 36:
	                    return 75;
	                    break;
	                case 37:
	                    return 69;
	                    break;
	                case 38:
	                    return 71;
	                    break;
	                case 39:
	                    return 66;
	                    break;
	                case 40:
	                    return 66;
	                    break;
	                case 41:
	                    return "INVALID";
	                    break;
	                case 42:
	                    return 5;
	                    break;
	            }
	        };
	        lexer.rules = [/^(?:[^\x00]*?(?=(\{\{)))/, /^(?:[^\x00]+)/, /^(?:[^\x00]{2,}?(?=(\{\{|\\\{\{|\\\\\{\{|$)))/, /^(?:\{\{\{\{\/[^\s!"#%-,\.\/;->@\[-\^`\{-~]+(?=[=}\s\/.])\}\}\}\})/, /^(?:[^\x00]*?(?=(\{\{\{\{\/)))/, /^(?:[\s\S]*?--(~)?\}\})/, /^(?:\()/, /^(?:\))/, /^(?:\{\{\{\{)/, /^(?:\}\}\}\})/, /^(?:\{\{(~)?>)/, /^(?:\{\{(~)?#)/, /^(?:\{\{(~)?\/)/, /^(?:\{\{(~)?\^\s*(~)?\}\})/, /^(?:\{\{(~)?\s*else\s*(~)?\}\})/, /^(?:\{\{(~)?\^)/, /^(?:\{\{(~)?\s*else\b)/, /^(?:\{\{(~)?\{)/, /^(?:\{\{(~)?&)/, /^(?:\{\{(~)?!--)/, /^(?:\{\{(~)?![\s\S]*?\}\})/, /^(?:\{\{(~)?)/, /^(?:=)/, /^(?:\.\.)/, /^(?:\.(?=([=~}\s\/.)|])))/, /^(?:[\/.])/, /^(?:\s+)/, /^(?:\}(~)?\}\})/, /^(?:(~)?\}\})/, /^(?:"(\\["]|[^"])*")/, /^(?:'(\\[']|[^'])*')/, /^(?:@)/, /^(?:true(?=([~}\s)])))/, /^(?:false(?=([~}\s)])))/, /^(?:undefined(?=([~}\s)])))/, /^(?:null(?=([~}\s)])))/, /^(?:-?[0-9]+(?:\.[0-9]+)?(?=([~}\s)])))/, /^(?:as\s+\|)/, /^(?:\|)/, /^(?:([^\s!"#%-,\.\/;->@\[-\^`\{-~]+(?=([=~}\s\/.)|]))))/, /^(?:\[[^\]]*\])/, /^(?:.)/, /^(?:$)/];
	        lexer.conditions = { mu: { rules: [6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42], inclusive: false }, emu: { rules: [2], inclusive: false }, com: { rules: [5], inclusive: false }, raw: { rules: [3, 4], inclusive: false }, INITIAL: { rules: [0, 1, 42], inclusive: true } };
	        return lexer;
	    })();
	    parser.lexer = lexer;
	    function Parser() {
	        this.yy = {};
	    }Parser.prototype = parser;parser.Parser = Parser;
	    return new Parser();
	})();exports["default"] = handlebars;
	module.exports = exports["default"];

/***/ },
/* 16 */
/***/ function(module, exports, __webpack_require__) {

	'use strict';

	var _interopRequireDefault = __webpack_require__(8)['default'];

	exports.__esModule = true;

	var _Visitor = __webpack_require__(6);

	var _Visitor2 = _interopRequireDefault(_Visitor);

	function WhitespaceControl() {}
	WhitespaceControl.prototype = new _Visitor2['default']();

	WhitespaceControl.prototype.Program = function (program) {
	  var isRoot = !this.isRootSeen;
	  this.isRootSeen = true;

	  var body = program.body;
	  for (var i = 0, l = body.length; i < l; i++) {
	    var current = body[i],
	        strip = this.accept(current);

	    if (!strip) {
	      continue;
	    }

	    var _isPrevWhitespace = isPrevWhitespace(body, i, isRoot),
	        _isNextWhitespace = isNextWhitespace(body, i, isRoot),
	        openStandalone = strip.openStandalone && _isPrevWhitespace,
	        closeStandalone = strip.closeStandalone && _isNextWhitespace,
	        inlineStandalone = strip.inlineStandalone && _isPrevWhitespace && _isNextWhitespace;

	    if (strip.close) {
	      omitRight(body, i, true);
	    }
	    if (strip.open) {
	      omitLeft(body, i, true);
	    }

	    if (inlineStandalone) {
	      omitRight(body, i);

	      if (omitLeft(body, i)) {
	        // If we are on a standalone node, save the indent info for partials
	        if (current.type === 'PartialStatement') {
	          // Pull out the whitespace from the final line
	          current.indent = /([ \t]+$)/.exec(body[i - 1].original)[1];
	        }
	      }
	    }
	    if (openStandalone) {
	      omitRight((current.program || current.inverse).body);

	      // Strip out the previous content node if it's whitespace only
	      omitLeft(body, i);
	    }
	    if (closeStandalone) {
	      // Always strip the next node
	      omitRight(body, i);

	      omitLeft((current.inverse || current.program).body);
	    }
	  }

	  return program;
	};
	WhitespaceControl.prototype.BlockStatement = function (block) {
	  this.accept(block.program);
	  this.accept(block.inverse);

	  // Find the inverse program that is involed with whitespace stripping.
	  var program = block.program || block.inverse,
	      inverse = block.program && block.inverse,
	      firstInverse = inverse,
	      lastInverse = inverse;

	  if (inverse && inverse.chained) {
	    firstInverse = inverse.body[0].program;

	    // Walk the inverse chain to find the last inverse that is actually in the chain.
	    while (lastInverse.chained) {
	      lastInverse = lastInverse.body[lastInverse.body.length - 1].program;
	    }
	  }

	  var strip = {
	    open: block.openStrip.open,
	    close: block.closeStrip.close,

	    // Determine the standalone candiacy. Basically flag our content as being possibly standalone
	    // so our parent can determine if we actually are standalone
	    openStandalone: isNextWhitespace(program.body),
	    closeStandalone: isPrevWhitespace((firstInverse || program).body)
	  };

	  if (block.openStrip.close) {
	    omitRight(program.body, null, true);
	  }

	  if (inverse) {
	    var inverseStrip = block.inverseStrip;

	    if (inverseStrip.open) {
	      omitLeft(program.body, null, true);
	    }

	    if (inverseStrip.close) {
	      omitRight(firstInverse.body, null, true);
	    }
	    if (block.closeStrip.open) {
	      omitLeft(lastInverse.body, null, true);
	    }

	    // Find standalone else statments
	    if (isPrevWhitespace(program.body) && isNextWhitespace(firstInverse.body)) {
	      omitLeft(program.body);
	      omitRight(firstInverse.body);
	    }
	  } else if (block.closeStrip.open) {
	    omitLeft(program.body, null, true);
	  }

	  return strip;
	};

	WhitespaceControl.prototype.MustacheStatement = function (mustache) {
	  return mustache.strip;
	};

	WhitespaceControl.prototype.PartialStatement = WhitespaceControl.prototype.CommentStatement = function (node) {
	  /* istanbul ignore next */
	  var strip = node.strip || {};
	  return {
	    inlineStandalone: true,
	    open: strip.open,
	    close: strip.close
	  };
	};

	function isPrevWhitespace(body, i, isRoot) {
	  if (i === undefined) {
	    i = body.length;
	  }

	  // Nodes that end with newlines are considered whitespace (but are special
	  // cased for strip operations)
	  var prev = body[i - 1],
	      sibling = body[i - 2];
	  if (!prev) {
	    return isRoot;
	  }

	  if (prev.type === 'ContentStatement') {
	    return (sibling || !isRoot ? /\r?\n\s*?$/ : /(^|\r?\n)\s*?$/).test(prev.original);
	  }
	}
	function isNextWhitespace(body, i, isRoot) {
	  if (i === undefined) {
	    i = -1;
	  }

	  var next = body[i + 1],
	      sibling = body[i + 2];
	  if (!next) {
	    return isRoot;
	  }

	  if (next.type === 'ContentStatement') {
	    return (sibling || !isRoot ? /^\s*?\r?\n/ : /^\s*?(\r?\n|$)/).test(next.original);
	  }
	}

	// Marks the node to the right of the position as omitted.
	// I.e. {{foo}}' ' will mark the ' ' node as omitted.
	//
	// If i is undefined, then the first child will be marked as such.
	//
	// If mulitple is truthy then all whitespace will be stripped out until non-whitespace
	// content is met.
	function omitRight(body, i, multiple) {
	  var current = body[i == null ? 0 : i + 1];
	  if (!current || current.type !== 'ContentStatement' || !multiple && current.rightStripped) {
	    return;
	  }

	  var original = current.value;
	  current.value = current.value.replace(multiple ? /^\s+/ : /^[ \t]*\r?\n?/, '');
	  current.rightStripped = current.value !== original;
	}

	// Marks the node to the left of the position as omitted.
	// I.e. ' '{{foo}} will mark the ' ' node as omitted.
	//
	// If i is undefined then the last child will be marked as such.
	//
	// If mulitple is truthy then all whitespace will be stripped out until non-whitespace
	// content is met.
	function omitLeft(body, i, multiple) {
	  var current = body[i == null ? body.length - 1 : i - 1];
	  if (!current || current.type !== 'ContentStatement' || !multiple && current.leftStripped) {
	    return;
	  }

	  // We omit the last node if it's whitespace only and not preceeded by a non-content node.
	  var original = current.value;
	  current.value = current.value.replace(multiple ? /\s+$/ : /[ \t]+$/, '');
	  current.leftStripped = current.value !== original;
	  return current.leftStripped;
	}

	exports['default'] = WhitespaceControl;
	module.exports = exports['default'];

/***/ },
/* 17 */
/***/ function(module, exports, __webpack_require__) {

	'use strict';

	var _interopRequireDefault = __webpack_require__(8)['default'];

	exports.__esModule = true;
	exports.SourceLocation = SourceLocation;
	exports.id = id;
	exports.stripFlags = stripFlags;
	exports.stripComment = stripComment;
	exports.preparePath = preparePath;
	exports.prepareMustache = prepareMustache;
	exports.prepareRawBlock = prepareRawBlock;
	exports.prepareBlock = prepareBlock;

	var _Exception = __webpack_require__(12);

	var _Exception2 = _interopRequireDefault(_Exception);

	function SourceLocation(source, locInfo) {
	  this.source = source;
	  this.start = {
	    line: locInfo.first_line,
	    column: locInfo.first_column
	  };
	  this.end = {
	    line: locInfo.last_line,
	    column: locInfo.last_column
	  };
	}

	function id(token) {
	  if (/^\[.*\]$/.test(token)) {
	    return token.substr(1, token.length - 2);
	  } else {
	    return token;
	  }
	}

	function stripFlags(open, close) {
	  return {
	    open: open.charAt(2) === '~',
	    close: close.charAt(close.length - 3) === '~'
	  };
	}

	function stripComment(comment) {
	  return comment.replace(/^\{\{~?\!-?-?/, '').replace(/-?-?~?\}\}$/, '');
	}

	function preparePath(data, parts, locInfo) {
	  locInfo = this.locInfo(locInfo);

	  var original = data ? '@' : '',
	      dig = [],
	      depth = 0,
	      depthString = '';

	  for (var i = 0, l = parts.length; i < l; i++) {
	    var part = parts[i].part,

	    // If we have [] syntax then we do not treat path references as operators,
	    // i.e. foo.[this] resolves to approximately context.foo['this']
	    isLiteral = parts[i].original !== part;
	    original += (parts[i].separator || '') + part;

	    if (!isLiteral && (part === '..' || part === '.' || part === 'this')) {
	      if (dig.length > 0) {
	        throw new _Exception2['default']('Invalid path: ' + original, { loc: locInfo });
	      } else if (part === '..') {
	        depth++;
	        depthString += '../';
	      }
	    } else {
	      dig.push(part);
	    }
	  }

	  return new this.PathExpression(data, depth, dig, original, locInfo);
	}

	function prepareMustache(path, params, hash, open, strip, locInfo) {
	  // Must use charAt to support IE pre-10
	  var escapeFlag = open.charAt(3) || open.charAt(2),
	      escaped = escapeFlag !== '{' && escapeFlag !== '&';

	  return new this.MustacheStatement(path, params, hash, escaped, strip, this.locInfo(locInfo));
	}

	function prepareRawBlock(openRawBlock, content, close, locInfo) {
	  if (openRawBlock.path.original !== close) {
	    var errorNode = { loc: openRawBlock.path.loc };

	    throw new _Exception2['default'](openRawBlock.path.original + ' doesn\'t match ' + close, errorNode);
	  }

	  locInfo = this.locInfo(locInfo);
	  var program = new this.Program([content], null, {}, locInfo);

	  return new this.BlockStatement(openRawBlock.path, openRawBlock.params, openRawBlock.hash, program, undefined, {}, {}, {}, locInfo);
	}

	function prepareBlock(openBlock, program, inverseAndProgram, close, inverted, locInfo) {
	  // When we are chaining inverse calls, we will not have a close path
	  if (close && close.path && openBlock.path.original !== close.path.original) {
	    var errorNode = { loc: openBlock.path.loc };

	    throw new _Exception2['default'](openBlock.path.original + ' doesn\'t match ' + close.path.original, errorNode);
	  }

	  program.blockParams = openBlock.blockParams;

	  var inverse = undefined,
	      inverseStrip = undefined;

	  if (inverseAndProgram) {
	    if (inverseAndProgram.chain) {
	      inverseAndProgram.program.body[0].closeStrip = close.strip;
	    }

	    inverseStrip = inverseAndProgram.strip;
	    inverse = inverseAndProgram.program;
	  }

	  if (inverted) {
	    inverted = inverse;
	    inverse = program;
	    program = inverted;
	  }

	  return new this.BlockStatement(openBlock.path, openBlock.params, openBlock.hash, program, inverse, openBlock.strip, inverseStrip, close && close.strip, this.locInfo(locInfo));
	}

/***/ },
/* 18 */
/***/ function(module, exports, __webpack_require__) {

	'use strict';

	exports.__esModule = true;
	/*global define */

	var _isArray = __webpack_require__(13);

	var SourceNode = undefined;

	try {
	  /* istanbul ignore next */
	  if (false) {
	    // We don't support this in AMD environments. For these environments, we asusme that
	    // they are running on the browser and thus have no need for the source-map library.
	    var SourceMap = require('source-map');
	    SourceNode = SourceMap.SourceNode;
	  }
	} catch (err) {}

	/* istanbul ignore if: tested but not covered in istanbul due to dist build  */
	if (!SourceNode) {
	  SourceNode = function (line, column, srcFile, chunks) {
	    this.src = '';
	    if (chunks) {
	      this.add(chunks);
	    }
	  };
	  /* istanbul ignore next */
	  SourceNode.prototype = {
	    add: function add(chunks) {
	      if (_isArray.isArray(chunks)) {
	        chunks = chunks.join('');
	      }
	      this.src += chunks;
	    },
	    prepend: function prepend(chunks) {
	      if (_isArray.isArray(chunks)) {
	        chunks = chunks.join('');
	      }
	      this.src = chunks + this.src;
	    },
	    toStringWithSourceMap: function toStringWithSourceMap() {
	      return { code: this.toString() };
	    },
	    toString: function toString() {
	      return this.src;
	    }
	  };
	}

	function castChunk(chunk, codeGen, loc) {
	  if (_isArray.isArray(chunk)) {
	    var ret = [];

	    for (var i = 0, len = chunk.length; i < len; i++) {
	      ret.push(codeGen.wrap(chunk[i], loc));
	    }
	    return ret;
	  } else if (typeof chunk === 'boolean' || typeof chunk === 'number') {
	    // Handle primitives that the SourceNode will throw up on
	    return chunk + '';
	  }
	  return chunk;
	}

	function CodeGen(srcFile) {
	  this.srcFile = srcFile;
	  this.source = [];
	}

	CodeGen.prototype = {
	  prepend: function prepend(source, loc) {
	    this.source.unshift(this.wrap(source, loc));
	  },
	  push: function push(source, loc) {
	    this.source.push(this.wrap(source, loc));
	  },

	  merge: function merge() {
	    var source = this.empty();
	    this.each(function (line) {
	      source.add(['  ', line, '\n']);
	    });
	    return source;
	  },

	  each: function each(iter) {
	    for (var i = 0, len = this.source.length; i < len; i++) {
	      iter(this.source[i]);
	    }
	  },

	  empty: function empty() {
	    var loc = arguments[0] === undefined ? this.currentLocation || { start: {} } : arguments[0];

	    return new SourceNode(loc.start.line, loc.start.column, this.srcFile);
	  },
	  wrap: function wrap(chunk) {
	    var loc = arguments[1] === undefined ? this.currentLocation || { start: {} } : arguments[1];

	    if (chunk instanceof SourceNode) {
	      return chunk;
	    }

	    chunk = castChunk(chunk, this, loc);

	    return new SourceNode(loc.start.line, loc.start.column, this.srcFile, chunk);
	  },

	  functionCall: function functionCall(fn, type, params) {
	    params = this.generateList(params);
	    return this.wrap([fn, type ? '.' + type + '(' : '(', params, ')']);
	  },

	  quotedString: function quotedString(str) {
	    return '"' + (str + '').replace(/\\/g, '\\\\').replace(/"/g, '\\"').replace(/\n/g, '\\n').replace(/\r/g, '\\r').replace(/\u2028/g, '\\u2028') // Per Ecma-262 7.3 + 7.8.4
	    .replace(/\u2029/g, '\\u2029') + '"';
	  },

	  objectLiteral: function objectLiteral(obj) {
	    var pairs = [];

	    for (var key in obj) {
	      if (obj.hasOwnProperty(key)) {
	        var value = castChunk(obj[key], this);
	        if (value !== 'undefined') {
	          pairs.push([this.quotedString(key), ':', value]);
	        }
	      }
	    }

	    var ret = this.generateList(pairs);
	    ret.prepend('{');
	    ret.add('}');
	    return ret;
	  },

	  generateList: function generateList(entries, loc) {
	    var ret = this.empty(loc);

	    for (var i = 0, len = entries.length; i < len; i++) {
	      if (i) {
	        ret.add(',');
	      }

	      ret.add(castChunk(entries[i], this, loc));
	    }

	    return ret;
	  },

	  generateArray: function generateArray(entries, loc) {
	    var ret = this.generateList(entries, loc);
	    ret.prepend('[');
	    ret.add(']');

	    return ret;
	  }
	};

	exports['default'] = CodeGen;
	module.exports = exports['default'];

	/* NOP */

/***/ }
/******/ ])
});
;
