(function($) {

    "use strict";

    var $window = $(window); 

    $window.on('load', function () {
        $window.trigger('dt.preloader_done');

        setTimeout(function () {
            $('body').addClass('page-loaded');
            $('#preloader').fadeOut('slow');
        }, 250);
    });

    $(document).ready(function() {
        $('.vc_row[data-vc-full-width="true"]').addClass('andaman_full_row_vc');

        $(window).on('load resize', function() {
            $('.vc_row[data-vc-full-width="true"]').addClass('andaman_full_row_vc');
        });



        function search_block() {

        $(document).on('click', '.close-black-block', function(event) {
            event.preventDefault();
                $('.black-search-block').removeClass('opened');
            });

            var searchField = $('.black-search-block');
            var searchBtn = $('.search-icon-header');
            var input = searchField.find('input');
            var inputValue = input.val();
            var opened = false;
            if ($('body').hasClass('search-no-results')) {
                searchField.addClass('opened');
                setTimeout(function() {
                    input.focus();
                }, 500);
                opened = true;
            }
            searchBtn.on('click', function(e) {
                e.preventDefault();

                if (!opened) {
                    searchField.addClass('opened');
                    setTimeout(function() {
                        input.focus();
                    }, 500);
                    opened = true;

                } else if (opened) {
                    searchField.removeClass('opened');
                    opened = false;
                }
            });
        }
        search_block();


        $('body').addClass('menu-transparent');






    $(window).on('scroll', function() {
        if ($(this).scrollTop() > $('.header').height()) {
            $('.sticky-menu').sticky({
                zIndex: 999
            });
        } else {
            $(".sticky-menu").unstick(); 
        }
    });








        $(window).on('load resize scroll', function() {
            if ($("body").hasClass('admin-bar') && ($(window).width() > 600)) {
                $('.sticky-wrapper.is-sticky .navbar-fixed-top').css('top', (($('#wpadminbar').height())))
            }
        });


        function scrollTop() {
            var offset = 500,
                scroll_top_duration = 350,
                $back_to_top = $('.scroll-top');

            $(window).on('scroll', function() {
                if ($(this).scrollTop() > offset) {
                    $back_to_top.addClass('scroll-top-visible').removeClass('scroll-top-hidden');
                } else {
                    $back_to_top.addClass('scroll-top-hidden').removeClass('scroll-top-visible');
                }
            });

            $back_to_top.on('click', function() {
                $('html, body').animate({
                    scrollTop: 0
                }, scroll_top_duration);
                return false;
            });

        }
        scrollTop();

        var $container = $('.andaman_mas_container');
        if ($container.length) {
            $container.waitForImages(function() {
                $container.isotope({
                    itemSelector: '.andaman_mas_item',
                    layoutMode: 'masonry',
                });
            }, null, true);
        }

        var wow = new WOW({
            boxClass: 'wow', // animated element css class (default is wow)
            animateClass: 'animated', // animation css class (default is animated)
            offset: 0, // distance to the element when triggering the animation (default is 0)
            mobile: false, // trigger animations on mobile devices (default is true)
            live: true, // act on asynchronously loaded content (default is true)
            callback: function(box) {
                // the callback is fired every time an animation is started
                // the argument that is passed in is the DOM node being animated
            },
            scrollContainer: null // optional scroll container selector, otherwise use window
        });
        $(window).one('dt.preloader_done', function() {
            wow.init();
        });
        

        $('.swipebox').swipebox({
            useCSS: true, // false will force the use of jQuery for animations
            useSVG: false, // false to force the use of png for buttons
            hideCloseButtonOnMobile: false, // true will hide the close button on mobile devices
            hideBarsDelay: 0, // delay before hiding bars on desktop
            videoMaxWidth: 1140, // videos max width
            loopAtEnd: false, // true will return to the first image after the last image is reached
            autoplayVideos: true // true will autoplay Youtube and Vimeo videos
        });

        /* Video */

        $('.swipebox-video').swipebox();

        // addition for swipebox, closing img on click on bg
        jQuery(function() {
            jQuery(document.body)
                .on('click touchend', '#swipebox-slider .current img', function(e) {
                    return false;
                })
                .on('click touchend', '#swipebox-slider .current', function(e) {
                    jQuery('#swipebox-close').trigger('click');
                });
        });

        $(window).on('load scroll', function() {
            $('a.page-scroll').on('click', function(event) {
                var $anchor = $(this);
                $('html, body').stop().animate({
                    scrollTop: ($($anchor.attr('href')).offset().top - 55)
                }, 1500, 'easeInOutExpo');
                event.preventDefault();
            });
        });

        $(window).on("load", function() {
            $(".share-class a").mPageScroll2id({
                highlightSelector: "#menu-onepage a",
                scrollSpeed: 1500,
                scrollingEasing: "easeInOutExpo",
                clickedClass: "active-menu",
                highlightClass: "active-menu"
            });
        });

        if ($("body").hasClass('fullscreen')) {
            $(function() {
                $('.tag_line.tag_line_image').css('height', (($(window).height())))
            })
        }

        if ($("body").hasClass('fullscreen')) {
            $(function() {
                $(window).on('load resize', function() {
                    $('.tag_line.tag_line_image').css('height', (($(window).height())))
                })
            })
        }

        if ($("body").hasClass('error404')) {
            $(function() {
                $('.tag_line.tag_line_image').css('height', (($(window).height())))
            })
        }

        if ($("body").hasClass('error404')) {
            $(function() {
                $(window).on('load resize', function() {
                    $('.tag_line.tag_line_image').css('height', (($(window).height())))
                })
            })
        }



        function responsive_menu() {
            function andamanMenu() {
            var $burger_menu = $('.burger_andaman_menu_overlay_normal');
                $burger_menu.find('.menu-item-has-children > a').on('click', function (e) {
                    var $this = $(this),
                        $current_menu_item = $(this).parent();
                    $burger_menu.find('.menu-item-has-children').each(function () {
                        if (!$.contains(this, $current_menu_item.get(0))) {
                            $(this).find('> a').removeClass('sub-active').next('ul').slideUp(250);
                        }
                    });
                    if ($this.next('ul').is(':visible') === false) {
                        $this.addClass('sub-active').next('ul').slideDown(250);
                    }
                    e.preventDefault();
                });
            }

            andamanMenu();
            function andaman_burger_responsive() {
                $('#open-button').click(function(e) {
                    e.preventDefault();
                    $(this).toggleClass('active');
                    $('body').toggleClass('show-menu');
                });
            }
            andaman_burger_responsive();
            $('.burger_andaman_menu_overlay_normal .share-class a').on('click', function(){$('#open-button').trigger('click')});
        };
        $(window).on('load', responsive_menu);

    });
})(jQuery);