/* Minification failed. Returning unminified contents.
(202,38-39): run-time error JS1195: Expected expression: >
(202,69-70): run-time error JS1004: Expected ';': )
(206,53-54): run-time error JS1195: Expected expression: >
(207,26-27): run-time error JS1195: Expected expression: >
(215,4-5): run-time error JS1195: Expected expression: )
(216,3-4): run-time error JS1195: Expected expression: ,
(218,2-3): run-time error JS1195: Expected expression: )
(226,3-4): run-time error JS1195: Expected expression: )
(233,43-44): run-time error JS1195: Expected expression: >
(235,4-5): run-time error JS1195: Expected expression: )
 */
var defaultToggleDuration = 250;

var InitialiseShoppingCart = function () {
	$(".shopping-cart-container").hover(
		function () {
			$(".shopping-cart.initial").addClass("d-none");
			$(".shopping-cart.hover").removeClass("d-none");
		},
		function () {
			$(".shopping-cart.initial").removeClass("d-none");
			$(".shopping-cart.hover").addClass("d-none");
		});
};

var InitialiseSearchIcon = function () {
	var desktopOnly = window.matchMedia("(min-width: 1200px)");
	if (desktopOnly.matches) {
		$(".search-bar").hover(
			function () {
				$(".search-icon-image.initial").removeClass("d-xl-inline");
				$(".search-icon-image.hover").addClass("d-xl-inline");
			},
			function () {
				$(".search-icon-image.initial").addClass("d-xl-inline");
				$(".search-icon-image.hover").removeClass("d-xl-inline");
			});

		$(".search-bar, .close-icon").click(function () {
			$(".top-section, .search-form-container").toggle(defaultToggleDuration);
			$(".search-textbox").focus();
		});
	} else {
		$(".search-bar, .close-icon").click(function () {
			$(".top-section, .search-form-container").toggle(defaultToggleDuration);
			$(".search-textbox").focus();
			//$("body").toggleClass("no-scroll");
		});
	}

	$(".search").click(function () {
		$("form[role=search]").submit();
	});
};

var InitialiseHamburgerIcon = function () {
	$(".hamburger-nav-container, .hamburger-close-icon").click(function () {
		$(".top-section, .menu-container").toggle(defaultToggleDuration);
		//$("body").toggleClass("no-scroll");
	});
};

var InitialiseOverlayAndModal = function () {
	$("body").on("click",
		".overlay, .close-modal, .main-image-modal.modal",
		function () {
			$(".overlay").hide();
			$(".main-image-modal").removeClass("modal");
			$(".ui-dialog-content").dialog("close");
		});
};

var SetBannerTextContainer = function () {
	var desktopOnly = window.matchMedia("(min-width: 1200px)");
	if (desktopOnly.matches) {
		if ($(".banner-image-container .text-container").length > 0) {
			$BannerImage = $(".banner-image");
			var BannerImageHeight = $BannerImage.height();
			var HeaderHeight = 140;
			var MaxTextContainerHeight = BannerImageHeight - HeaderHeight;
			$BannerImageTextContainer = $(".banner-image-container .text-container");
			$BannerImageTextContainer.css("position", "relative");
			var BannerImageTextContainerHeight = $BannerImageTextContainer.height();
			$BannerImageTextContainer.css("position", "absolute");
			var BannerImageTextContainerPosition = (MaxTextContainerHeight - BannerImageTextContainerHeight) / 2;
			$BannerImageTextContainer.css("padding", BannerImageTextContainerPosition + "px 0");

		}
	}
};

var InitialiseMegaMenu = function () {
	var desktopOnly = window.matchMedia("(min-width: 1200px)");
	if (desktopOnly.matches) {
		$("[data-controller].desktop-controller").each(function (index, element) {
			var guid = $(element).attr("data-controller");
			var panel = $("[data-panel=" + guid + "]");
			$(element).hover(function () {
				$(".panel-container").attr("style", "display: none !important");
				var leftPosition = $(element).position().left + 15;
				$(panel).attr("style", "display: flex !important; left: " + leftPosition + "px;");
				$("[data-controller]").not($(element)).removeClass("hover");
				$(element).addClass("hover");
			});
		});
		$(".main-menu-links").hover(function (event) {
		}, function (event) {
			$(".panel-container").attr("style", "display: none !important");
			$("[data-controller].desktop-controller").removeClass("hover");
		});
	}
	else {
		$(".main-menu-links a").each(function (index, element) {
			var childPages = $(this).next(".childpages");
			if (childPages.length === 1) {
				$(this).click(function () {
					$(childPages).toggle();
					return false;
				});
			}
		});
	}
};

var InitialiseFooterAccordion = function () {
	var desktopOnly = window.matchMedia("(min-width: 1200px)");
	if (!desktopOnly.matches) {
		$("footer .links-container h3").click(function (event) {
			var LinksContainer = $(this).parent();
			$(LinksContainer).toggleClass("open");
		});
	}
};

