/* Minification failed. Returning unminified contents.
(545,69-70): run-time error JS1195: Expected expression: >
(545,82-83): run-time error JS1004: Expected ';': )
 */
function loadMoreArticles(requestBody, btn) {

  if (btn.disabled) return;

  btn.setAttribute('disabled', true);

  var postRequest = new XMLHttpRequest();
  postRequest.open('POST', '/umbraco/surface/article/fetch', true);
  postRequest.setRequestHeader('Content-Type', 'application/json');

  postRequest.onload = function (e) {
    if (this.status == 200) {
      console.log(JSON.parse(this.response));

      var newData = JSON.parse(this.response);

      var row = document.querySelector('.c-news-listing__news-cards-row');

      if (newData.Articles.length) {
        for (var k = 0, l = newData.Articles.length; k < l; k++) {
          var data = newData.Articles[k];

          var article = document.createElement('article');
          article.className = 'col-12 col-sm-6 col-lg-4 c-news-card';

          var link = document.createElement('a');
          link.href = data.Link;
          link.className = 'c-news-card__link zoomIntoImage';

          var imgWrapper = document.createElement('div');
          imgWrapper.className = 'c-news-card__img-wrapper';

          if (data.Image !== null) {
              var img = document.createElement('img');
              img.src = data.Image.Path;
              imgWrapper.appendChild(img);
          }

          var copyContent = document.createElement('div');
          copyContent.className = 'c-news-card__copy-content';

          var cardTitle = document.createElement('h4');
          cardTitle.className = 'c-news-card__title';
          cardTitle.appendChild(document.createTextNode(data.Title));

          var cardFooter = document.createElement('footer');
          cardFooter.className = 'c-news-card__footer';

          var cardDate = document.createElement('span');
          cardDate.className = 'c-news-card__date';
          cardDate.appendChild(document.createTextNode(data.PublishDate));

          var cardType = document.createElement('span');
          cardType.className = 'c-news-card__type';
          cardType.appendChild(document.createTextNode(data.Tag));

          cardFooter.appendChild(cardDate);
          cardFooter.appendChild(cardType);

          copyContent.appendChild(cardTitle);
          copyContent.appendChild(cardFooter);

          link.appendChild(imgWrapper);
          link.appendChild(copyContent);

          article.appendChild(link);

          row.appendChild(article);
        }
      }

      if (newData.DisplayLoadMore === false) btn.style.opacity = 0;
      else btn.setAttribute('disabled', false);
    } else btn.setAttribute('disabled', false);
  };

  postRequest.send(JSON.stringify(requestBody));
}
;

