$(document).ready(function() {

    var wind = $(window);

    wow = new WOW({
        boxClass: 'wow',
        animateClass: 'animated',
        offset: 200,
        mobile: false,
        live: false
    });
    wow.init();



    /* ----------------------------------------------------------------
                [ sidemenu dropdown ]
-----------------------------------------------------------------*/
    var linkGroup = $('.linkGroup'),
        linkGroupHead = $('.linkGroup .linkItem-head');

    linkGroupHead.on('click', function() {

        $(this).next(".linkItem-body").slideToggle();
    });

    linkGroup.on('click', function(e) {
        e.stopPropagation();
        $(this).addClass("active").siblings().removeClass("active");
        $(this).siblings().find('.linkItem-body').slideUp()
    });

    $('html').on('click', function() {
        linkGroup.removeClass("active");
        linkGroup.find('.linkItem-body').slideUp()
    });

    /* ----------------------------------------------------------------
                [ sidemenu active ]
-----------------------------------------------------------------*/
    $('.sidemenu-links li').on('click', function() {
        $(this).addClass('active').siblings().removeClass('active');
    })

    /* ----------------------------------------------------------------
                [ gallery ]
-----------------------------------------------------------------*/
    $('.photos').on('click', ".img-title .add-title", function() {
        $(this).parent(".img-title").find(".preview").addClass("show");
    })

    $(".photos").on("change", ".img-title input", function() {
        var inval = $(this).val();
        $(this).siblings(".preview").text(inval);
    });


    // ----------- gallery close button -----------
    $('.photos').on('click', '.items .close', function(e) {
        e.preventDefault();
        $(this).parent().parent().fadeOut(500);
    })

    /* ----------------------------------------------------------------
                [ toggelmenu ]
-----------------------------------------------------------------*/
    $('.toggelmenu').on('click', function() {
        $(this).toggleClass("arrow");
        $(".sidemenu").toggleClass("smallmenu");
        $(".top-nav").toggleClass("tallnav");
        $("main").toggleClass("fullwidth");
    })

    /* ----------------------------------------------------------------
                [ back-top ]
-----------------------------------------------------------------*/


    $('.back-top').on('click', function() {
        $('html, body').animate({
            scrollTop: 0
        }, 2000);
    })

    //   progress bar
    wind.on('scroll', function() {
        $(".progress-item span").each(function() {
            var bottom_of_object =
                $(this).offset().top + $(this).outerHeight();
            var bottom_of_window =
                $(window).scrollTop() + $(window).height();
            var myVal = $(this).attr('data-value');
            if (bottom_of_window > bottom_of_object) {
                $(this).css({
                    width: myVal
                }, 1000);
            }
        });
    });
    // end progress bar

    // ===============================================

    // Add class to active link in menu
    $('.sidemenu-links .linkItem-body a').click(function () {
        localStorage.setItem('activeLink', $(this).attr('href'));
    });
    let activeLink = localStorage.getItem('activeLink');
    $('.sidemenu-links .linkItem-body a[href="'+activeLink+'"]').addClass('before');


});