var InitialiseFooterBackToTop = function () {
	var desktopOnly = window.matchMedia("(min-width: 1200px)");
	if (!desktopOnly.matches) {
		$("footer .bottom-links-section .back-to-top").click(function (event) {
			$('html, body').animate({ scrollTop: 0 }, 'slow');
		});
	}
};

var Bookmark = {
	init: function () {
		$(document).on("click", "button.bookmark", Bookmark.saveBookmark);
	},
	saveBookmark: function (e) {
		e.preventDefault();

		var form = $(this).closest("form");
		$.ajax({
			cache: false,
			async: true,
			type: "POST",
			url: "/Bookmark/SaveBookmark",
			dataType: "json",
			data: form.serialize(),
			success: function (data) {
				if (data === "/login/") {
					window.location.href = data;
					return true;
				}
				var returnedData = JSON.parse(data);
				if (returnedData.hasOwnProperty("success")) {
					$('.bookmark-container').hide();
					$('.added').show();
				}

			},
			error: function () {
			}
		});
	}
};


var InitialiseMain = function () {
	InitialiseLazyImages();
	InitialiseShoppingCart();
	InitialiseSearchIcon();
	InitialiseHamburgerIcon();
	InitialiseOverlayAndModal();
	SetMarginsOnFullWidthBlocks();
	InitialiseMegaMenu();
	InitialiseFooterAccordion();
	InitialiseFooterBackToTop();
	SetBannerTextContainer();
	Bookmark.init();

};

var SetMarginsOnFullWidthBlocks = function () {
	var $f = $('.block.full-width');
	$f.css('margin-left', 0);
	$f.css('margin-right', 0);
	var totalWidth = $('body').outerWidth(),
		fWidth = $f.outerWidth(),
		diff = totalWidth - fWidth,
		marg = -Math.floor(diff / 2) + 'px';
	$f.each(function () {
		$(this).css({
			'margin-left': marg,
			'margin-right': marg
		});
	});
};

function InitialiseLazyImages() {
	const lazyImages = document.querySelectorAll('img[data-src]');

	if (!('IntersectionObserver' in window)) {
		lazyImages.forEach((imageElement) => setSrcAttribute(imageElement));
		return;
	}

	const observer = new IntersectionObserver(entries => {
		entries.forEach(entry => {
			if (entry.intersectionRatio <= 0) {
				return;
			}

			const imageElement = entry.target;
			setSrcAttribute(imageElement);
			observer.unobserve(imageElement);
		});
	},
		{ rootMargin: '100px' }
	);

	lazyImages.forEach((imageElement) => {
		if (imageElement.loading === 'lazy' && 'loading' in HTMLImageElement.prototype) {
			setSrcAttribute(imageElement);
		} else {
			observer.observe(imageElement);
		}
	});
}

function setSrcAttribute(imageElement) {
	const parent = imageElement.parentNode;
	if (parent.tagName === 'PICTURE') {
		const sourceElements = parent.querySelectorAll('source');
		sourceElements.forEach((sourceElement) => {
			sourceElement.srcset = sourceElement.dataset.srcset;
		});
	}

	imageElement.src = imageElement.dataset.src;
}

$(document).ready(function () {
	InitialiseMain();

	var originalScreenWidth = $(window).width();
	$(window).resize(function () {
		SetBannerTextContainer();
		SetMarginsOnFullWidthBlocks();
		if ((originalScreenWidth >= 1200 && $(window).width() <= 1200) || (originalScreenWidth <= 1200 && $(window).width() >= 1200)) {
			location.reload();
		}
	});

});;
var serviceUrl = "//api.reciteme.com/asset/js?key=";
var serviceKey = "1c1bc7663ae43eaa7aa0ff6bc22c8113df6d4734";
var options = {};  // Options can be added as needed
var autoLoad = false;
var enableFragment = "#reciteEnable";
var loaded = [], frag = !1; window.location.hash === enableFragment && (frag = !0); function loadScript(c, b) { var a = document.createElement("script"); a.type = "text/javascript"; a.readyState ? a.onreadystatechange = function () { if ("loaded" == a.readyState || "complete" == a.readyState) a.onreadystatechange = null, void 0 != b && b() } : void 0 != b && (a.onload = function () { b() }); a.src = c; document.getElementsByTagName("head")[0].appendChild(a) } function _rc(c) { c += "="; for (var b = document.cookie.split(";"), a = 0; a < b.length; a++) { for (var d = b[a]; " " == d.charAt(0);)d = d.substring(1, d.length); if (0 == d.indexOf(c)) return d.substring(c.length, d.length) } return null } function loadService(c) { for (var b = serviceUrl + serviceKey, a = 0; a < loaded.length; a++)if (loaded[a] == b) return; loaded.push(b); loadScript(serviceUrl + serviceKey, function () { "function" === typeof _reciteLoaded && _reciteLoaded(); "function" == typeof c && c(); Recite.load(options); Recite.Event.subscribe("Recite:load", function () { Recite.enable() }) }) } "true" == _rc("Recite.Persist") && loadService(); if (autoLoad && "false" != _rc("Recite.Persist") || frag) document.addEventListener ? document.addEventListener("DOMContentLoaded", function (c) { loadService() }) : loadService();