$(function() {
	objectFitImages();

	gsap.registerPlugin(ScrollTrigger);

	ScrollTrigger.defaults({
		markers:false
	})

	if ($('body').is('.home-page')) {
		const logoImg = document.querySelector(".home-pinned-animation__image-foreground");
		let tl = gsap.timeline({
			scrollTrigger: {
				trigger: ".home-pinned-animation",
				start: "top top",
				// end: () => "+=" + (window.innerHeight * 1.8), // not cool for IE11...
				end: function () { return "+=" + (window.innerHeight * 1.8) },
				// markers: true,
				scrub: .3,
				pin: true,
				// anticipatePin: 1
			},
			defaults: { ease: "none" }
		});
		tl.set(logoImg, { scale: 50, xPercent: -30, opacity: 1 });
		tl.to(logoImg, { scale: 1, xPercent: 0, ease: 'power3' });
		tl.to(logoImg, { scale: 1 });






		//gsap.set(".diamond-dynamic", { rotation: -90, transformOrigin: "center" })


		//let diamondInit = gsap.timeline({
		//	scrollTrigger: {
		//		trigger: "#homeIntro",
		//		start: "top center",
		//	},
		//	repeat: -1,
		//	repeatDelay: 1,
		//	yoyo: true,
		//})

		//const initialDuration = 1.5;
		//const endTransition = 5;

		//diamondInit
		//	.addLabel("myLabel", 2)
		//	.set(".diamond-dynamic__graphic-device--1", { yPercent: 12, xPercent: 24 })
		//	.set(".diamond-dynamic__graphic-device--2", { yPercent: 24, xPercent: -12 })
		//	.set(".diamond-dynamic__graphic-device--3", { yPercent: -12, xPercent: -24 })
		//	.set(".diamond-dynamic__graphic-device--4", { yPercent: -24, xPercent: 12 })

		//	.fromTo(".diamond-dynamic__graphic-device", { opacity: 0 }, { opacity: 1, duration: 1 }, 0)

		//	.fromTo(".diamond-dynamic__graphic-device--1 .diamond-dynamic__graphic-device-inner-pattern", { height: 0 }, { height: '100%', duration: initialDuration }, 0)
		//	.fromTo(".diamond-dynamic__graphic-device--1 .diamond-dynamic__graphic-device-inner", { top: '100%' }, { top: 0, duration: initialDuration }, 0)
		//	.fromTo(".diamond-dynamic__graphic-device--3 .diamond-dynamic__graphic-device-inner-pattern", { height: 0 }, { height: '100%', duration: initialDuration }, 0)
		//	.fromTo(".diamond-dynamic__graphic-device--2 .diamond-dynamic__graphic-device-inner-pattern", { left: '-100%' }, { left: 0, duration: initialDuration }, 0)
		//	.fromTo(".diamond-dynamic__graphic-device--4 .diamond-dynamic__graphic-device-inner-pattern", { right: '-100%' }, { right: 0, duration: initialDuration }, 0)
		//	.fromTo(".diamond-dynamic__graphic-device--4 .diamond-dynamic__graphic-device-inner", { left: '100%' }, { left: 0, duration: initialDuration }, 0)

		//	.to(".diamond-dynamic", 2, { rotation: -45, transformOrigin: "center", ease: "power2.inOut" }, 0)
		//	// .to(".diamond-dynamic__graphic-device", 3, { yPercent: 0, xPercent: 0 }, "<.5")
		//	// .call(function () { diamondTl.play() })

		//	.to({}, { duration: .75 })

		//	/*
		//	.to({}, { delay: 3 })
		//	.to(".diamond-dynamic", 2, { rotation: -90, transformOrigin: "center", ease: "power2.inOut" })

		//	.fromTo(".diamond-dynamic__graphic-device--1 .diamond-dynamic__graphic-device-inner-pattern", { height: '100%' }, { height: 0, duration: initialDuration }, '<+.5')
		//	.fromTo(".diamond-dynamic__graphic-device--1 .diamond-dynamic__graphic-device-inner", { top: 0 }, { top: '100%', duration: initialDuration }, '<')
		//	.fromTo(".diamond-dynamic__graphic-device--3 .diamond-dynamic__graphic-device-inner-pattern", { height: '100%' }, { height: 0, duration: initialDuration }, '<')
		//	.fromTo(".diamond-dynamic__graphic-device--2 .diamond-dynamic__graphic-device-inner-pattern", { left: 0 }, { left: '-100%', duration: initialDuration }, '<')
		//	.fromTo(".diamond-dynamic__graphic-device--4 .diamond-dynamic__graphic-device-inner-pattern", { right: 0 }, { right: '-100%', duration: initialDuration }, '<')
		//	.fromTo(".diamond-dynamic__graphic-device--4 .diamond-dynamic__graphic-device-inner", { left: 0 }, { left: '100%', duration: initialDuration }, '<')

		//	.fromTo(".diamond-dynamic__graphic-device", { opacity: 1 }, { opacity: 0, duration: 1 }, '<+.5')
		//	*/



		///*
		//.to(".diamond-dynamic", 2, { rotation: 0, transformOrigin: "center" })
		//.to(".diamond-dynamic__graphic-device--1", .5, { yPercent: 12, xPercent: 24 }, "myLabel")
		//.to(".diamond-dynamic__graphic-device--2", .5, { yPercent: 24, xPercent: -12 }, "myLabel")
		//.to(".diamond-dynamic__graphic-device--3", .5, { yPercent: -12, xPercent: -24 }, "myLabel")
		//.to(".diamond-dynamic__graphic-device--4", .5, { yPercent: -24, xPercent: 12 }, "myLabel")
		


		//.call(function () { diamondTl.play() })
		//*/


		//// .to(".diamond-dynamic", 2, { rotation: "+=45", transformOrigin: "center", repeatRefresh: true })
		//// .to(".diamond-dynamic__graphic-device", 2.1, { rotation: "-=45", transformOrigin: "center", repeatRefresh: true }, 0)

		//const XYIn = "alignment-=1"
		//const XYduration = 1
		//const XYease = "back.inOut.config(2)"

		//let diamondTl = gsap.timeline({
		//	// repeat: -1,
		//	// repeatRefresh: true
		//})
		//diamondTl
		//	.addLabel("alignment", 3.1)
		//	.to(".diamond-dynamic", 3, { rotation: "+=270", transformOrigin: "center" })
		//	.to(".diamond-dynamic__graphic-device", { rotation: "-=270", duration: 3, /* yPercent: 0, xPercent: 0, */ /* stagger: { each: .2 }, */ transformOrigin: "center" }, '<')

		//	/*
		//	.to(".diamond-dynamic__graphic-device", 3, { yPercent: 0, xPercent: 0},  "<")

			
		//	.to(".diamond-dynamic__graphic-device--1", XYduration, { yPercent: 12, xPercent: 24, ease: XYease }, XYIn)
		//	.to(".diamond-dynamic__graphic-device--2", XYduration, { yPercent: 24, xPercent: -12, ease: XYease }, XYIn)
		//	.to(".diamond-dynamic__graphic-device--3", XYduration, { yPercent: -12, xPercent: -24, ease: XYease }, XYIn)
		//	.to(".diamond-dynamic__graphic-device--4", XYduration, { yPercent: -24, xPercent: 12, ease: XYease }, XYIn)
		//	*/

		//	/* 
		//	.to(".diamond-dynamic__graphic-device--1", .5, { yPercent: 12, xPercent: 24 }, "<-1.5")
		//	.to(".diamond-dynamic__graphic-device--2", .5, { yPercent: 24, xPercent: -12 }, "<-1.5")
		//	.to(".diamond-dynamic__graphic-device--3", .5, { yPercent: -12, xPercent: -24 }, "<-1.5")
		//	.to(".diamond-dynamic__graphic-device--4", .5, { yPercent: -24, xPercent: 12 }, "<-1.5")
		//	*/
		//	// .to(".diamond-dynamic__graphic-device", { rotation: "-=45", duration: 2, transformOrigin: "center" }, 0)
		//	// .to({}, { delay: .2 })
		//	.pause();




	}



	// about page
	/*
	const imgAbout = document.querySelector(".about-pinned-animation__image-reveal");
	const copyAbout = document.querySelectorAll(".about-pinned-animation-copy__text");


	const svgAboutPolygon = document.querySelectorAll(".about-pinned-animation__image-background polygon");

	const tlAbout = gsap.timeline({
		scrollTrigger: {
			trigger: ".about-pinned-animation",
			// start: "center center",
			start: "1px top",
			// end: ()=> "+=" + (window.innerHeight),

			// makes the height of the scrolling (while pinning) match the width, thus the speed remains constant (vertical/horizontal)
			// end: () => "+=" + section.offsetWidth,
			// markers: true,
			pin: true,
			// anticipatePin: 1
			refreshPriority: 1
		},
		// defaults: { ease: "none" }
	});

	// tlAbout.fromTo(imgAbout, { height: 0 }, { height: 'auto', duration: 1.5, ease: "steps(32)" })

	const svgAboutPolygonFirst = document.querySelectorAll(".about-pinned-animation__image-background polygon.first");
	const svgAboutPolygonLast = document.querySelectorAll(".about-pinned-animation__image-background polygon.last");


	const tlAboutPolygonStagger = {
		each: 0.1,
		// ease: "power4.inOut"
	} 


	const tlAboutPolygonColourDelay = .5;
	const tlAboutPolygonColour = gsap.timeline({repeat:-1});
	tlAboutPolygonColour
		.to(svgAboutPolygon, { fill: '#F76B6A', duration: .1, stagger: tlAboutPolygonStagger, delay: tlAboutPolygonColourDelay  })
		.to(svgAboutPolygon, { fill: '#8AAAFD', duration: .1, stagger: tlAboutPolygonStagger, delay: tlAboutPolygonColourDelay })
		.to(svgAboutPolygon, { fill: '#E1FF67', duration: .1, stagger: tlAboutPolygonStagger, delay: tlAboutPolygonColourDelay })
		.pause();



	tlAbout
		.fromTo(svgAboutPolygonFirst, { opacity: 0 }, { opacity: 1, duration: .1, stagger: {each:0.06} })
		.fromTo(copyAbout, { fill: 'transparent' }, { fill: '#fff', duration: 1 }, '>-.1')
		.fromTo(svgAboutPolygonLast, { opacity: 0 }, { opacity: 1, duration: .1, stagger: { each: 0.06 } }, '>-.5')
		.to({}, { delay: tlAboutPolygonColourDelay })
		.call(function () { tlAboutPolygonColour.play() })
	

	*/




	// about page
	if ($('body').is('.about-us-page')) {

		const svgAboutPolygonFirst = document.querySelectorAll(".about-pinned-animation__image-background polygon.first");
		const svgAboutPolygonLast = document.querySelectorAll(".about-pinned-animation__image-background polygon.last");

		const copyAboutWrapper1 = document.querySelector(".about-pinned-animation__copy-block--1");
		const copyAboutWrapper2 = document.querySelector(".about-pinned-animation__copy-block--2");
		const copyAboutWrapper3 = document.querySelector(".about-pinned-animation__copy-block--3");

		const copyAbout1 = copyAboutWrapper1.querySelectorAll(".about-pinned-animation-copy__text");
		const copyAbout2 = copyAboutWrapper2.querySelectorAll(".about-pinned-animation-copy__text");
		const copyAbout3 = copyAboutWrapper3.querySelectorAll(".about-pinned-animation-copy__text");

		const tlAbout = gsap.timeline({
			scrollTrigger: {
				trigger: ".about-pinned-animation",
				start: "1px top",
				pin: true,
				refreshPriority: 1
			},
		});

		const tlAboutPolygonColourDelay = .5;
		const tlAboutPolygonStagger = { each: 0.06 };
		const tlAboutRepeatDelay = .1;

		tlAbout
			.to(svgAboutPolygonFirst, { fill: '#E1FF67', opacity: 1, duration: .1, stagger: tlAboutPolygonStagger, delay: tlAboutPolygonColourDelay })
			.fromTo(copyAbout1, { fill: 'transparent' }, { fill: '#fff', duration: 1 }, '>-.1')
			.to(svgAboutPolygonLast, { fill: '#E1FF67', opacity: 1, duration: .1, stagger: tlAboutPolygonStagger, delay: tlAboutPolygonColourDelay }, '>-1')
			.to({}, { delay: tlAboutRepeatDelay })
			.call(function () { tlAboutRepeat.play() })


		const tlAboutRepeat = gsap.timeline({ repeat: -1 });
		tlAboutRepeat

			.to(svgAboutPolygonFirst, { fill: '#F76B6A', duration: .1, stagger: tlAboutPolygonStagger, delay: tlAboutPolygonColourDelay })

			.set(copyAboutWrapper1, { zIndex: 2 })
			.set(copyAboutWrapper2, { zIndex: 1, opacity: 1 })
			.set(copyAboutWrapper3, { zIndex: 0, opacity: 1 })
			.to(copyAboutWrapper1, { opacity: 0, duration: .3 })
			.fromTo(copyAbout2, { fill: 'transparent' }, { fill: '#fff', duration: 1 }, '>-.1')

			.to(svgAboutPolygonLast, { fill: '#F76B6A', duration: .1, stagger: tlAboutPolygonStagger, delay: tlAboutPolygonColourDelay }, '>-1')
			.to({}, { delay: tlAboutRepeatDelay  })


			.to(svgAboutPolygonFirst, { fill: '#8AAAFD', duration: .1, stagger: tlAboutPolygonStagger, delay: tlAboutPolygonColourDelay })

			.set(copyAboutWrapper2, { zIndex: 2 })
			.set(copyAboutWrapper3, { zIndex: 1, opacity: 1 })
			.set(copyAboutWrapper1, { zIndex: 0, opacity: 1 })
			.to(copyAboutWrapper2, { opacity: 0, duration: .3 })
			.fromTo(copyAbout3, { fill: 'transparent' }, { fill: '#fff', duration: 1 }, '>-.1')

			.to(svgAboutPolygonLast, { fill: '#8AAAFD', duration: .1, stagger: tlAboutPolygonStagger, delay: tlAboutPolygonColourDelay }, '>-1')
			.to({}, { delay: tlAboutRepeatDelay  })


			.to(svgAboutPolygonFirst, { fill: '#E1FF67', duration: .1, stagger: tlAboutPolygonStagger, delay: tlAboutPolygonColourDelay })

			.set(copyAboutWrapper3, { zIndex: 2 })
			.set(copyAboutWrapper1, { zIndex: 1, opacity: 1 })
			.set(copyAboutWrapper2, { zIndex: 0, opacity: 1 })
			.set(copyAbout1, { fill: 'transparent' })
			.to(copyAboutWrapper3, { opacity: 0, duration: .3 })
			.fromTo(copyAbout1, { fill: 'transparent' }, { fill: '#fff', duration: 1 }, '>-.1')

			.to(svgAboutPolygonLast, { fill: '#E1FF67', duration: .1, stagger: tlAboutPolygonStagger, delay: tlAboutPolygonColourDelay }, '>-1')
			.to({}, { delay: tlAboutRepeatDelay  })


			.pause();


	}



	/* not in use, belongs to fullsize panel with graphic devices 
	const copyHome = document.querySelectorAll(".home-scrolled-animation-copy__text");
	const copyHomeP = document.querySelectorAll(".home-scrolled-animation-copy p");
	const tlHomeScrolled = gsap.timeline({
		scrollTrigger: {
			trigger: ".home-scrolled-animation-copy",
			start: "top center",
		}
	});
	tlHomeScrolled

		.fromTo([copyHome, copyHomeP], { yPercent: 20, opacity: 0 }, { yPercent: 0, opacity: 1, duration: .5, stagger: .33 })
		.fromTo(copyHome, { fill: 'transparent' }, { fill: '#fff', duration: 1 }, '>-.25')
	*/




	if ($('body').is('.career-page')) {

		const copyCareers = document.querySelector(".careers-scrolled-animation__copy-wrapper");
		const imageCareers = document.querySelector(".careers-scrolled-animation__image-background");

		const tlCareersScrolled2 = gsap.timeline({
			scrollTrigger: {
				trigger: ".careers-scrolled-animation",
				start: "top top",
				scrub: true
			}
		});
		tlCareersScrolled2.fromTo(imageCareers, { yPercent: -50 }, { yPercent: -20 })


		const tlCareersScrolled = gsap.timeline({
			scrollTrigger: {
				trigger: ".careers-scrolled-animation",
				start: "top top",
				scrub:true
			}
		});
		tlCareersScrolled.fromTo(copyCareers, { top: '50%', yPercent: 0 }, { top: '50%', yPercent: 100 });

		gsap.set(copyCareers, { top: '130%'});
		gsap.to(copyCareers, { top: '50%', duration: 1, ease: 'Power1.easeOut' });

		/*	
		$(window).on('load', function () {
		
			const tlCareersBeforeScrolled = gsap.timeline({})
			if ($(window).scrollTop() === 0) {
				tlCareersBeforeScrolled.fromTo(copyCareers, { top: '105%', yPercent:100 }, { top: '50%', yPercent:0, duration: 1, ease: 'Power1.easeInOut' })
			}

			const tlCareersScrolled = gsap.timeline({
				scrollTrigger: {
					trigger: ".careers-scrolled-animation",
					start: "20% top",
					toggleActions: "play none none reverse",
				}
			});
			tlCareersScrolled.fromTo(copyCareers, { top: '50%', yPercent: 0 }, { top: '105%', yPercent: 100, duration: .75, ease: 'Power1.easeInOut' });
			// tlCareersScrolled.fromTo(copyCareers, { top: '50%' }, { top: '-10%', duration: .5, ease: 'Power1.easeInOut' })
		})
		*/
	
	/*
	$(window).on('load', function () {

		const tlCareersBeforeScrolled = gsap.timeline({})
		if ($(window).scrollTop() === 0) {
			tlCareersBeforeScrolled.fromTo(copyCareers, { top: '120%' }, { top: '50%', duration: 1, ease: 'Power1.easeInOut' })
		}

		const tlCareersScrolled = gsap.timeline({
			scrollTrigger: {
				trigger: ".careers-scrolled-animation",
				start: "top top",
				toggleActions: "play none none reverse",
				scrub:.1
			}
		});
		tlCareersScrolled.fromTo(copyCareers, { top: '50%' }, { top: '130%', duration: 1, ease: 'sine.easeInOut' })
		})
	*/



		// tlCareersScrolled.fromTo(copyCareersContainer, { yPercent: -50 }, { yPercent: -100, duration: .5, ease: 'power1.easeIn' }, '>-.5')
		// .fromTo(copyHome, { fill: 'transparent' }, { fill: '#fff', duration: 1 }, '>-.25')



		// gsap.utils.toArray(".comparisonSection").forEach(section => {
		/*
			let tl = gsap.timeline({
				scrollTrigger: {
					trigger: ".about-pinned-animation__image-wrapper",
					// start: "center center",
					start: "top top",
					// end: "+=100%",
					// makes the height of the scrolling (while pinning) match the width, thus the speed remains constant (vertical/horizontal)
					// end: () => "+=" + section.offsetWidth,
					markers: true,
					scrub: true,
					pin: true,
					anticipatePin: 1
				},
				defaults: { ease: "none" }
			});
			*/

		/*
		// animate the container one way...
		tl.fromTo(section.querySelector(".afterImage"), { xPercent: 100, x: 0 }, { xPercent: 0 })
			// ...and the image the opposite way (at the same time)
			.fromTo(section.querySelector(".afterImage img"), { xPercent: -100, x: 0 }, { xPercent: 0 }, 0);
			*/
		// });
	}




    // gsap.to('#test-id', { opacity:.3});
    // console.log('test on DOMready');

	/*
	var scene = new ScrollMagic.Scene({
		triggerElement: "#test-container"
	})
	.setTween("#test-id", 0.5, { backgroundColor: "green", scale: 2.5 }) // trigger a TweenMax.to tween
	// .addIndicators({ name: "1 (duration: 0)" }) // add indicators (requires plugin)
	.addTo(controller);
	*/





	/* NOT IN USE ANYMORE
	
	gsap.set(".home-fifty-fifty__column-content", { yPercent: 35, opacity: 0 });

	ScrollTrigger.batch(".home-fifty-fifty__column-content", {
		start: "top 70%",
		onEnter: function (batch) { gsap.to(batch, { yPercent: 0, opacity: 1, stagger: { each: 0.35 }, overwrite: true }) }
	});

	*/




})


