jQuery(function ($) {
	if($('body.page-id-25').length) {
		gsap.registerPlugin(ScrollTrigger);

		function initSticky() {
			ScrollTrigger.getById('heroImagePin')?.kill();

			const $pin = $('.box-1 .col-2');
			const $end = $('.box-2 .row');
			if (!$pin.length || !$end.length) return;

			const $row = $pin.closest('.row');
			$row.css('min-height', $('img', $pin).outerHeight());

			ScrollTrigger.create({
				id: 'heroImagePin',
				trigger: $pin[0],
				pin: true,
				start: "top top",
						end: () => {
					const pinTop     = $pin.offset().top;
					const pinH       = $pin.outerHeight();
					const endBottom  = $end.offset().top + $end.outerHeight();
					return "+=" + Math.max(0, endBottom - pinTop - pinH);
				},
				scrub: 0.5,
				anticipatePin: 1,
				invalidateOnRefresh: true,
				pinSpacing: true,
				pinReparent: true
			});
		}

		$(window).on('load', initSticky);

		$(window).on('resize orientationchange', () => ScrollTrigger.refresh());
	}
});

jQuery(function ($) {
    if (!$('body').hasClass('page-id-47')) return;

    const $body = $('body');

    $body.on('click', '.tile .tile--wrapper .tile--btn', function (e) {
        e.preventDefault();
        $body.addClass('no-scroll');

        const $tile = $(this).closest('.tile');
        const $sidebar = $tile.find('.tile-sidebar');

        $('.tile').not($tile).removeClass('active')
                  .find('.tile-sidebar').fadeOut(200);

        $sidebar.fadeToggle(200);
        $tile.toggleClass('active');
    });

    $body.on('click', '.tile .tile-sidebar .tile--btn, .tile .tile-sidebar-bg', function (e) {
        e.preventDefault();
        $body.removeClass('no-scroll');
        $(this).closest('.tile-sidebar').fadeOut(200)
               .closest('.tile').removeClass('active');
    });
});