document.addEventListener("DOMContentLoaded", function (event) {
    document.getElementById('enableRecite').addEventListener("click", function () {
        loadService();
    });

    document.getElementById('recite-me-mobile').addEventListener("click", function () {
        loadService();
    });

});;
(function ($) {
	$.validator.unobtrusive.adapters.addBool("booleanrequired", "required");
})(jQuery);

function PopulateFields(orgFound) {
	var addressId = "";
	var company = "";
	var addressField1 = "";
	var addressField2 = "";
	var city = "";
	var county = "";
	var country = "";

	var selectAddress = $("#selectAddress").val();
	if (selectAddress) {
		var newString = selectAddress.replace(/(\r\n|\n|\r)/gm, ",");
		var fields = newString.split(',');

		addressId = fields[0].trim();
		company = fields[1].trim();
		addressField1 = fields[2].trim();
		addressField2 = fields[3].trim();
		city = fields[4].trim();
		county = fields[5].trim();
		country = fields[6].trim();
	}

	if ((company !== undefined) && (company !== '')) {
		$("#Company").val(company);
		$("#line1").val(addressField1);

		//if ((addressField2 !== undefined) && (addressField2 !== '')) {
		//	addressField1 = addressField1 + ', ' + addressField2;
		//}
		$("#line2").val(addressField2);
	} else {
		$("#line1").val(addressField1);
		$("#line2").val(addressField2);
	}

	$("#city").val(city);
	$("#Province").val(county);
	$("#AddressId").val(addressId);
	$("#CountryCode").val(country);

	if (selectAddress && (orgFound === true)) {
		$("#line1").attr('readonly', 'readonly');
		$("#line2").attr('readonly', 'readonly');
		$("#city").attr('readonly', 'readonly');
		$("#Province").attr('readonly', 'readonly');
		$("#PostalCode").attr('readonly', 'readonly');
	} else {
		$("#line1").removeAttr('readonly');
		$("#line2").removeAttr('readonly');
		$("#city").removeAttr('readonly');
		$("#Province").removeAttr('readonly');
		$("#PostalCode").removeAttr('readonly');
	}
}

function populateJobTitle(company) {
	var securityToken = $('input[name="__RequestVerificationToken"]').val();
	var name = $('name').val();
	var nameAgain = $('Name').val();
	var postdata = { __RequestVerificationToken: securityToken, Name: name, Label: company };
	$.ajax({
		type: "POST",
		url: '/Registration/PopulateJobTitle',
		data: postdata,
		success: function (data) {
			if (data.errorMessage === undefined) {

			}
			else {
				$('#jobtitlespan').hide();
				$('#jobtitlepopulatespan').show();
			}
		},
		error: function () {
			$('#jobtitlespan').hide();
			$('#jobtitlepopulatespan').show();
		},
		complete: function () {
			$('#jobtitlepopulatespan').show();
		}
	});
}

$(".toggle-password").click(function () {
	$(this).toggleClass("fas fa-eye fa-eye-slash");
	var inputID = $(this).attr("data-toggle-target");
	var input = $("#" + inputID);

	if (input.attr("type") === "password") {
		input.attr("type", "text");
	} else {
		input.attr("type", "password");
	}
});