;
function fetchJobData(request) {
    const postRequest = new XMLHttpRequest();

    postRequest.open('POST', '/umbraco/surface/careers/fetch', true);
    postRequest.setRequestHeader('Content-Type', 'application/json');

    postRequest.onreadystatechange = function receiveResponse() {
        if (this.readyState === 4) {
            removeJobs()
            if (this.status === 200) {
                const response = JSON.parse(this.response);
                addNewJobs(response.Jobs)
                updatePagination(response)
                document.getElementById("job-count").innerHTML = response.JobTotal
            }
        }
    };
    
    postRequest.send(JSON.stringify(request));
}

function removeJobs() {
    document.querySelectorAll(".c-link-explorer__card").forEach(el => el.remove());
    document.getElementById("job-count").innerHTML = "0"
}

function updatePagination(paginationData) {

    const paginationContainer = document.querySelector(".c-link-explorer__pagination")

    paginationContainer.innerHTML = '';

    if (paginationData.DisplayPagination) {

        // Prev pagination link
        const prevPageLink = paginationData.PreviousPaginationLink;
        const previousPageLinkEl = document.createElement("a");
        previousPageLinkEl.className = "mr-3 c-cta-link c-cta-link--with-chevron-left";
        previousPageLinkEl.appendChild(document.createTextNode(prevPageLink.Title));
        if (prevPageLink.IsDisabled) {
            previousPageLinkEl.classList.add("disabled")
        }
        paginationContainer.appendChild(previousPageLinkEl)

        // Numbered pagination links
        paginationData.PagePaginationLinks.forEach(function (paginationLink) {
            let paginationLinkEl = document.createElement("a");
            paginationLinkEl.className = "c-link-explorer__pagination-page";
            if (paginationLink.IsCurrent) {
                paginationLinkEl.classList.add("c-link-explorer__pagination-page--current")
            }
            paginationLinkEl.appendChild(document.createTextNode(paginationLink.Title));
            paginationContainer.appendChild(paginationLinkEl)
        })

        // Next pagination link            
        const nextPageLink = paginationData.NextPaginationLink;
        const nextPageLinkEl = document.createElement("a");
        nextPageLinkEl.className = "mr-3 c-cta-link c-cta-link--with-chevron-right";
        nextPageLinkEl.appendChild(document.createTextNode(nextPageLink.Title));
        if (nextPageLink.IsDisabled) {
            nextPageLinkEl.classList.add("disabled")
        }

        paginationContainer.appendChild(nextPageLinkEl)
    }

}

