$(document).ready(function(){ 

  // Highlight the current path and levels above
  var path = location.pathname.substring(1);
  if ( !path )
  {
    path = 'index.html';
  }

    $('.mega_menu_column a[href$="' + path + '"]').each( function() {
      $( this ).addClass('current').closest( '.mega_menu_column' ).addClass( 'current' ).closest( 'li' ).addClass( 'current' );
    });

    var megaConfig = {
         interval: 100,
         sensitivity: 4,
         over: addMega,
         timeout: 200,
         out: removeMega
    };

    $("li.mega").hoverIntent(megaConfig);

	function addMega(){
		$(this).addClass("hovering");
	}

	function removeMega(){
		$(this).removeClass("hovering");
	}

  // Handle highlighting the second level menu heading
  $( '.mega_menu_column' ).hover(
  function () {
		$(this).addClass("highlight");
  },
  function () {
		$(this).removeClass("highlight");
  }
);

  // Force each of the columns inside the mega menu to be of eual heights
  $( '.mega_menu' ).each( function() {
      // Make the element visible for a moment so we have a height
      $(this).closest( 'li' ).addClass("hovering");
      $( '.mega_menu_column', this ).equalHeights();
      $(this).closest( 'li' ).removeClass("hovering");
  });
  
  // Handle the social sidebar
    var offset = $('#social_sidebar').offset().top;
    var position = $('#social_sidebar').position().top;

    $(window).scroll(function() {
        var wst = $(window).scrollTop();

        (wst >= offset) ?
        $('#social_sidebar').css({position: 'fixed', top: 15+'px' }) :  
        $('#social_sidebar').css({position: 'absolute', top: position+'px' })

    });

    // Handle fading of the social sidebar
    // start faded
  $( '#social_sidebar' ).hide().delay( 1000 ).fadeTo( 'slow', 0.4 );
/*  $('#facebook-find img').load(function() {
    $('#social_sidebar').fadeTo( 'slow',0.4)
  });*/

    $( '#social_sidebar' ).hover(
  function () {
    $(this).fadeTo('slow', 1);
  },
  function () {
    $(this).fadeTo('slow',0.4);
  });


  // Submit the newsletter form
  $( '#newsletter_signup' ).click( function() { $('#subForm').submit(); } );
  $( '#byutth-byutth' ).defaultText();

  
});

(function(d, s, id) {
  var js, fjs = d.getElementsByTagName(s)[0];
  if (d.getElementById(id)) {return;}
  js = d.createElement(s); js.id = id;
  js.src = "//connect.facebook.net/en_US/all.js#xfbml=1";
  fjs.parentNode.insertBefore(js, fjs);
}(document, 'script', 'facebook-jssdk'));

  (function() {
    var po = document.createElement('script'); po.type = 'text/javascript'; po.async = true;
    po.src = 'https://apis.google.com/js/plusone.js';
    var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(po, s);
  })();

