( function( $ ) {

  $(document).ready(function($){

    // Search in Header.
      if( $('.search-toggle').length > 0 ) {
        $('.search-toggle').on( 'click',function(e){
          e.preventDefault();
          $(this).parent().toggleClass( 'toggled-on' );
        });

        $( window )
          .on( 'load.educationsoul resize.educationsoul', function() {
          if ( window.innerWidth > 767 ) {
            $('#primary-search-form').on('focusout', function () {
              var $elem = $(this);

                // let the browser set focus on the newly clicked elem before check
                setTimeout(function () {
                    if ( ! $elem.find(':focus').length ) {
                      $( '.primary-search-wrapper .search-toggle' ).trigger('click');
                    }
                }, 0);
            });
          }
        } );
      }

    // Implement go to top
    if ( $('#btn-scrollup').length > 0 ) {

      $(window).on( 'scroll',function(){
        if ($(this).scrollTop() > 100) {
          $('#btn-scrollup').fadeIn();
        } else {
          $('#btn-scrollup').fadeOut();
        }
      });

      $('#btn-scrollup').on( 'click',function(){
        $('html, body').animate({ scrollTop: 0 }, 600);
        return false;
      });
    }

    // Notice ticker.
    var $notice_ticker = $('#notice-ticker');

    $notice_ticker.easyTicker({
      direction: 'up',
      easing: 'swing',
      speed: 'slow',
      interval: 3000,
      height: 'auto',
      visible: 1,
      mousePause: 1
    });


  });
    //Fixed header

    $(window).on( 'scroll',function () {
        if( $(window).scrollTop() > $('#main-nav').offset().top && !($('#main-nav').hasClass('fixed'))){
          $('#main-nav').addClass('fixed');
      }

      else if ( 0 === $(window).scrollTop() ){
          $('#main-nav').removeClass('fixed');
      }
  });
} )( jQuery );