function addNewJobs(jobs) {

    const heading = document.querySelector(".c-link-explorer__listing")

    jobs.reverse().forEach(function (job) {

        const article = document.createElement("article")
        article.className = "col-12 col-sm-6 col-md-4 col-lg-3 c-link-explorer__card";

        const link = document.createElement("a");
        link.href = job.Link;
        link.className = "c-link-explorer__card-link";

        const div = document.createElement("div");
        div.className = "c-link-explorer__card-content";

        const title = document.createElement("h4");
        title.className = "c-link-explorer__card-title";
        title.appendChild(document.createTextNode(job.Title));

        const location = document.createElement("p");
        const node = document.createTextNode(job.Location);
        location.appendChild(node);

        article.appendChild(link);
        link.appendChild(div)
        div.appendChild(title)
        div.appendChild(location)

        heading.parentNode.insertBefore(article, heading.nextSibling);
    })
};

// helper to debounce window resize
$.fn.resized = function (callback, timeout) {
    $(this).resize(function () {
        var $this = $(this);
        if ($this.data('resizeTimeout')) {
            clearTimeout($this.data('resizeTimeout'));
        }
        $this.data('resizeTimeout', setTimeout(callback, timeout));
    });
};

$(function () {
    // cards carousel: news, insights, team
    $('.c-group-carousel').each(function () {
        var $prev = $(this).parents('.o-section').find('.c-group-carousel-prev');
        var $next = $(this).parents('.o-section').find('.c-group-carousel-next');

        $(this).slick({
            infinite: false,
            slidesToShow: 3,
            slidesToScroll: 3,
            rows: 0,

            prevArrow: $prev,
            nextArrow: $next,

            responsive: [
                {
                    breakpoint: 992,
                    settings: {
                        slidesToShow: 2,
                        slidesToScroll: 2,
                        arrows: false
                    }
                },
                {
                    breakpoint: 575,
                    settings: {
                        slidesToShow: 1,
                        slidesToScroll: 1
                    }
                }
            ]
        });
    });



    $('.c-single-carousel__wrapper').each(function () {
        var $prev = $(this).parents('.o-section').find('.c-group-carousel-prev');
        var $next = $(this).parents('.o-section').find('.c-group-carousel-next');

        $(this).slick({
            infinite: false,
            slidesToShow: 1,
            slidesToScroll: 1,
            rows: 0,
            dots: true,
            adaptiveHeight: true,

            prevArrow: $prev,
            nextArrow: $next,
        });
    });


    $('.c-vertical-carousel__wrapper').each(function () {

        // resizeVerticalCarousel($(this));
        

        /* 
        var allCards = $(this).find('.c-vertical-carousel__card');

        var heights = allCards.map(function () {
            return $(this).outerHeight()+25;
        }).get();

        console.log(heights)

        allCards.css('height', Math.max.apply(null, heights));
        */



        var $prev = $(this).parents('.o-section').find('.c-group-carousel-prev');
        var $next = $(this).parents('.o-section').find('.c-group-carousel-next');

        $(this).slick({
            infinite: false,
            slidesToShow: 1,
            slidesToScroll: 1,
            rows: 0,
            dots: true,
            // adaptiveHeight: true,
            vertical: true,
            verticalSwiping: true,
            arrows: false,
            autoplay: true,
            autoplaySpeed: 2000,
            prevArrow: $prev,
            nextArrow: $next,

            responsive: [
                {
                  breakpoint: 1200,
                  settings: {
                    slidesToShow: 1,
                    slidesToScroll: 1,
                    arrows: true,
                    vertical: false,
                    verticalSwiping: false,
                  }
                }
              ]
        });

        $(this).on('beforeChange', function (event, slick, currentSlide, nextSlide) {
            var carousel = $(this).parents('.o-vertical-carousel');

            carousel.removeClass(function (index, css) {
                return (css.match(/(^|\s)o-section--bg-\S+/g) || []).join(' ');
            }).addClass('o-section--bg-' + $(this).find('.slick-slide').eq(nextSlide).data('slide-class'));

            // console.log('o-section--bg-' + $(this).find('.slick-slide').eq(nextSlide).data('slide-class'), nextSlide);
        });

        /*
        $(this).on('afterChange', function (event, slick, currentSlide, nextSlide) {

            var wrapper = $(this).find('.slick-list');

            var height = $(this).find('.slick-slide').eq(currentSlide).outerHeight() + 25;
            console.log(height);
            setTimeout(function () { wrapper.height(height) }, 1000);
        });
        */
    });

    /*
    var windowResizeTimer;

    $(window).on('resize', function (e) {

        clearTimeout(windowResizeTimer);
        windowResizeTimer = setTimeout(function () {
            $('.c-vertical-carousel__wrapper').each(function () { resizeVerticalCarousel($(this))})
        }, 250);

    });
    */


    $(window).on('load', resizeAllVerticalCarousels);
    $(window).resized(resizeAllVerticalCarousels, 250);

    function resizeAllVerticalCarousels() {
        $('.c-vertical-carousel__wrapper').each(function () { resizeVerticalCarousel($(this)) })
    }

    function resizeVerticalCarousel($carousel) {
        // console.log('resized')
        var allCards = $carousel.find('.c-vertical-carousel__card');
        allCards.css('height', 'auto');

        var heights = allCards.map(function () {
            return $(this).outerHeight() + 25;
        }).get();

        allCards.css('height', Math.max.apply(null, heights));
    }

});