if ($(".already-registered").length > 0) {
	$(".overlay").show();
	$(".already-registered").dialog({
		position: {
			my: "top",
			at: "top+20",
			of: window,
			collision: "none"
		},
		modal: true,
		resizable: false,
		closeOnEscape: false,
		create: function (event, ui) {
			$(event.target).parent().css('position', 'fixed');
			$(".ui-dialog-title").addClass("h2");
			$(".already-registered.d-none").removeClass("d-none");
		}
	});
}
;
$(document).ready(function () {
	var minNoOfItems = 2;
	var minNoOfItemsInfographic = 2;
	var hiddenString = "d-none";
	var visibleString = "d-block";
	var desktopOnly = window.matchMedia("(min-width: 769px)");

	if (desktopOnly.matches) {
		hiddenString = "d-lg-none";
		visibleString = "d-lg-block";
		minNoOfItems = 5;
		minNoOfItemsInfographic = 6;
	}

	var HideMoreArrowIfMinNoOfItems = function ($this) {
		var itemBlocks = $($this).find(".item");
		var min = $($this).closest(".block").hasClass("infographicblock") ? minNoOfItemsInfographic : minNoOfItems;
		if (itemBlocks.length < min) {
			$($this).find(".more-items").removeClass("d-block").removeClass("d-lg-block").addClass("d-none");
		}
	};

	var GetBlockVisibility = function ($items) {
		var hiddenBlocksList = [];
		$($items).each(function (index, element) {
			hiddenBlocksList.push({ Index: index, Hidden: $(element).parent().hasClass(hiddenString) });
		});
		return hiddenBlocksList;
	};

	var GetFirstVisibleBlock = function (itemList) {
		return $(itemList).filter(function (index, element) { return element.Hidden === false })[0];
	};

	var GetFirstHiddenBlock = function (itemList) {
		return $(itemList).filter(function (index, element) { return element.Hidden === true })[0];
	};

	var SetupCarouselArrows = function ($this) {
		HideMoreArrowIfMinNoOfItems($this);

		$($this).find(".less-items").on("click", function () {
			var itemBlocks = $($this).find(".item");
			var itemBlocksWithVisibility = GetBlockVisibility(itemBlocks);
			var firstVisibleBlock = GetFirstVisibleBlock(itemBlocksWithVisibility);
			var itemBlocksWithoutPreviousBlocks = itemBlocksWithVisibility.slice(firstVisibleBlock.Index);
			var firstNextHiddenBlock = GetFirstHiddenBlock(itemBlocksWithoutPreviousBlocks);
			var itemBlocksWithoutNextBlocks = itemBlocksWithVisibility;

			if (firstNextHiddenBlock) {
				itemBlocksWithoutNextBlocks = itemBlocksWithVisibility.slice(0, firstNextHiddenBlock.Index);
			}

			var lastVisibleBlock = itemBlocksWithoutNextBlocks[itemBlocksWithoutNextBlocks.length - 1];
			$($($this).find(".item")[firstVisibleBlock.Index - 1]).parent().removeClass(hiddenString).addClass(visibleString);
			$($($this).find(".item")[lastVisibleBlock.Index]).parent().addClass(hiddenString).removeClass(visibleString);
			DisplayCarouselArrows($this);
		});

		$($this).find(".more-items").on("click", function () {
			var itemBlocks = $($this).find(".item");
			var itemBlocksWithVisibility = GetBlockVisibility(itemBlocks);
			var firstVisibleBlock = GetFirstVisibleBlock(itemBlocksWithVisibility);
			var itemBlocksWithoutPreviousBlocks = itemBlocksWithVisibility.slice(firstVisibleBlock.Index);
			var firstNextHiddenBlock = GetFirstHiddenBlock(itemBlocksWithoutPreviousBlocks);

			if (firstVisibleBlock) {
				$($($this).find(".item")[firstVisibleBlock.Index]).parent().addClass(hiddenString).removeClass(visibleString);
			}

			if (firstNextHiddenBlock) {
				$($($this).find(".item")[firstNextHiddenBlock.Index]).parent().removeClass(hiddenString).addClass(visibleString);
			}			

			DisplayCarouselArrows($this);
		});
	};

	var DisplayCarouselArrows = function ($this) {
		var itemBlocks = $($this).find(".item");
		var itemBlocksWithVisibility = GetBlockVisibility(itemBlocks);
		var showPrevious = itemBlocksWithVisibility[0].Hidden === true;

		if (showPrevious) {
			$($this).find(".less-items." + hiddenString).removeClass(hiddenString).addClass(visibleString);
			$($this).addClass("with-less-arrow");
		}
		else {
			$($this).find(".less-items." + visibleString).addClass(hiddenString).removeClass(visibleString);
			$($this).removeClass("with-less-arrow");
		}

		var showNext = itemBlocksWithVisibility[itemBlocksWithVisibility.length - 1].Hidden === true;

		if (showNext) {
			$($this).find(".more-items." + hiddenString).removeClass(hiddenString).addClass(visibleString);
			$($this).addClass("with-more-arrow");
		}
		else {
			$($this).find(".more-items." + visibleString).addClass(hiddenString).removeClass(visibleString);
			$($this).removeClass("with-more-arrow");
		}
	};

	var SetEventTextContainerHeight = function ($this) {
		$textContainers = $($this).find(".event-product .h3");
		var maxHeight = 0;
		$($textContainers).height("auto");

		$($textContainers).each(function (index, textContainerElement) {
			if ($(textContainerElement).height() > maxHeight) {
				maxHeight = $(textContainerElement).height();
			}
		});
		$($textContainers).height(maxHeight);
    }

	var SetCarouselMaxTextContainerHeight = function ($this) {
		$textContainers = $($this).find(".text-container");
		var maxHeight = 0;
		$($textContainers).height("auto");

		$($textContainers).each(function (index, textContainerElement) {
			if ($(textContainerElement).height() > maxHeight) {
				maxHeight = $(textContainerElement).height();
			}
		});
		$($textContainers).height(maxHeight);
	};

	$(".findoutmorecarousel").each(function (index, element) {
		SetupCarouselArrows($(element));
	});

	$(window).resize(function () {
		$(".findoutmorecarousel").each(function (index, element) {
			SetCarouselMaxTextContainerHeight($(element));
			SetEventTextContainerHeight($(element));
		});
	});

	$(".findoutmorecarousel").each(function (index, element) {
		SetCarouselMaxTextContainerHeight($(element));
	});
});;
$(document).ready(function () {
    var SetMaxTextContainerHeight = function ($element) {
        var maxTextContainerHeight = 0;
        var maxTextHeadingHeight = 0;
        var $textContainers = $($element).find(".text-container");
        var $textHeadings = $($element).find(".text-container h4");
        var $hiddenItems = $($element).find(".d-none");
        $($hiddenItems).removeClass("d-none");
        $($textContainers).height("auto");
        $($textHeadings).height("auto");

        $($textContainers).each(function(index, textContainer) {
            var textHeadingHeight = $(textContainer).find("h4").height();
            if (maxTextHeadingHeight < textHeadingHeight) {
                maxTextHeadingHeight = textHeadingHeight;
            }
        });
        $($textHeadings).height(maxTextHeadingHeight);

        $($textContainers).each(function (index, textContainer) {
            var textContainerHeight = $(textContainer).height();
            if (maxTextContainerHeight < textContainerHeight) {
                maxTextContainerHeight = textContainerHeight;
            }
        });
        $($textContainers).height(maxTextContainerHeight);

        $($hiddenItems).addClass("d-none");     
    };

    $(".featuredblogsblock").each(function (index, element) {
        SetMaxTextContainerHeight($(element));
    });

    $(window).resize(function () {
        $(".featuredblogsblock").each(function (index, element) {
            SetMaxTextContainerHeight($(element));
        });
    });
});;
$(document).ready(function () {
    var SetupDropdownChange = function ($this) {
        $($this).find("select").on("change", function (event) {
            var categoryIDList = $(event.target).val();
            if (categoryIDList == '') {
                $($this).find("[data-unfiltered]").hide();
                $($this).find("[data-category]").not("[data-unfiltered]").show();
                $($this).find(".primary").show();

                var count = $($this).find("[data-category]").not("[data-unfiltered]").length;
                if (count > 12) {
                    $($this).find(".button-row").show();
                }
                else {
                    $($this).find(".button-row").hide();
                }
            }
            else {
                $($this).find("[data-category], .primary").hide();
                var IDs = categoryIDList.split(',');
                $(IDs).each(function (index, element) {
                    $($this).find("[data-unfiltered][data-category*=" + element + "]").show();
                });                

                var count = $($this).find("[data-category]:visible").length;
                if (count > 16) {
                    $($this).find(".button-row").show();
                    for (i = 16; i < count; i++) {
                        $($($this).find("[data-category]:visible")[i]).addClass("extra d-none");
                    }
                }
                else {
                    $($this).find(".button-row").hide();
                }
            }
        });
    }

    var HideExtraRemaining = function ($this) {
        var count = $($this).find(".remaining [data-category]").length;
        if (count > 5) {
            for (i = 5; i < count; i++) {
                $($($this).find(".remaining [data-category]")[i]).addClass("extra d-none");
            }
        }
    }

    var textContainers = $('.filtereddynamiccontentblock .inner-container:not(.large-item .inner-container');
    var height = getTallestHeight(textContainers);
    textContainers.height(height);

    $('.filtereddynamiccontentblock .inner-container.blog').height(height - 22);

    $(".filtereddynamiccontentblock").each(function (index, element) {
        HideExtraRemaining($(element));
        SetupDropdownChange($(element));
    });

    addQuotesToBlogTitles();

});

