// Variables and DOM Caching.

$(document).ready(function () {
     $('.btn-contact-enquiry').click(function(){
        $('.contact-enquiry-form').slideToggle();
     })
     
     if($(window).width()  < 968){
         $('.inner-nav a h3').click(function(){
             $('.inner-nav ul').slideUp();
             var nextEl = $(this).parents('a');
             nextEl.next().slideToggle();
             $('.inner-nav a h3').removeClass('active');
             $(this).addClass('active');
         })
     }
     
    
    // if($(window).width()  < 768){
    //     $('.sub-menu').each(function(){
    //       $(this).prev().append('<span class="fas fa-chevron-right ml-3 toggle-submenu"></span>'); 
    //     });
        
    // }else{
    //      $(".site-menu li a").on("mouseover", function () {
    //         if($(this).hasClass('has-menu')){
    //           var html = $(this).next().html();
    //             $('#RightMenu').html(html);
    //             $('.right-menu-box').fadeIn();
    //         }else{
    //             $('.right-menu-box').fadeOut();
    //         }
    //     });
    // }
    $(document).on('click','.toggle-submenu',function(){
        var submenu = $(this).parents('li');
        submenu.find('.sub-menu').slideToggle();
        $(this).toggleClass('fa-chevron-down');
        $(this).toggleClass('fa-chevron-right');
        return false;
    });
    $(".menu-toggle-icon").click(function(){	
        $('.site-navigation').addClass('open');
        $('.close-text').addClass('open');
        $("body").addClass('scroll-off');
        return false;
    });
    $(".menu-close").click(function(){
        $('.site-navigation').removeClass('open');
        $('.close-text').removeClass('open');
        $("body").removeClass('scroll-off');
        return false;
    });
   
    if ($(".animated-icon").length > 0) {
        const animatedEls = document.querySelectorAll(".animated-icon");
        for (const animatedEl of animatedEls) {
          const id = animatedEl.id;
          lottie.loadAnimation({
            container: document.getElementById(id),
            renderer: "svg",
            loop: true,
            autoplay: true,
            path: '/front/json/'+id+'.json'
          });
        }
    }
    
    if ($("#logoSvg").length) {
        new Vivus('logoSvg', {}, function (myVivus) {
            myVivus.play(myVivus.getStatus() === 'end' ? -1 : 1);
        });
    }

    if ($('.typed').length > 0) {
        var typedItems = $('.typed-items').text();
        var typed = new Typed('.typed', {
            strings: typedItems.split(','),
            typeSpeed: 100,
            backSpeed: 80,
            backDelay: 500,
            startDelay: 100,
            showCursor: false,
            loop: true
        });
    }
    if ($('.owl-slider').length > 0) {
        $('.owl-slider').owlCarousel({
            loop: true,
            autoplay: true,
            autoplayTimeout: 6000,
            smartSpeed: 1000,
            animateOut: 'fadeOut',
            animateIn: 'fadeIn',
            items: 1,
            nav: true,
            dots:false,
            navText: ['<span style="text-indent: -1000px;display:inline-block;overflow:hidden;width: 100%;">Left</span><i  class="fas fa-chevron-left"></i>', '<span style="text-indent: 1000px;display:inline-block;overflow:hidden;width: 100%;">Right</span><i  class="fas fa-chevron-right"></i>'],
        });

    }
    if ($(".clients-slider").length) {
        $(".clients-slider").owlCarousel({
            autoplay: true,
            loop: true,
            autoplayTimeout: 2000,
            slideSpeed: 2000,
            items: 5,
            dots: false,
            nav: false,
            navText: ['<i  class="fas fa-chevron-left"></i>', '<i  class="fas fa-chevron-right"></i>'],
            smartSpeed: 1000,
            responsive: {
                0: {
                    margin: 15,
                    items: 2
                },
                600: {
                    items: 3
                },
                1000: {
                    items: 3
                },
                1200: {
                    items: 5
                }
            }
        });
    }

    if ($('.wow').length > 0) {
        wow = new WOW({
            animateClass: 'animated',
            offset: 100,
        });
        wow.init();
    }

    if ($(".google-reviews-slider").length) {
        $(".google-reviews-slider").owlCarousel({
            autoplay: true,
            autoplayTimeout: 4000,
            slideSpeed: 2000,
            items: 3,
            dots: false,
            nav: true,
            navText: ['<i  class="fas fa-chevron-left"></i>', '<i  class="fas fa-chevron-right"></i>'],
            smartSpeed: 1000,
            responsive: {
                0: {

                    items: 1
                },
                600: {
                    items: 2
                },
                1000: {
                    items: 2
                },
                1200: {
                    items: 3
                }
            }
        });
    }
    if($('[data-toggle="tooltip"]').length){
        $('[data-toggle="tooltip"]').tooltip();
    }
    


    $('.CheckoutNext').click(function () {
        var current = $(this).parents('.step');
        var step = $('.checkout-steps .active');
        //step.removeClass('active');
        step.next().addClass('active');
        current.fadeOut(200);
        current.next().fadeIn(200);
    });
    $('.CheckoutFinish').click(function () {
        $('#yourDetails').fadeOut(200);
        $('#Summary').fadeIn(200);
        var step = $('.checkout-steps .active');
        step.next().addClass('active');
    });

    $('#btnAddressManually').click(function () {
        $(this).fadeOut(200);
        $('.address-manually').fadeIn(200);
    })

    $('.summaryNextButton').click(function () {
        var current = $(this).parents('.summary-step');
        var step = $('.checkout-steps .active');
        step.next().addClass('active');
        current.fadeOut(200);
        current.next().fadeIn(200);
    })


    if ($("input[name='services']")) {
        $("input[name='services']").change(function () {
            var yourFloPrice = parseFloat($('#YourFloPrice').text());
            var price = parseFloat($(this).attr('data-price'));
            if ($(this).is(':checked')) {
                var totalPrice = yourFloPrice + price;
                totalPrice = totalPrice.toFixed(2);
                $('#YourFloPrice').text(totalPrice);
            } else {
                var totalPrice = yourFloPrice - price;
                totalPrice = totalPrice.toFixed(2);
                $('#YourFloPrice').text(totalPrice);
            }
        });
    }

    if ($("input[name='landlordservices']")) {
        $("input[name='landlordservices']").change(function () {
            var yourFloPrice = parseFloat($('#landlordYourFloPrice').text());
            var price = parseFloat($(this).attr('data-price'));
            if ($(this).is(':checked')) {
                var totalPrice = yourFloPrice + price;
                totalPrice = totalPrice.toFixed(2);
                $('#landlordYourFloPrice').text(totalPrice);
            } else {
                var totalPrice = yourFloPrice - price;
                totalPrice = totalPrice.toFixed(2);
                $('#landlordYourFloPrice').text(totalPrice);
            }
        });
    }


    $('#ZeroExcess').click(function () {
        if ($('#perMonth').hasClass('active')) {
            $("#MiniFloPrice").text('18.25');
            $("#HalfFloPrice").text('24.99');
            $("#FullFloPrice").text('32.99');
        } else {
            $("#MiniFloPrice").text('219.00');
            $("#HalfFloPrice").text('299.88');
            $("#FullFloPrice").text('395.88');
        }
        $(this).addClass('active');
        $('#SixtyExcess').removeClass('active');
        $('#EightyFiveExcess').removeClass('active');
    });

    $('#SixtyExcess').click(function () {
        if ($('#perMonth').hasClass('active')) {
            $("#MiniFloPrice").text('15.99');
            $("#HalfFloPrice").text('20.99');
            $("#FullFloPrice").text('26.99');
        } else {
            $("#MiniFloPrice").text('191.88');
            $("#HalfFloPrice").text('251.88');
            $("#FullFloPrice").text('323.88');
        }
        $(this).addClass('active');
        $('#ZeroExcess').removeClass('active');
        $('#EightyFiveExcess').removeClass('active');
    });

    $('#EightyFiveExcess').click(function () {
        if ($('#perMonth').hasClass('active')) {
            $("#MiniFloPrice").text('12.99');
            $("#HalfFloPrice").text('15.99');
            $("#FullFloPrice").text('20.99');
        } else {
            $("#MiniFloPrice").text('155.88');
            $("#HalfFloPrice").text('191.88');
            $("#FullFloPrice").text('251.88');
        }
        $(this).addClass('active');
        $('#ZeroExcess').removeClass('active');
        $('#SixtyExcess').removeClass('active');
    });

    $('#perMonth').click(function () {
        if ($('#ZeroExcess').hasClass('active')) {
            $("#MiniFloPrice").text('18.25');
            $("#HalfFloPrice").text('24.99');
            $("#FullFloPrice").text('32.99');
        } else if ($('#SixtyExcess').hasClass('active')) {
            $("#MiniFloPrice").text('15.99');
            $("#HalfFloPrice").text('20.99');
            $("#FullFloPrice").text('26.99');
        } else if ($('#EightyFiveExcess').hasClass('active')) {
            $("#MiniFloPrice").text('12.99');
            $("#HalfFloPrice").text('15.99');
            $("#FullFloPrice").text('20.99');
        }
        $(this).addClass('active');
        $('#perYear').removeClass('active');
        $('.timeperiod').text('Per Month');
    });

    $('#perYear').click(function () {
        if ($('#ZeroExcess').hasClass('active')) {
            $("#MiniFloPrice").text('219.00');
            $("#HalfFloPrice").text('299.88');
            $("#FullFloPrice").text('395.88');
        } else if ($('#SixtyExcess').hasClass('active')) {
            $("#MiniFloPrice").text('191.88');
            $("#HalfFloPrice").text('251.88');
            $("#FullFloPrice").text('323.88');
        } else if ($('#EightyFiveExcess').hasClass('active')) {
            $("#MiniFloPrice").text('155.88');
            $("#HalfFloPrice").text('191.88');
            $("#FullFloPrice").text('251.88');
        }
        $(this).addClass('active');
        $('#perMonth').removeClass('active');
        $('.timeperiod').text('Per Year');
    });

    $('#landloardCareButton').click(function () {
        $('#LandlordCare').fadeIn(300);
        $('#homeCare').fadeOut(300);
        $(this).addClass('active');
        $('#homeCareButton').removeClass('active');
    });
    $('#homeCareButton').click(function () {
        $('#homeCare').fadeIn(300);
        $('#LandlordCare').fadeOut(300);
        $(this).addClass('active');
        $('#landloardCareButton').removeClass('active');
    });

    //Land Lord Package Prices
    $('#landloardZeroExcess').click(function () {
        if ($('#landloardperMonth').hasClass('active')) {
            $("#landloardMiniFloPrice").text('22.99');
            $("#landloardHalfFloPrice").text('29.99');
            $("#landloardFullFloPrice").text('36.99');
        } else {
            $("#landloardMiniFloPrice").text('275.88');
            $("#landloardHalfFloPrice").text('359.88');
            $("#landloardFullFloPrice").text('443.88');
        }
        $(this).addClass('active');
        $('#landloardSixtyExcess').removeClass('active');
        $('#landloardEightyFiveExcess').removeClass('active');
    });

    $('#landloardSixtyExcess').click(function () {
        if ($('#landloardperMonth').hasClass('active')) {
            $("#landloardMiniFloPrice").text('18.99');
            $("#landloardHalfFloPrice").text('23.99');
            $("#landloardFullFloPrice").text('29.99');
        } else {
            $("#landloardMiniFloPrice").text('227.88');
            $("#landloardHalfFloPrice").text('287.88');
            $("#landloardFullFloPrice").text('359.88');
        }
        $(this).addClass('active');
        $('#landloardZeroExcess').removeClass('active');
        $('#landloardEightyFiveExcess').removeClass('active');
    });

    $('#landloardEightyFiveExcess').click(function () {
        if ($('#landloardperMonth').hasClass('active')) {
            $("#landloardMiniFloPrice").text('15.99');
            $("#landloardHalfFloPrice").text('18.99');
            $("#landloardFullFloPrice").text('23.99');
        } else {
            $("#landloardMiniFloPrice").text('191.88');
            $("#landloardHalfFloPrice").text('227.88');
            $("#landloardFullFloPrice").text('287.88');
        }
        $(this).addClass('active');
        $('#landloardZeroExcess').removeClass('active');
        $('#landloardSixtyExcess').removeClass('active');
    });

    $('#landloardperMonth').click(function () {
        if ($('#landloardZeroExcess').hasClass('active')) {
            $("#landloardMiniFloPrice").text('22.99');
            $("#landloardHalfFloPrice").text('29.99');
            $("#landloardFullFloPrice").text('36.99');
        } else if ($('#landloardSixtyExcess').hasClass('active')) {
            $("#landloardMiniFloPrice").text('18.99');
            $("#landloardHalfFloPrice").text('23.99');
            $("#landloardFullFloPrice").text('29.99');
        } else if ($('#landloardEightyFiveExcess').hasClass('active')) {
            $("#landloardMiniFloPrice").text('15.99');
            $("#landloardHalfFloPrice").text('18.99');
            $("#landloardFullFloPrice").text('23.99');
        }
        $(this).addClass('active');
        $('#landloardperYear').removeClass('active');
        $('.timeperiod').text('Per Month');
    });

    $('#landloardperYear').click(function () {
        if ($('#landloardZeroExcess').hasClass('active')) {
            $("#landloardMiniFloPrice").text('275.88');
            $("#landloardHalfFloPrice").text('359.88');
            $("#landloardFullFloPrice").text('443.88');
        } else if ($('#SixtyExcess').hasClass('active')) {
            $("#landloardMiniFloPrice").text('227.88');
            $("#landloardHalfFloPrice").text('287.88');
            $("#landloardFullFloPrice").text('359.88');
        } else if ($('#landloardEightyFiveExcess').hasClass('active')) {
            $("#landloardMiniFloPrice").text('191.88');
            $("#landloardHalfFloPrice").text('227.88');
            $("#landloardFullFloPrice").text('287.88');
        }
        $(this).addClass('active');
        $('#landloardperMonth').removeClass('active');
        $('.timeperiod').text('Per Year');
    });




    $('.packageButton-Off').click(function () {
        var title = $(this).parents('.card');
        title = title.find('.package-title');
        var price = $(this).parents('.card').find('.package-price').text();
        $('#packagesModalModalLabel').text(title.text());
        $("input[name='packagename']").val(title.text());
        $("input[name='packageprice']").val(price);

        var services = $(this).parents('.card').find('.service-switch');
        if (services.length > 0) {
            var serves = '';
            $('.service-switch').each(function () {
                if ($(this).is(':checked')) {
                    serves += $(this).val() + ' , ';
                }
            });
            $('#ServicesCol').show();
            $('#ServicesCol').html('<input type="text" readonly name="packageservices" value="' + serves + '" class="form-control form-control-lg" placeholder="Services">');
        } else {
            if ($('#ServicesCol')) {
                $('#ServicesCol').html('');
                $('#ServicesCol').hide();
            }
        }
        $('.form-response').html('');
    });

    if ($("#PackageForm").length > 0) {
        $("#PackageForm").validate({
            ignore: false,
            errorClass: "error text-warning",
            validClass: "success text-success",
            highlight: function (element, errorClass) { },
            rules: {
                name: {
                    required: true
                },
                packagename: {
                    required: true
                },
                email: {
                    required: true
                },
                postcode: {
                    required: true
                },
                packageprice: {
                    required: true
                },
            },
            email: {
                firstname: "Please enter valid email"
            }
        });
        $('#submitPackageForm').click(function () {
            if ($('#PackageForm').valid()) {
                var formData = $('#PackageForm').serialize();
                var form = $("#PackageForm");
                $.ajax({
                    type: "POST",
                    url: 'packagemail.php',
                    dataType: 'json',
                    cache: false,
                    data: formData,
                    success: function (data) {
                        if (data.success) {
                            $('.form-response').html('<span class="py-3 h3 text-success">' + data.msg + '</span>');
                            form.validate().resetForm();
                            form[0].reset();
                        } else {
                            $('.form-response').html('<span class="py-3 h3 text-danger">' + data.msg + '</span>');
                        }
                    },
                    error: function (data) {
                        console.log(data);
                    }
                });
            } else {
                return false;
            }
        });
    }
    $('.showAns').click(function () {

        var collapse = $(this).parents('.tab-pane');
        collapse.find('.collapse').each(function () {
            $(this).addClass('show');
        });
        collapse.find('.faq-title').each(function () {
            $(this).removeClass('collapsed');
        })
    })
    $('.hideAns').click(function () {
        var collapse = $(this).parents('.tab-pane');
        collapse.find('.collapse').each(function () {
            $(this).removeClass('show');
        });
        collapse.find('.faq-title').each(function () {
            $(this).addClass('collapsed');
        })
    });
    if ($(window).width() < 900) {
        $('#contact-accordion .collapse').removeClass('show');
        $('#contact-accordion h4.open').removeClass('collapsed');
        $('#contact-accordion #collapseOne').addClass('show');
    }
    if ($('.date-picker').length > 0) {
        $(".date-picker").datepicker({
            minDate: 0
        });
    }

    $(".show-password").click(function () {
        var input = $(this).prev();
        if (input.attr("type") == "password") {
            input.attr("type", "text");
            $(this).html('<i class="fas fa-eye"></i>');
        } else {
            input.attr("type", "password");
            $(this).html('<i class="fas fa-eye-slash"></i>');
        }
    });

    $('.package-info').click(function(){
        return false;
    })
    
    if($(window).width() < 768){
        $('.footer-links-title').click(function(){
           $(this).next().slideToggle(); 
           $(this).toggleClass('active');
        });
    }
    
});


// On scroll, we want to stick/unstick the navigation.
$(window).on('scroll', function () {
    var scrollTop = $(window).scrollTop();

    if (scrollTop > 80) {
        $(".header").addClass("is-fixed");
    } else {
        $(".header").removeClass("is-fixed");
    }

    if ($('#homecare-packages').length > 0 && $(window).width() > 800) {
        var packageoffset = $('#homecare-packages').offset().top;
        if (scrollTop > packageoffset) {
            $(".package-header").addClass("fixed");
        } else {
            $(".package-header").removeClass("fixed");
        }
    }

    if ($('#blog-detail').length > 0) {
        var packageoffset = $('#blog-detail').offset().top;
        if (scrollTop > packageoffset) {
            $(".blog-socials").addClass("fixed");
        } else {
            $(".blog-socials").removeClass("fixed");
        }
    }
   


});


$(window).on("load", function () {

});