;

$(function() {
	$('.c-form__input-wrapper--checkbox input[type="checkbox"] + label').on('keypress', function(event){
		const input = $('.c-form__input-wrapper--checkbox input[type="checkbox"]')[0];
		if (event.which === 13 || event.which === 32) {
			input.checked = !input.checked;
		  }
	})
})
;
// const { default: ar } = require("../Umbraco/lib/flatpickr/l10n/ar");

$(function () {

    var mainNavbar = document.querySelector(".o-glb-header");

    var headroom = new Headroom(mainNavbar, {
        offset: 205,
        tolerance: 5,
    });
    headroom.init();

    function closeSubMenus() {
        $('.megamenu').parent('li').find('button').attr("aria-expanded", false);
    }

    $('.mobile-trigger').on('click', function () {
        var btn = $(this);
        if (btn.attr("aria-expanded") == 'true') {
            btn.attr("aria-expanded", false);
            document.body.classList.remove('mobile-menu-expanded');
        }
        else {
            btn.attr("aria-expanded", true);
            document.body.classList.add('mobile-menu-expanded');
        }
    })

    // $('.megamenu').parent('li').find('button').on('click', function () {
    $('.megamenu-toggle').on('click', function () {
        var btn = $(this).is('.megamenu-toggle--mobile') ? $('.megamenu-toggle').eq(0) : $(this);
        if (btn.attr("aria-expanded") == 'true') {
            btn.attr("aria-expanded", false);
            document.body.classList.remove('megamenu-expanded');
        }
        else {
            btn.attr("aria-expanded", true)
            document.body.classList.add('megamenu-expanded');
        }
    })

    $('.o-glb-header__megamenu-overlay').on('click', function () {
        $('.megamenu-toggle').eq(0).trigger('click');
    })

    $('.submenu-trigger').on('click', function () {
        var btn = $(this);
        if (btn.attr("aria-expanded") == 'true') {
            btn.attr("aria-expanded", false);
        }
        else {
            btn.attr("aria-expanded", true);
        }
    })
});