function getTallestHeight(elements) {
    var tallest = 0, height;

    for (var i = 0; i < elements.length; i++) {
        height = $(elements[i]).height();

        if (height > tallest)
            tallest = height;
    }

    return tallest;
};

function addQuotesToBlogTitles() {
    $('.blog h3.title').prepend('\"').append('\"');
};
$(document).ready(function () {
    var SetPaddingOnTextContainer = function ($this) {
        $textContainer = $($this).find(".text-container");
        $imageContainer = $($this).find(".image-container");
        var textContainerPadding = 20;

        $imageContainer.css("position", "relative");
        $imageContainer.css("padding", "0");

        var desktopOnly = window.matchMedia("(min-width: 1170px)")
        if (desktopOnly.matches) {
            $textContainer.css("display", "table");
            $textContainer.css("padding-top", "0");
            $textContainer.css("padding-bottom", "0");
            var textContainerHeight = $($textContainer).height();
            $textContainer.css("display", "");
            
            var imageContainerHeight = $($imageContainer).find("img").height();
            if ($($this).find(".position-5, .position-6, .position-7").length > 0) {
                $imageContainer.css("position", "");
            }

            if (imageContainerHeight > textContainerHeight) {
                var heightDifference = imageContainerHeight - textContainerHeight;
                textContainerPadding = heightDifference / 2;
                if (textContainerPadding < 20) {
                    textContainerPadding = AdjustTextContainerWidthToReduceImagePadding($this, $textContainer, $imageContainer, 25);
                }
            }
            else {
                textContainerPadding = AdjustTextContainerWidthToReduceImagePadding($this, $textContainer, $imageContainer, 25);
            }
        }
    };

    var AdjustTextContainerWidthToReduceImagePadding = function ($this, $textContainer, $imageContainer, previousWidthPercentage) {
        $textContainer.css("width", (previousWidthPercentage) + '%');
        var textContainerHeight = $($textContainer).height();
        $imageContainer.css("position", "relative");
        var imageContainerHeight = $($imageContainer).find("img").height();
        if ($($this).find(".position-5, .position-6, .position-7").length > 0) {
            $imageContainer.css("position", "");
        }

        var heightDifference = imageContainerHeight - textContainerHeight;
        var textContainerPadding = heightDifference / 2;

        if (previousWidthPercentage != 100) {
            if (imageContainerHeight < textContainerHeight) {
                return AdjustTextContainerWidthToReduceImagePadding($this, $textContainer, $imageContainer, previousWidthPercentage + 5)
            }
            else if (textContainerPadding < 20) {
                return AdjustTextContainerWidthToReduceImagePadding($this, $textContainer, $imageContainer, previousWidthPercentage + 5)
            }
            else {
                return textContainerPadding;
            }
        }
        else {
            return textContainerPadding;
        }
    };

    $(window).resize(function () {
        SetPaddingOnTextContainer($('.imagectablock'));
    });

    SetPaddingOnTextContainer($('.imagectablock'));
});;
function addCommas(nStr) {
    return nStr.toString().replace(/\B(?=(\d{3})+(?!\d))/g, ",");
}

