/**
 * Latest Custom JS
 *
 * @package Latest
 *
 * Distributed under the MIT license - http://opensource.org/licenses/MIT
 */
jQuery(document).ready(function($){
    // Defining a function to set size for page title padding if we have a very large primary menu
    function fullscreen(){

        var topbarheight = $('#top-bar').outerHeight();
        topbarheight = parseInt(topbarheight);

        if ( topbarheight > 0 ) {
            jQuery('.toggle-nav').css({
                'top' : topbarheight + 'px'
            });
            jQuery('.site-search').css({
                'top' : topbarheight + 'px'
            });
        }

        if ( ! $('#primary-menu').length ) {
            jQuery('.toggle-nav').css({
                'display' : 'none'
            });
        }

    }
  
    fullscreen();

    // Run the function in case of window resize
    jQuery(window).resize(function() {
        fullscreen();         
    });

});


jQuery(function($){

    // Mobile Menu
    $('#primary-menu .menu-item-has-children').prepend('<span class="sub-trigger"></span>');

    $( '.toggle-nav' ).click( function() {
        $( '#page' ).toggleClass( 'is-visible' );
        $( '#masthead' ).toggleClass( 'is-visible' );
        $( this ).toggleClass( 'is-visible' );
    });
    $( '.sub-trigger' ).click( function() {
        $( this ).toggleClass( 'is-open' );
        $( this ).siblings( '.sub-menu' ).toggle( 300 );
    });

});

jQuery(document).ready( function($) {
    $('#masonry-loop').imagesLoaded(function () {
        $('#masonry-loop').masonry({
            itemSelector: '.masonry-entry',
            gutter: 0,
            transitionDuration: 0,
        }).masonry('reloadItems');
    });
});