$(function () {

	gsap.registerPlugin(ScrollTrigger);

	ScrollTrigger.defaults({
		markers:false
	})


	// stats
	const items = document.querySelectorAll(".stat__number");
	if (items.length) {

		gsap.from(items, {
			textContent: 0,
			duration: 3,
			ease: "power1.in",
			snap: { textContent: 1 },
			stagger: {
				each: 0.5,
				onUpdate: function () {
					this.targets()[0].innerHTML = numberWithCommas(Math.ceil(this.targets()[0].textContent));
				},
			},
			scrollTrigger: {
				trigger: items,
				start: "top 70%",
				refreshPriority: 0
			}
		});


		function numberWithCommas(x) {
			return x.toString().replace(/\B(?=(\d{3})+(?!\d))/g, ",");
		}
	}


	// img-dynamic
	let images = Array.prototype.slice.call(document.querySelectorAll('.c-img-dynamic:not(.c-img-dynamic--no-js)'))

	if (images.length) {
		images.forEach(function (image) {

			const graphicDevices = image.querySelectorAll(".c-img-dynamic__graphic-device-inner")

			let tl = gsap.timeline({
				scrollTrigger: {
					trigger: image,
					start: "top 70%",
					refreshPriority: 0
				},
			});

			tl.fromTo(image.querySelector(".c-img-dynamic__image"), { yPercent: 35, opacity: 0 }, { yPercent: 0, opacity: 1, duration: .75 })


			if (graphicDevices.length) {
				tl.fromTo(graphicDevices[0], { height: 0 }, { duration: .5, height: "auto" }, ">-0.25")
				if (graphicDevices.length > 1) {
					tl.fromTo(graphicDevices[1], { height: 0 }, { duration: .5, height: "auto" }, ">-0.25")
				}
			}

		});
	}

	// product collection
	if (document.querySelectorAll(".c-product-collection__card").length) {
		gsap.set(".c-product-collection__card", { yPercent: 35, opacity: 0 });

		ScrollTrigger.batch(".c-product-collection__card", {
			start: "top 80%",
			onEnter: function (batch) { gsap.to(batch, { yPercent: 0, opacity: 1, stagger: { each: 0.2 }, overwrite: true }) }
		});
	}




	$('.scroll-to-anchor').on('click', function (e) {
		e.preventDefault();
		let $target = $($(this).attr('href'));

		if ($target.length) {
			let targetTop = $target.offset().top - 90;

			var scrollDuration = ($(this).is('.scroll-to-anchor--slow')) ? 2 : 0.75;

			gsap.to(['html', 'body'], { scrollTop: targetTop, duration: scrollDuration });
		} else {
			console.log('Anchor target not present in the document')
		}
	})
})


;
// GA Tracking

window.dataLayer = window.dataLayer || [];
function gtag() { dataLayer.push(arguments); }
gtag('js', new Date());

gtag('config', 'UA-184159775-1');

// Pardot tracking

piAId = '823433';
piCId = '';
piHostname = 'digital.geniussports.com';

(function () {
	function async_load() {
		var s = document.createElement('script'); s.type = 'text/javascript';
		s.src = ('https:' == document.location.protocol ? 'https://' : 'http://') + piHostname + '/pd.js';
		var c = document.getElementsByTagName('script')[0]; c.parentNode.insertBefore(s, c);
	}
	if (window.attachEvent) { window.attachEvent('onload', async_load); }
	else { window.addEventListener('load', async_load, false); }
})();

;