function animateValue($thisValue, end, duration, showPercentage) {
    var current = 0;
    var increment = Math.abs(Math.floor(end / duration));

    var stepTime = Math.abs(Math.floor(duration / end));
    if (increment == 0) {
        increment = 1;
    }
    if (stepTime == 0) {
        stepTime = 1;
    }

    var timer = setInterval(function () {
        current += increment;
        if (showPercentage) {
            $thisValue.text(current + '%');
        }
        else {
            $thisValue.text(addCommas(current));
        }
        if ((current + increment) > end) {
            if (showPercentage) {
                $thisValue.text(end + '%');
            }
            else {
                $thisValue.text(addCommas(end));
            }
        }
        else if (current == end) {
            clearInterval(timer);
        }
    }, stepTime);
}

function drawPieChart(numberelement, $span) {
    var number = $($span).attr("data-infographic-number");
    var myData = [
        {
            value: parseInt(number),
            color: {
                normal: '#1D3062', // stroke/fill color of the segment
                active: '#1D3062',
            },
        },
        {
            value: 100 - parseInt(number),
            color: {
                normal: '#fff', // stroke/fill color of the segment
                active: '#fff',
            },
        }
    ]
    var myChart = $(numberelement).find(".piechart").jChart({
        data: myData,
        appearance: {
            type: 'donut',
            baseOffset: 0, // offset for starting point of first segment
            baseStrokeWidth: 1,
            strokeWidth: 3, // default stroke width for all segments
            animated: false,
            gap: 0.00001
        }
    });
}

