$.noConflict();
jQuery(document).ready(function($) {
    
    /*
    |--------------------------------------------------------------------------
    | Intialize
    |--------------------------------------------------------------------------=
    | Everything to do while loading
    |
    */

    // Get element reference
    var screenHeight = $(window).height();
    var $window      = $(window);
    var $nav         = $("#site-navigation");

    // Start the parallax
	$('.parallax').parallax({height: 100});

    // Init carrousel
    $('.carousel.carousel-slider').carousel({fullWidth: true});

    // Auto Loop
    // setInterval(function(){ $('.carousel').carousel('next'); }, 4000);

    // Adjust post height
    stylePost();

    // Start Hero Navigation
    heroNavigation($window)

    // Remove loader and start transition when fadeout is completed
    setTimeout(function() {
        $("#loading-screen").fadeOut(400, function() {
            // Transition
            // On index
            if ($("#post-hero-content-d2d").length) {
                Materialize.showStaggeredList("#post-hero-content-d2d");
            }
            // On navigation menu
            Materialize.showStaggeredList("#primary-menu");
            // Transition on Page Title On all single, archive, search, etc...
            translateX($("#page-title-container"));
        });
    }, 1500);

    
    /*
    |--------------------------------------------------------------------------
    | Functions
    |--------------------------------------------------------------------------=
    |
    */

    function stylePost() {
        var $post = $("#primary article.card.hentry");
        var height;

        $post.css("height", "")
            .find(".post-container")
            .css({height: "initial", position: "initial"});

        if ($post.length) {
            $.each($post, function() {
                height = $(this).height();
                $(this).height(height).find(".post-container").height(height).css("position", "absolute");
            });
        }    
    }

    function heroNavigation($this) {
        if ($this.scrollTop() > (screenHeight - 64)) {
            $nav.removeClass("hero-mode");
        } else {
            $nav.addClass("hero-mode");
        }
    }

    function translateX($object) {

        $object.velocity(
            { translateX: "-100px"},
            { duration: 0 });

        $object.velocity(
            { opacity: "1", translateX: "0"},
            { duration: 800, easing: [60, 10] });
    }


    /*
    |--------------------------------------------------------------------------
    | Events
    |--------------------------------------------------------------------------=
    |
    */

    // Adjust post height on resize
    $window.on("resize", stylePost);

    // Adjust screen height variable on resize
    $window.on("resize", function(){
        screenHeight = $window.height();
    });
    // Check navigation on scroll
    $window.on("scroll", function() {
        heroNavigation($(this));
    });

    // Toggle Responsive navigation
    $("#responsive-nav-trigger").on("click", function() {
        var $this = $(this);

        if ($this.hasClass("active")) {
            $this.removeClass("active").find("i").text("menu");
            // $("#site-logo").css("z-index", 'initial');
            $("#responsive-nav").fadeOut();
            $("#responsive-menu li").css("opacity", "0");
            $("html").css("overflow", "initial");
        } else {
            $this.addClass("active").css("z-index", '100').find("i").text("close");
            $("#site-logo").css("z-index", '100');
            $("#responsive-nav").fadeIn();
            $("html").css("overflow", "hidden");
            Materialize.showStaggeredList("#responsive-menu");
        }
    });


    

});

