$(document).ready(function () {

  // Responsive tables
  $('table').basictable({
      breakpoint: 768,
  });

  // Navigation Functionality & Accessibility
  $('.header__navbar__right__search-and-mainnav > .nav-icon').attr('aria-expanded', 'false');

  //Navigation Tab Loop
  $('.header__navigation-content .col--cta > li:last > a').keydown(function (e) {
    var code = e.keyCode || e.which;
    if (code == 9) {
      $('.header__navbar__right__search-and-mainnav > .nav-icon').focus();
    }

    e.preventDefault();
    return false;
  });

  // Used to determine scroll position when menu is opened on mobile views
  var $bodyScrollTop = 0;

  $('.header__navbar__right__search-and-mainnav > .nav-icon').click(function (e) {
    // Scroll to top if on large screens and user has scrolled past top of page
    if (currentScrollLocation > 0 && window.innerWidth > 1023) {
      window.scrollTo(0, 0);
    }

    //Cast Overlay
    $('.overlay').toggleClass('js-active js-nav-active');

    // On large screens, disable section navigation
    if (window.innerWidth > 1023) {
      if ($(this).hasClass('js-expanded')) {
        $('.section-nav').css('display', 'block');
        $('.header__navbar.blend-overlay').removeClass('js-fadeOut');
        $('.header__navbar.blend-overlay > .multiple-blend-overlay').removeClass('js-hidden');
      }
      else {
        $('.header__navbar.blend-overlay').addClass('js-fadeOut');
        $('.section-nav').css('display', 'none');
        $('.header__navbar.blend-overlay > .multiple-blend-overlay').addClass('js-hidden');
      }
    }
    else {
      if (window.innerWidth >= 700) {
        if ($(this).hasClass('js-expanded') && currentScrollLocation <= 25) {
          $('.header__navbar.blend-overlay').removeClass('js-fadeOut');
          $('.section-nav').fadeIn(200, function () {
            $(this).css('display', 'block');
          });
        }
        else {
          $('.header__navbar.blend-overlay').addClass('js-fadeOut');
          $('.section-nav').fadeOut(200, function () {
            $(this).css('display', 'none');
          });
        }
      }
      if (window.innerWidth < 700) {
        // Toggle Navigation Backgrounds
        if ($(this).hasClass('js-expanded')) {
          $('.header__navbar.blend-overlay').removeClass('js-fadeOut');
          $('.header__navbar.blend-overlay > .multiple-blend-overlay').removeClass('js-hidden');

          $('#main-content').removeAttr('style');
        }
        else {
          $bodyScrollTop = $(window).scrollTop();
          $('.header__navbar.blend-overlay').addClass('js-fadeOut');
          $('.header__navbar.blend-overlay > .multiple-blend-overlay').addClass('js-hidden');

          $('#main-content').css({
            'position': 'relative',
            'top': -($bodyScrollTop)
          });
        }

        // Show / Hide Section Nav
        if ($(this).hasClass('js-expanded') && currentScrollLocation <= 25) {
          $('.section-nav').css('display', 'block');
        }
        else {
          $('.section-nav').css('display', 'none');
        }
      }
    }

    // Accessibility
    if ($(this).hasClass('js-expanded')) {
      $(this).attr('aria-expanded', 'false');
    }
    else {
      $(this).attr('aria-expanded', 'true');
    }

    // Collapse all navigation items on close / Scroll to top of navigation
    if ($(this).hasClass('js-expanded') && $(window).innerWidth() < 1024) {
      $('.header__navigation-content__inner').scrollTop(0);
      $('.header__navigation-content__inner .col button').each(function () {
        if ($(this).hasClass('js-active')) {
          $(this).attr('aria-expanded', 'false');
          $(this).removeClass('js-active');
          $(this).next().slideToggle(200);
          $(this).next().removeClass('js-expanded');
        }
      });
    }

    //Toggle classes
    $(this).toggleClass('js-expanded');
    $('body, html').toggleClass('js-fixed');

    if (window.innerWidth < 700 && !$(this).hasClass('js-expanded')) {
      window.scrollTo(0, $bodyScrollTop);
    }

    $('.header__navigation-content').toggleClass('js-expanded');
    $('.header').toggleClass('js-background');
    e.preventDefault();
  });

  // Add backgrounds if header is resized to medium screens
  $(window).on('load resize', function () {
    if ($(window).innerWidth() < 1024) {
      $('.header__navbar.blend-overlay').removeClass('js-fadeOut');
      $('.header__navbar.blend-overlay > .multiple-blend-overlay').removeClass('js-hidden');
    }
  });

  //Expand Sections on medium and small screens - accessibility & Functionality
  $(window).on('load resize', function () {
    if ($(window).innerWidth() < 1024) {
      if ($('.header__navigation-content .title > button').hasClass('js-expanded')) {
        $('.header__navigation-content .title > button').attr('aria-expanded', 'true');
      }
      else {
        $('.header__navigation-content .title > button').attr('aria-expanded', 'false');
      }
    }
    else { //Desktop view - Remove all aria states and display all sections
      $('.header__navigation-content .title > button').removeAttr('aria-expanded');
      $('.header__navigation-content .title > ul').removeAttr('style');
      $('.header__navigation-content .title > ul').removeClass('js-expanded');
    }
  });

  $('.header__navigation-content .title > button').click(function () {
    var ul = $(this).next('ul');
    if ($(ul).hasClass('js-expanded')) {
      $(this).attr('aria-expanded', 'false');
      $(this).removeClass('js-active');
    }
    else {
      $(this).attr('aria-expanded', 'true');
      $(this).addClass('js-active');
    }
    $(ul).slideToggle(200);
    $(ul).toggleClass('js-expanded');
  });

  // Show / Hide Search Nav
  $('.search-icon').click(function () {
    $('.search-overlay').addClass('js-active');
    $('.search-field').addClass('js-visible');
    $('body, html').addClass('js-fixed-search');
    $('.search-field__centered-content > form > input').focus();
    $('body').scrollTop(0);
  });

  $('.search-exit-button').click(function () {
    $('.search-overlay').removeClass('js-active');
    $('body').toggleClass('js-fixed-search');
    $('.search-field').removeClass('js-visible');
    $('body, html').removeClass('js-fixed-search');
    $('.search-icon').focus();
  });

  //Search Tab Loop
  $('.search-field__centered-content > form > input').keydown(function (e) {
    var code = e.keyCode || e.which;
    if (code == 9) {
      $('.search-overlay__inner > .search-exit-button').focus();
      e.preventDefault();
      return false;
    }

  });

  // Show / Hide Section Navigation When Beyond Top of Screen
  $(window).on('load scroll', function () {
    if (!$('.search-overlay').hasClass('js-active')) {
      if ($(window).scrollTop() <= 25 && !$('.header__navbar__right__search-and-mainnav > .nav-icon').hasClass('js-expanded')) {
        $('.section-nav').fadeIn(200, function () {
          $(this).css('display', 'block');
        });
      }
      else {
        $('.section-nav').fadeOut(200, function () {
          $(this).css('display', 'none');
        });

        //Close Section Nav dropdown if open
        if ($('.section-nav__button').hasClass('js-active')) {
          $('.section-nav__expand').slideUp(200);
          $('.section-nav__button').attr('aria-expanded', 'false');
          $('.section-nav__button').removeClass('js-active');
        }
      }
    }
  });

  // Section Navigation Functionality and Accessibilty
  // Initial Section Nav state
  $('.section-nav__button').attr('aria-expanded', 'false');

  $('.section-nav__button').click(function () {
    if ($(this).hasClass('js-active')) {
      $(this).removeClass('js-active')
        .attr('aria-expanded', 'false');
      $('.section-nav__expand').slideUp(200);
      $('body').removeClass('js-fixed');
    }
    else {
      $(this).addClass('js-active')
        .attr('aria-expanded', 'true');
      $('.section-nav__expand').slideDown(200);
      $('body').addClass('js-fixed');
    }
  });

  $('.section-nav__expand button').attr('aria-expanded', 'false');

  $('.section-nav__expand button').click(function () {
    if ($(this).hasClass('js-active')) {
      $(this).removeClass('js-active')
        .attr('aria-expanded', 'false');
      $(this).next('ul').slideUp(200);
    }
    else {
      $(this).addClass('js-active')
        .attr('aria-expanded', 'true');
      $(this).next('ul').slideDown(200);
    }
  });

  //Section Nav Tab Loop
  $('.section-nav__expand li:last > a').keydown(function (e) {

    var code = e.keyCode || e.which;
    if (code == 9) {
      $('.section-nav__button').focus();
    }

    e.preventDefault();
    return false;
  });

  function outsideClick(e) {
    if (!$(e.target).closest('.section-nav__expand').length &&
      !$(e.target).closest('.section-nav__button').length) {
        if ($('.section-nav__button').hasClass('js-active')) {
          $('.section-nav__button').click();
        }
    }
  }

  $(document).on('click', outsideClick);

  // Listing and Filter Pages - Accessibiity and Keyboard Functionality
  $('.filter--show-more').keydown(function (e) {

    var code = e.keyCode || e.which;
    if (code == 13) {
      $('.filter--show-more').click();
    }

    e.preventDefault();
    return false;
  });

  // Hide Navigation on Scroll Down, Show on Scroll Up
  var currentScrollLocation = $(window).scrollTop();
  $(window).scroll(function () {
    setInterval(function () {
      if (!$('.search-overlay').hasClass('js-active')) {
        if ($(window).scrollTop() < (currentScrollLocation - 85)) {
          $('.header > .header__navbar').removeClass('js-visually-hidden');
          currentScrollLocation = $(window).scrollTop();
        }
        if ($(window).scrollTop() > (currentScrollLocation + 85)) {
          if (!($('.header__navigation-content').hasClass('js-expanded'))) { //Prevents scroll up on small screen sizes
            $('.header > .header__navbar').removeClass('js-background');
            $('.header > .header__navbar').addClass('js-visually-hidden');

          }
          currentScrollLocation = $(window).scrollTop();
        }
      }
    }, 1000);
  });

  // Footer Scroll To Top
  $('.footer__back-to-top').click(function () {
    $('html, body').animate({
      scrollTop: 0
    }, 200, function () {
      $('.header .logo > .logo__item').focus();
    });
  });

  // Navigation Background Injection based on Hero Image
  $(window).on('load resize begin', function () {
    // Large Screen Sizes
    var isIE11 = !!window.MSInputMethodContext && !!document.documentMode;

    if (isIE11 === false && $('.hero__picture').length) {
      var imgSource;
      //Large Screen Sizes
      if (window.innerWidth > 1023) {
        imgSource = $('.hero__picture :nth-child(3)').attr('srcset');
      }

      // Medium Screen Sizes
      if (window.innerWidth < 1024 && window.innerWidth >= 700) {
        imgSource = $('.hero__picture :nth-child(2)').attr('srcset');
      }

      if (window.innerWidth < 700) {
        imgSource = $('.hero__picture :nth-child(1)').attr('srcset');
      }
      $('.header__navbar > .multiple-blend-overlay').css('background', '#00447C url(' + imgSource + ')'); // $color-darkblue in variables.scss
      $('.section-nav__wrapper > .blend-container > .multiple-blend-overlay').css('background', '#e55c30 url(' + imgSource + ')'); // $color-orange in variables.scss
    }
  });

  // Load Custom Scrollbar Styles
  if ($(window).width() > 1024) {
    $(window).on('load', function () {
      $('.our-academics__list__inner').mCustomScrollbar({
        axis: 'x',
        mouseWheel: {
          enable: false
        },
        callbacks: {
          whileScrolling: function () {
            var scrollAmount = $(window).width() - $('#mCSB_1_dragger_horizontal').width();
            var final = (parseInt($('#mCSB_1_dragger_horizontal').css('left')) / scrollAmount) * 100;
            $('.mCSB_dragger_bar').css('left', final + '%');
          }
        }
      });

      setTimeout(function () {
        $('#mCSB_1').removeAttr('tabindex');
      }, 300);
    });
  }

  // Row of Three Slider on Med + Sm Screens
  var homeAcademics = {
    arrows: true,
    dots: false,
    infinite: false,
    mobileFirst: true,
    slidesToShow: 1,
    slidesToScroll: 1,
    responsive: [{
        breakpoint: 550,
        settings: {
          slidesToShow: 2,
          slidesToScroll: 2
        }
      },
      {
        breakpoint: 700,
        settings: {
          slidesToShow: 3,
          slidesToScroll: 2,
        }
      },
      {
        breakpoint: 1025,
        settings: 'unslick'
      }
    ]
  };

  // $('.our-academics__list__inner').slick(homeAcademics);

  // If only three items are present in carousel, unslick on large screen sizes
  $(window).on('load resize', function () {
    if (window.innerWidth > 1024) {
      if ($('.our-academics__list__inner').hasClass('slick-initialized')) {
        $('.our-academics__list__inner').slick('unslick');
      }
      return;
    }

    if (!$('.our-academics__list__inner').hasClass('slick-initialized')) {
      return $('.our-academics__list__inner').slick(homeAcademics);
    }
  });

  // Homepage Our Research overlay
  $('.our-research__team a').click(function (e) {
    $('body').addClass('research-visible');
    e.preventDefault();
  });

  $('.our-research__team--overlay__inner button').click(function () {
    $('body').removeClass('research-visible');
  });

  // Homepage Stories carousel
  var homeSettings = {
    mobileFirst: true,
    arrows: false,
    dots: true,
    slidesToShow: 1,
    infinite: false,
    responsive: [{
        breakpoint: 600,
        settings: {
          slidesToShow: 2,
        },
      },
      {
        breakpoint: 1025,
        settings: 'unslick',
      }
    ]
  };

  $(window).on('load resize', function () {
    var $homepageSliders = $('.home-stories__stories-wrap, .facts-container--homepage, .home:not(.lazy-load) .homepage-instagram__items')

    $homepageSliders.each(function(i, elem) {
      if (window.innerWidth > 1024) {
        if ($(elem).hasClass('slick-initialized')) {
          $(elem).slick('unslick');
        }
        return;
      }

      if (!$(elem).hasClass('slick-initialized')) {
        return $(elem).slick(homeSettings);
      }
    });
  });

  // Facts accessibility
  $('.fact').attr('tabindex', '0');

  // Video w/ Caption Functionality
  // Video Play
  $('.item-and-cap--video .play-video').click(function (e) {

    if ($(window).width() < 1025) {
      $('body').addClass('js-fixed');

      var el = $(e.target);
      var elOffset = el.offset().top;
      var elHeight = el.height();
      var windowHeight = $(window).height();
      var offset;

      if (elHeight < windowHeight) {
        offset = elOffset - ((windowHeight / 2) - (elHeight / 2));
      }
      else {
        offset = elOffset;
      }

      $('html, body').animate({
        scrollTop: offset
      }, 200);

      $('body > .overlay').addClass('js-active');
    }

    var container = $(this).parent();
    // Show video & play video
    $(container).find('iframe').addClass('visible');
    var response = $(container).find('iframe')[0].src += '?autoplay=1';
    // Disable overlay
    $(container).addClass('no-hover');

    e.preventDefault();
    return false;
  });

  // Video Stop
  $('.item-and-cap--video .close-video').click(function (e) {
    var container = $(this).parent();
    // Show video & play video
    $(container).find('iframe').removeClass('visible');

    var response = $(container).find('iframe')[0].src += '?autoplay=0';
    // Disable overlay
    $(container).removeClass('no-hover');

    $('body').removeClass('js-fixed');
    $('body > .overlay').removeClass('js-active');
    e.preventDefault();
    return false;
  });

  // Accordion Accessibiity and Functionality
  $('.accordion__content:not(.open-default)').css('display', 'none');
  // Individual item show/hide toggle
  $('.accordion__toggle').on('click keypress', function (e) {
    if (e.which === 13 || e.type === 'click') {
      if ($(this).hasClass('js-expanded')) {
        $(this).attr('aria-expanded', 'false').removeClass('js-expanded');
        $(this).next('.accordion__content').slideUp(200).attr('aria-hidden', 'true');
      }
      else {
        $(this).attr('aria-expanded', 'true').addClass('js-expanded');
        $(this).next('.accordion__content').slideDown(200).attr('aria-hidden', 'false');
      }
    }
  });

  // Expand All functionality
  $('.accordion--expand').on('click keypress', function (e) {
    if (e.which === 13 || e.type === 'click') {
      var accordionInQuestion = $(this).closest('.accordion');
      $(accordionInQuestion).children('.accordion__item').attr('aria-expanded', 'true');
      $(accordionInQuestion).find('.accordion__toggle').addClass('js-expanded');
      $(accordionInQuestion).find('.accordion__content').slideDown(200).attr('aria-hidden', 'false');
    }
  });

  // Collapse All functionality
  $('.accordion--collapse').on('click keypress', function (e) {
    if (e.which === 13 || e.type === 'click') {
      var accordionInQuestion = $(this).closest('.accordion');
      $(accordionInQuestion).children('.accordion__item').attr('aria-expanded', 'false');
      $(accordionInQuestion).find('.accordion__toggle').removeClass('js-expanded');
      $(accordionInQuestion).find('.accordion__content').slideUp(200).attr('aria-hidden', 'true');
    }
  });

  // Accordtion back to top functionality
  $('.accordion__top').on('click keypress', function (e) {
    var accordion = $(this).closest('.accordion');
    var headerHeight = $('header').height();
    if (e.which === 13 || e.type === 'click') {
      $('html, body').animate({
        scrollTop: $(accordion).find('.accordion__all').offset().top - headerHeight
      }, 200);

      $(accordion).find('.button-container').children('.accordion--expand').focus();
    }
  });

  $('.across:not(.assorted) .flexible-container').each(function () {
    var shownSlides = 3;

    if ($(this).children().length > 3) {
      shownSlides = 3.2;
    }
    else {
      $(this).addClass('three-across');
    }

    // Row of Three Slider on Med + Sm Screens
    var acrossSettings = {
      dots: true,
      arrows: false,
      infinite: false,
      speed: 200,
      slidesToShow: shownSlides,
      centerMode: false,
      variableWidth: false,
      draggable: false,
      swipe: true,
      responsive: [{
          breakpoint: 1024,
          settings: {
            slidesToShow: 2.3,
          },
        },
        {
          breakpoint: 700,
          settings: {
            slidesToShow: 1.3
          }
        },
        {
          breakpoint: 400,
          settings: {
            slidesToShow: 1.15
          }
        },
        {
          breakpoint: 350,
          settings: {
            slidesToShow: 1.1
          }
        },
      ]
    };

    $(this).slick(acrossSettings);

    //If only three items are present in carousel, unslick on large screen sizes
    $(window).on('load resize', function () {
      if (window.innerWidth > 1023) {
        if ($('.three-across').hasClass('slick-initialized')) {
          $('.three-across').slick('unslick');
        }
        return;
      }

      if (!$('.three-across').hasClass('slick-initialized')) {
        return $('.three-across').slick(acrossSettings);
      }
    });
  });

  $('.homepage-hero__video , .ambient--video').on('click keypress', function (e) {
    if (e.which === 13 || e.type === 'click') {
      if ($(this).children('video').get(0).paused) {
        $(this).children('video').get(0).play();
      }
      else {
        $(this).children('video').get(0).pause();
      }
    }
  });

  // Homepage slide waypoint interactions / Video lazy load
  $('.home-slide').waypoint(function(direction) {
    if (direction === 'down') {
      $(this.element).addClass('active');
      this.destroy();
    }
  }, {
    offset: '50%'
  });


  var feed = new Instafeed({
      get: 'user',
      userId: '3155864491',
      clientId: '8873ac182e3b411f9f8d34d0758fb372',
      accessToken: '3155864491.8873ac1.427231d010eb4a0bbb026364e501725f',
      sortBy: 'most-recent',
      limit: '3',
      template: '<div class="homepage-instagram__item"> <a class="item-picture" href="{{link}}" target="_blank" style="background-image: url({{image}})"> <span class="visuallyhidden">{{caption}}</span> </a> </div>',
      resolution: 'standard_resolution',
  });


  if ($('.home:not(.lazy-load) #instafeed').length) {
    feed.run();
  }

  // On load, if ambient video is visible, load video
  $(document).on('ready', function() {
    var $videowrapper = $('.homepage-hero__video video, .ambient--video video');
    $videowrapper.each(function(index, elem) {
      if ($(elem).is(':visible')) {
        if ($(window).width() >= 1025) {
          $(elem).find('source').eq(0).attr('src', $(elem).find('source').eq(0).attr('data-src'));
          $(elem).load();
        }
      }
    })
  });

  // Homepage lazy load images
  $('.lazy-load .homepage-hero').waypoint(function(direction) {
    if (direction === 'down') {
      $(this.element).find('.homepage-hero__video').attr('style', 'background-image: ' + 'url(' +$(this.element).find('.homepage-hero__video').attr('data-img') + ')');

      if ($(window).width() >= 1025) {
        $(this.element).find('source').eq(0).attr('src', $(this.element).find('source').eq(0).attr('data-src'));
        $(this.element).find('.homepage-hero__video video').attr('poster', $(this.element).find('.homepage-hero__video video').attr('data-img'));
        $(this.element).find('video').load();
      }
      this.destroy();
    }
  }, {
    offset: '100% - 10px',
  });

  $('.lazy-load .our-academics').waypoint(function(direction) {
    if (direction === 'down') {
      $(this.element).find('.our-academics__list__item img').each(function(i,elem) {
        $(elem).attr('src', $(elem).attr('data-img'));
      });

      $(this.element).find('.our-academics__blur__inner').each(function(i,elem) {
        $(elem).attr('style', 'background-image: ' + 'url(' +$(elem).attr('data-img'));
      });
      this.destroy();
    }
  }, {
    offset: '100% - 10px',
  });

  $('.lazy-load .our-research').waypoint(function(direction) {
    if (direction === 'down') {
      $(this.element).find('.home-slide__inner').attr('style', 'background-image: ' + 'url(' +$(this.element).find('.home-slide__inner').attr('data-img') + ')');
      $(this.element).find('.ambient--video video').attr('poster', $(this.element).find('.ambient--video video').attr('data-img'));
      this.destroy();
    }
  }, {
    offset: '100% - 10px',
  });

  $('.lazy-load .our-campus').waypoint(function(direction) {
    if (direction === 'down') {
      $(this.element).find('.home-slide__inner').attr('style', 'background-image: ' + 'url(' +$(this.element).find('.home-slide__inner').attr('data-img') + ')');
      $(this.element).find('.ambient--video video').attr('poster', $(this.element).find('.ambient--video video').attr('data-img'));

      var elemArr = ['.our-campus__blur__inner--left', '.our-campus__blur__inner', '.our-campus__blend-bg'];
      for (let i = 0; i < elemArr.length; i++) {
        $(elemArr[i]).attr('style', 'background-image: ' + 'url(' +$(elemArr[i]).attr('data-img') + ')');
      }

      this.destroy();
    }
  }, {
    offset: '100% - 10px',
  });

  $('.lazy-load .home-stories').waypoint(function(direction) {
    if (direction === 'down') {
      $(this.element).find('.home-stories__stories-wrap__story__image').each(function(i,elem) {
        $(elem).children('img').attr('src', $(elem).children('img').attr('data-img'));
      });


      $(this.element).find('.homepage-instagram__items').slick(homeSettings)

      this.destroy();
    }
  }, {
    offset: '100% - 10px',
  });

  $('.lazy-load .nmt-now').waypoint(function(direction) {

    if (direction === 'down') {
      if ($('#instafeed').length) {
        feed.run();
      }

      setTimeout(function() {
        $('.home.lazy-load .homepage-instagram__items').each(function(i, elem) {
          if (window.innerWidth > 1024) {
            if ($(elem).hasClass('slick-initialized')) {
              $(elem).slick('unslick');
            }
            return;
          }

          if (!$(elem).hasClass('slick-initialized')) {
            return $(elem).slick(homeSettings);
          }
        });
      }, 1000)

      this.destroy();
    }
  }, {
    offset: '100% - 10px',
  });

  $('.lazy-load .homepage-facts').waypoint(function(direction) {
    if (direction === 'down') {
      $(this.element).find('.fact').each(function(i,elem) {
        $(elem).attr('style', 'background-image: ' + 'url(' +$(elem).attr('data-img'));
      });
      this.destroy();
    }
  }, {
    offset: '100% - 10px',
  });

  $('.lazy-load .adds-up').waypoint(function(direction) {
    if (direction === 'down') {
      $(this.element).find('.home-slide__inner').attr('style', 'background-image: ' + 'url(' +$(this.element).find('.home-slide__inner').attr('data-img') + ')');
      $(this.element).find('.adds-up__link a').attr('style', 'background-image: ' + 'url(' +$(this.element).find('.home-slide__inner').attr('data-img') + ')');
      this.destroy();
    }
  }, {
    offset: '100% - 10px',
  });

  $('.lazy-load .home-footer').waypoint(function(direction) {
    if (direction === 'down') {
      $(this.element).find('.home-slide__inner').attr('style', 'background-image: ' + 'url(' +$(this.element).find('.home-slide__inner').attr('data-img') + ')');
      this.destroy();
    }
  }, {
    offset: '100% - 10px',
  });

  // Program Finder - fix Matching Programs button above footer
  if ($('.results__matches').length) {
    $('.footer').waypoint(function (direction) {
      if (direction === 'up') {
        $('.results__matches > a').removeClass('js-footer-fixed');
      }
      else if (direction === 'down') {
        $('.results__matches > a').addClass('js-footer-fixed');
      }
    }, {
      offset: '100%'
    });

    $(window).on('scroll', function () {
      Waypoint.refreshAll();
    });
  }
});
