$(document).ready(function() {
    navBar();
    smoothScroll();
    backToTop();

    if ($('body').hasClass('single-portfolio')) {
        slider();
    };
    if ($('body').hasClass('page-id-12')) {
        formValidation();
    };
     if ($('body').hasClass('page-id-10')) {
        instafeed();
    };
})

function backToTop() {
    $(document).scroll(function() {
        var y = $(this).scrollTop();
        if (y > 600) {
            $('.backToTop').fadeIn('fast', function() {});
        } else {
            $('.backToTop').fadeOut('fast');
        }
    });
    $('.backToTop').on('click', function(event) {
        event.preventDefault();
        $("html, body").animate({
            scrollTop: 0
        }, 1000);

    });
}

function slider() {  
    $('#carousel').flexslider({
        animation: "slide",
        controlNav: false,
        animationLoop: false,
        slideshow: false,
        directionNav: false,
        asNavFor: '#slider',
    });
    $('#slider').flexslider({
        animation: "slide",
        controlNav: false,
        directionNav: true,
        prevText: "",
        nextText: "",
        animationLoop: false,
        slideshow: false,
        sync: "#carousel"
    });
}

function navBar() {
    $(".hamburger").click(function() {
        $("body").toggleClass('overlay-display');
        $(".navWrapper").toggleClass('showMenu');

    });
    $(".overlay").click(function() {
        $("body").removeClass('overlay-display');
        $(".navWrapper").removeClass('showMenu');
    });
}

function smoothScroll() {
    $('.downToMain').on('click', function(event) {
        event.preventDefault();
        $("html, body").animate({
            scrollTop: 925
        }, 1000);

    });
}

function formValidation() {
    $('#contactForm').validate({
        highlight: function(element, errorClass, validClass) {
            $(element).removeClass('successClass').addClass('errorClass');
        },
        unhighlight: function(element) {
            $(element).removeClass('errorClass').addClass('successClass');
        },
        rules: {
            formName: {
                required: true,
            },
            formEmail: {
                required: true,
                email: true
            },
            formSubject: {
                required: true
            },
            formMessage: {
                required: true,
                minlength: 50
            }
        }
    });
}

function instafeed() {
    var feed = new Instafeed({
        get: 'user',
        userId: 207397831,
        accessToken: '207397831.467ede5.4de11bee921343dcbf7a81f442df2e66',
        clientId: '5a9e4dd226244fc18b8f7a21fd80548b',
        sortBy: 'most-recent',
        link: 'false',
        limit: '12',
        resolution: 'low_resolution',
        template: '<div class="instagramWrap col-sm-2"><img width="100%" height="auto" id="{{id}}" alt="{{caption}}" src="{{image}}"/></div>'

    });
    feed.run();
}