window.onload = function () {
    var desktopOnly = window.matchMedia("(min-width: 1200px)");

    $(".infographicpiechartblock").each(function (index, element) {
        $(element).find(".infographic-container").each(function (numberindex, numberelement) {
            var $span = $(numberelement).find("span[data-infographic-number]");

            if ($($span).attr("data-infographic-number") != 0 && $($span).text() == 0) {
                if (desktopOnly.matches) {
                    $($span).waypoint({
                        handler: function (direction) {
                            drawPieChart(numberelement, $span);
                        },
                        offset: 2200
                    });
                }
                else {
                    $($span).text($(numberelement).attr("data-infographic-number"));
                    drawPieChart(numberelement, $span);
                }
            }
        });
    });

    $(".infographicblock, .infographicpiechartblock").each(function (index, element) {
        $(element).find(".infographic-number span[data-infographic-number]").each(function (numberindex, numberelement) {
            if ($(numberelement).attr("data-infographic-number") != 0 && $(numberelement).text() == 0) {
                if (desktopOnly.matches) {
                    $(numberelement).waypoint({
                        handler: function (direction) {
                            if ($(numberelement).attr("data-infographic-number") != 0 && $(numberelement).text() == 0) {
                                animateValue($(numberelement), $(numberelement).attr("data-infographic-number"), 3000, $(element).hasClass("infographicpiechartblock"));
                            }
                        },
                        offset: 2200
                    });
                }
                else {
                    $(numberelement).text($(numberelement).attr("data-infographic-number"));
                }
            }
        });
    });
}
;
$(document).ready(function () {
	var isValid = function (element) {
		var email = $(element).find("input[name=email]").val();
		var re = new RegExp(
			"^([a-zA-Z0-9_\\-\\.]+)@((\\[[0-9]{1,3}\\.[0-9]{1,3}\\.[0-9]{1,3}\\.)|(([a-zA-Z0-9\\-]+\\.)+))([a-zA-Z]{2,10}|[0-9]{1,3})(\\]?)$");
		if (re.test(email)) {
			return $(element).find("input[name=email]").val().length > 0;
		} else {
			return false;
		}
	};

	var SetupSubmitClick = function (element) {
		$(element).find("input[type=submit]").on("click",
			function () {
				if (isValid(element)) {
					var token = $('input[name="__RequestVerificationToken"]').val();
					var email = $(element).find("input[name=email]").val();
					var postdata = { __RequestVerificationToken: token, Email: email };
					$.ajax({
						type: "POST",
						url: '/Newsletter/SignUp',
						data: postdata,
						success: function (data) {
							if (data == "/my-account/") {
								window.location.href = data;
								return true;
							}
							if (data !== undefined) {
								var dataParse = JSON.parse(data);
								if (dataParse.errorMessage === "") {
									$(element).find(".ajax-message")
										.text("Thank you. Please confirm the registration via your email account.");
								} else {
									$(element).find(".ajax-message").text(dataParse.errorMessage);
								}
							}
						},
						error: function () {
							$(element).find(".ajax-message").text('Sign up is not possible at this time.');
						},
						complete: function (data) {
							return false;
						}
					});
				}
				else {
					$(element).find(".ajax-message").text('Please enter a valid email');
				}
				return false;
			});
	};

	var SetupSavePreferencesClick = function ($this) {
		HideAjaxMessage();
		$($this).find("input[name=SavePreferences]").on("click", function () {
			if (isValid($this)) {
				var token = $('input[name="__RequestVerificationToken"]').val();
				var jsonData = $($this).find("#JsonData").val();
				var postdata = { __RequestVerificationToken: token, MyAccountPagePreferencesViewModel: jsonData };
				var url = $('#fieldset-preferences form[name="SavePreferences"]').attr("action");
				$.ajax({
					type: "POST",
					url: url,
					data: postdata,
					success: function (data) {
						if (data !== undefined) {
							var JSONdata = JSON.parse(data);
							if (JSONdata.errorMessage === "") {
								PreferencesModel.AjaxResult(true);
								PreferencesModel.AjaxResultText('Your preferences have been saved.');

								if (JSONdata.optInType !== undefined) {
									PreferencesModel.OptInType(JSONdata.optInType);
								}
							}
							else {
								PreferencesModel.AjaxResult(true);
								PreferencesModel.AjaxResultText(JSONdata.errorMessage);
							}
						}
					},
					error: function () {
						PreferencesModel.AjaxResult(true);
						PreferencesModel.AjaxResultText('It is not possible to save your preferences at this time.');
					},
					complete: function (data) {
						return false;
					}
				});
			}
			else {
				PreferencesModel.AjaxResult(true);
				PreferencesModel.AjaxResultText('Please enter a valid data.');
			}
			return false;
		});
	};
	var TriggerUnsubscribeDualAction = function ($this) {
		$(".overlay").show();
		$(".confirm-unsubscribe").dialog({
			position: {
				my: "top",
				at: "top+20",
				of: window,
				collision: "none"
			},
			modal: true,
			resizable: false,
			closeOnEscape: false,
			create: function (event, ui) {
				$(event.target).parent().css('position', 'fixed');
				$(".ui-dialog-title").addClass("h2");
				$(".confirm-unsubscribe.d-none").removeClass("d-none");
			}
		});
	}
	var TriggerUnsubscribeAjax = function ($this) {
		HideAjaxMessage()
		if (isValid($this)) {
			var token = $('input[name="__RequestVerificationToken"]').val();
			var email = $($this).find("input[name=email]").val();
			var postdata = { __RequestVerificationToken: token, Email: email };
			var url = $('#fieldset-preferences form[name="Unsubscribe"]').attr("action");
			$.ajax({
				type: "POST",
				url: url,
				data: postdata,
				success: function (data) {
					if (data !== undefined) {
						var JSONdata = JSON.parse(data);
						if (JSONdata.errorMessage === "") {
							PreferencesModel.AjaxResult(true);
							PreferencesModel.AjaxResultText('You have been unsubscribed.');
							PreferencesModel.OptInType("Unknown");
							PreferencesModel.ChosenNewsletterCategories([]);
							PreferencesModel.ChosenRegionCategories([]);
							PreferencesModel.ChosenEventCategories([]);
						}
						else {
							PreferencesModel.AjaxResultText(JSONdata.errorMessage);
						}
					}
				},
				error: function () {
					PreferencesModel.AjaxResult(true);
					PreferencesModel.AjaxResultText('It is not possible to unsubscribe at this time.');
				},
				complete: function (data) {
					return false;
				}
			});
		}
		else {
			PreferencesModel.AjaxResultText('Please enter a valid email.');
		}
	}
	var SetupUnsubscribeClick = function ($this) {
		$($this).find("input[name=unsubscribe]").on("click", function () {
			TriggerUnsubscribeDualAction($this);
			return false;
		});
		$($this).find(".confirm-unsubscribe .unsubscribe").on("click", function () {
			TriggerUnsubscribeAjax($this);
		});
	}
	var SetupHideAjaxMessage = function ($this) {
		$($this).find("input[type=checkbox], .my-account-menu li").on("click", function () {
			HideAjaxMessage();
		});
	}
	var HideAjaxMessage = function () {
		PreferencesModel.AjaxResult(false);
		PreferencesModel.AjaxResultText('');
	}

	$(".newsletterblock, .newsletterfooterblock").each(function (index, element) {
		SetupSubmitClick(element);
	});
	$(".myaccountpage").each(function (index, element) {
		SetupHideAjaxMessage($(element));
		SetupSavePreferencesClick($(element));
		SetupUnsubscribeClick($(element));
	});
});;
$(document).ready(function () {
    var SetImageSize = function ($this) {
        
        var desktopOnly = window.matchMedia("(min-width: 1200px)")
        if (desktopOnly.matches) {
            $quoteContainer = $($this).find(".quote-area");
            $imageContainer = $($this).find(".image-container");

            var quoteContainerHeight = $quoteContainer.height();
            var quoteContainerTopPositioning = 40;

            var quoteContainerHeightWithTopPositioning = (quoteContainerHeight + quoteContainerTopPositioning) * 1.2;

            $($imageContainer).height(quoteContainerHeightWithTopPositioning);
        }
    };

    $(window).resize(function () {
        $(".quoteblock").each(function (index, element) {
            SetImageSize($(element));
        });
    });

    $(".quoteblock").each(function (index, element) {
        var $Images = $(element).find("img");
        if ($Images.length > 0) {
            $($Images).each(function (index, $Image) {
                SetImageSize($(element));

                $($Image).one("load", function () {
                    SetImageSize($(element));
                });
            });
        }
    });
});;
$(document).ready(function () {
    var SetMaxTextContainerHeight = function ($this) {        
        var desktopOnly = window.matchMedia("(min-width: 1200px)")
        if (desktopOnly.matches) {
            $textContainers = $($this).find(".text-container");
            var maxHeight = 0;
            $($textContainers).height("auto");
            $($textContainers).each(function (index, textContainerElement) {
                if ($(textContainerElement).height() > maxHeight) {
                    maxHeight = $(textContainerElement).height();
                }
            });

            $($textContainers).height(maxHeight);
        }
    };

    $(window).resize(function () {
        $(".relatedstoriesblock").each(function (index, element) {
            SetMaxTextContainerHeight($(element));
        });
    });

    $(".relatedstoriesblock").each(function (index, element) {
        SetMaxTextContainerHeight($(element));
    });
});;
$(document).ready(function () {
    var SetArrowState = function ($this) {
        $($this).find(".carousel-indicator").removeClass("disable");
        $items = $($this).find(".carousel-item");
        if ($($items[0]).hasClass("active")) {
            $($this).find(".carousel-indicator.prev").addClass("disable");
        }
        if ($($items[$items.length - 1]).hasClass("active")) {
            $($this).find(".carousel-indicator.next").addClass("disable");
        }
    };

    var SetupChange = function ($this) {
        SetArrowState($this);

        $($this).on('slid.bs.carousel', function () {
            SetArrowState($this);
        });
    };

    var SetHeight = function ($this) {
        $carouselInnerContainer = $($this).find(".carousel-inner");
        $items = $($this).find(".carousel-item");
        var maxHeight = 0;
        $($carouselInnerContainer).height("auto");
        $($items).each(function (index, carouselElement) {
            if ($(carouselElement).height() > maxHeight) {
                maxHeight = $(carouselElement).height();
            }
        });

        $($carouselInnerContainer).height(maxHeight);
    };

    $(".themesimageblock").each(function (index, element) {
        $(element).find(".carousel").carousel({
            interval: false,
            wrap: false
        });

        SetupChange($(element).find(".carousel"));
        SetHeight($(element));

        $(window).resize(function () {
            SetHeight($(element));
        });
    });

});;
