$(document).ready(function() {

			$('.match-height').matchHeight();
	
			$(".menu-toggle").click(function (e) {

				$(".mobile-menu").toggleClass("open");
				e.preventDefault();

			});

			$(".menu-close").click(function (e) {

				$(".mobile-menu").removeClass("open");
				e.preventDefault();

			});

			$(".mobile-menu li a").click(function (e) {

				if (/*isMobile ||*/ $(window).width() <= 880) {
					$(".mobile-menu").removeClass("open");
					//e.preventDefault();

				}
			});
			
			$("#applicationform").click(function (e) {
				fbq('track', "Lead");
			});
			
			
			
			$(".apply-now").click(function (e) {
			
				var href = $(this).attr("href");
				var logged = trackApplicationFormDownload(href)
				
			});
			
			$(".apply-now-inline").click(function (e) {
			
				var href = $(this).attr("href");
				var logged = trackApplicationFormDownload(href)
				
			});


    //Play HTML5 Video
	$(".play-page-video").click(function (e) {

		var t = $(this);
		var tID = t.attr("data-id");
		var video;

		if (tID != null && typeof tID != "undefined") {
			t.hide();
			video = document.getElementById(tID);
			AM_PlayVideo(video);
		}

		e.preventDefault();
	});
    //
			
	$(".video-carousel-inner").slick({
	    autoplay: false,
	    arrows: true,
	    dots: true
	})
	
	// Carousel Set for testimonials
	//
	$('.testimonial-carousel').slick({
		arrows: true,
        dots: true,
        autoplay: false,
		appendDots: $('.carousel-nav')
		
	});
	
	





	$(".video-carousel-inner").each(function () {

		var _this = $(this);
		//He we need to check if a video was being played before the carousel slides moves on
		//
		_this.on('beforeChange', function (event, slick, currentSlide, nextSlide) {

			var thisSlide = _this.find(".slick-active")
			var videocontainer = thisSlide.find(".video-container");
			if (videocontainer != null && typeof videocontainer != "undefined" && videocontainer.length > 0) {

				//There is a video of some description
				//
				if (videocontainer.children("iframe").length > 0) {
					//YouTube/Vimeo. Take src out and then re-add to refresh the player iframe.
					//
					var iframeSrc = videocontainer.children("iframe").attr("src");
					videocontainer.children("iframe").attr("src", "");
					videocontainer.children("iframe").attr("src", iframeSrc);
				} else {
					//HTML5
					var videoid = videocontainer.children("video").attr("id");
					var restartVideo = document.getElementById(videoid);
					setTimeout(function () {
						AM_RestartVideo(videoid);
					}, 500);

					//$(".play-page-video[data-id=" + video + "]").show();
				}

			}

		});

	});








	
});

	$(document).on("click", ".accordion-item h3", function (e) {

		var t = $(this).parent(".accordion-item");
		t.toggleClass("active");
		t.children(".accordion-text").slideToggle(500);

		e.preventDefault();
		
	});





$(window).resize(function(){
	
			if ($(window).width() > 767) {
				$(".mobile-menu").removeClass("open");

			}
			else {
			}

	
});


function trackApplicationFormDownload(u) {

	gtag('event', 'conversion', {
		'send_to': 'AW-940170939/3XfoCJ6z0JYBELu9p8AD',
		'event_callback': u
	});
	//console.log(u);
	return u;

}


function SetPageColour(colour) {
    $("body").addClass(colour);
}
function SetHomeFooter(classes) {
    $("footer").addClass(classes);
}
function MatchHeightEndorsers(){
    $(".endorser").matchHeight({ byRow: true});
}

function AM_PlayVideo(video) {

    //Function that plays a HTML5 video when the play button is clicked
    //
    //Add the controls to the video and start playing.
    video.setAttribute("controls", "controls");
    video.play();
}

function AM_RestartVideo(video) {

    //Function that restarts the video once it has finished playing.
    //
    //Once the video as finished reload it so it can be played again.
    var restartVideo = document.getElementById(video);
    restartVideo.removeAttribute("controls");
    restartVideo.load();
    $(".play-page-video[data-id=" + video + "]").show();
}

function AM_RestartAllVideos() {

    //Function that loops through each video on the page that is NOT a background video, and stops them playing and reloads ready to play again.
    //
    $("video.video-html5").each(function () {
        $(this)[0].load();
        $(this)[0].removeAttribute("controls");
        $(this).prev(".play-page-video").show();
    });

}