(function($)
{
  Drupal.behaviors.myBehavior =
  {
    attach: function (context, settings)
    {

      // Adds Class to Main Navigation
        $("a.menu-1").parent("li").addClass("menu-1");
        $("a.menu-2").parent("li").addClass("menu-2");
        $("a.menu-3").parent("li").addClass("menu-3");
        $("a.menu-4").parent("li").addClass("menu-4");
        $("a.menu-5").parent("li").addClass("menu-5");
        $("a.menu-6").parent("li").addClass("menu-6");
        $("a.menu-7").parent("li").addClass("menu-7");
        $("a.menu-8").parent("li").addClass("menu-8");

      // Attach expand/collapse handlers
      expandCollapse(true, '.view-other-resources .ec h3','.hidable', 2);
      expandCollapse(true, '.view-grants-gov-search-api .summary','.details', 2);
      expandCollapse(true, '.view-federal-resources-search-api .summary','.details', 2);
      expandCollapse(true, '.ec h3','.hidable', 2);

      // EPI Cards
      if (document.getElementById('epi_cards'))
      {
        var mixer = mixitup('#epi_cards', {
          load: {
            filter: '.behavior'
          },
          animation: {
            enable: false
          }
        });
      }

      // Collaboration Profiles
      if (document.getElementsByClassName('view-collaboration-profiles').length > 0)
      {
        var mixer = mixitup('.view-collaboration-profiles.view-content .grid-row', {
          load: {
            filter: 'all'
          },
          animation: {
            enable: false
          }
        });
      }

      // Collaboration Profiles expand/collapse
      // expandCollapse(true, '.collaboration-landing-sidebar-block h2','.content', 2);

      // Click sidebar activates buttons
      jQuery('.collaboration-landing-sidebar-block h2').click(function()
      {
        acordionCollabSidebar(jQuery(this));
      });

      // Clicking filters activates sidebar
      jQuery('.view-collaboration-profiles .mixit_btn button').click(function(){
        var f = jQuery(this).attr('data-filter');
        if (f == 'all')
        {
          acordionCollabSidebar(jQuery('.collaboration-landing-sidebar-block h2'));
        } else {
          acordionCollabSidebar(jQuery('.collaboration-landing-sidebar-block h2[button="'+f+'"'));
        }

      });

      // Activate Collaboration Profile tabs based on sidebar selection
      jQuery('.collaboration-landing-sidebar-block h2').click(function()
      {
        var button = jQuery(this).attr('button');
        var s = 'button[data-filter="'+button+'"]';
        jQuery(s).trigger('click');
      });

      function acordionCollabSidebar(e)
      {
        jQuery('.collaboration-landing-sidebar-block .content').hide();
        e.closest('div').find('.content').show();
      }

      // Funding Sources
      if (document.getElementsByClassName('view-federal-funding-sources').length > 0)
      {
        var mixer = mixitup('.view-federal-funding-sources', {
          load: {
            filter: 'all'
          },
          animation: {
            enable: false
          }
        });
      }

      // Click sidebar activates buttons
      jQuery('#block-fundingcategories h2').click(function()
      {
        accordionFedFundingSidebar(jQuery(this));
      });

      // Clicking filters activates sidebar
      jQuery('.view-federal-funding-sources .mixit_btn button').click(function(){
        var f = jQuery(this).attr('data-filter');
        if (f == 'all')
        {
          accordionFedFundingSidebar(jQuery('#block-fundingcategories h2'));
        } else {
          accordionFedFundingSidebar(jQuery('#block-fundingcategories h2[button="'+f+'"'));
        }
      });

      // Activate Collaboration Profile tabs based on sidebar selection
      jQuery('#block-fundingcategories h2').click(function()
      {
        var button = jQuery(this).attr('button');
        var s = 'button[data-filter="'+button+'"]';
        jQuery(s).trigger('click');
      });

      function accordionFedFundingSidebar(e)
      {
        jQuery('#block-fundingcategories .content').hide();
        e.closest('div').find('.content').show();
      }

      iFrameResize({log:true}, '#mdrc_iframe');

    }
  };
})(jQuery);