/***************************************************************************************************************
||||||||||||||||||||||||||||         CUSTOM SCRIPT FOR POPULAR            ||||||||||||||||||||||||||||||||||||
****************************************************************************************************************
||||||||||||||||||||||||||||              TABLE OF CONTENT                  ||||||||||||||||||||||||||||||||||||
****************************************************************************************************************
****************************************************************************************************************
1. RevolutionSliderActiver
2. CounterNumberChanger
3. Single gallery slider
4. Accordion Box
5. testimonialCarosule
6. Jquery Tabs Box
7. Main menu
9. Update Scroll to Top
10. Scroll to a Specific 
11. Update Scroll to Top
12. Contact Form Validation   

****************************************************************************************************************
||||||||||||||||||||||||||||            End TABLE OF CONTENT                ||||||||||||||||||||||||||||||||||||
****************************************************************************************************************/
"use strict";
// 1 revolutionSliderActiver
function revolutionSliderActiver () {
	if ($('.rev_slider_wrapper #slider1').length) {
		$("#slider1").revolution({
			sliderType:"standard",
			sliderLayout:"auto",
			delay:5000,
            hideTimerBar:"off",
            onHoverStop:"off",
			navigation: {
				arrows:{enable:true} 
			}, 
			gridwidth:1170,
			gridheight:450 
		});
	};
}

// 2. CounterNumberChanger
function CounterNumberChanger() {
    var sFcounter = $('.sF-counter');
    if (sFcounter.length) {
        sFcounter.appear(function () {
            sFcounter.countTo();

        });
    };

}
//3. SerCarosule
function serCarosule() {
    if ($('.sercarosule').length) {
        $('.sercarosule').owlCarousel({
            loop: true,
            margin:13,
            nav: true,
            navText: [
                    '<i class="fa fa-angle-left" aria-hidden="true"></i>',
                    '<i class="fa fa-angle-right" aria-hidden="true"></i>'
                ],
            dots: false,
            items: 3,
            autoplay: true,
            autoplayTimeout: 3000,
            autoplayHoverPause: true,
            responsive: {
                0: {
                    items: 1
                },
                480: {
                    items: 1
                },
                800: {
                    items: 2
                },
                1000: {
                    items: 2
                },
                1200: {
                    items: 3
                }
            }
        });
    }
}
//3. SerCarosule
function serviceCarosule() {
    if ($('.servicecarosule').length) {
        $('.servicecarosule').owlCarousel({
            loop: true,
            margin:30,
            nav: true,
            navText: [
                    '<i class="fa fa-angle-left" aria-hidden="true"></i>',
                    '<i class="fa fa-angle-right" aria-hidden="true"></i>'
                ],
            dots: false,
            items: 3,
            autoplay: true,
            autoplayTimeout: 3000,
            autoplayHoverPause: true,
            responsive: {
                0: {
                    items: 1
                },
                480: {
                    items: 1
                },
                600: {
                    items: 2
                },
                1000: {
                    items: 3
                },
                1200: {
                    items: 3
                }
            }
        });
    }
}
//3. BlogCarosule
function blogCarosule() {
    if ($('.blogcarosul').length) {
        $('.blogcarosul').owlCarousel({
            loop: true,
            margin:30,
            nav: true,
            navText: [
                    '<i class="fa fa-angle-left" aria-hidden="true"></i>',
                    '<i class="fa fa-angle-right" aria-hidden="true"></i>'
                ],
            dots: false,
            items: 3,
            autoplay: true,
            autoplayTimeout: 3000,
            autoplayHoverPause: true,
            responsive: {
                0: {
                    items: 1
                },
                480: {
                    items: 1
                },
                600: {
                    items: 3
                },
                1000: {
                    items: 3
                }
            }
        });
    }
}
//3. Footercarosule
function trstimonial() {
    if ($('.trstimonial').length) {
        $('.trstimonial').owlCarousel({
            loop: true,
            margin: 0,
            nav: true,
            navText: [
                    '<i class="fa fa-angle-left" aria-hidden="true"></i>',
                    '<i class="fa fa-angle-right" aria-hidden="true"></i>'
                ],
            dots: false,
            items: 1,
            autoplay: true,
            autoplayTimeout: 3000,
            autoplayHoverPause: true,
            responsive: {
                0: {
                    items: 1
                },
                480: {
                    items: 1
                },
                600: {
                    items: 1
                },
                1000: {
                    items: 1
                }
            }
        });
    }
}
//3. Footercarosule
function galleryCarousel() {
    if ($('.gallery-container').length) {
        $('.gallery-container').owlCarousel({
            loop: true,
            margin: 30,
            nav: true,
            navText: [
                    '<i class="fa fa-angle-left" aria-hidden="true"></i>',
                    '<i class="fa fa-angle-right" aria-hidden="true"></i>'
                ],
            dots: false,
            items: 1,
            autoplay: true,
            autoplayTimeout: 3000,
            autoplayHoverPause: true,
            responsive: {
                0: {
                    items: 1
                },
                480: {
                    items: 1
                },
                600: {
                    items: 2
                },
                1000: {
                    items: 3
                }
            }
        });
    }
}
// 5. Brand Carosule
function brandCarosule() {
    if ($('.brand-carousel').length) {
        $('.brand-carousel').owlCarousel({
            loop: true,
            margin:20,
            nav: true,
            navText: [
                    '<i class="fa fa-angle-left" aria-hidden="true"></i>',
                    '<i class="fa fa-angle-right" aria-hidden="true"></i>'
                ],
            dots: false,
            autoplay: true,
            autoplayTimeout: 3000,
            autoplayHoverPause: true,
            responsive: {
                0: {
                    items: 2
                },
                480: {
                    items: 2
                },
                600: {
                    items: 3
                },
                800: {
                    items: 3
                },
                1000: {
                    items: 4
                },
                1200: {
                    items: 4
                }
            }
        });
    }
}
// 5. Brand Carosule
function brandCarosuletwo() {
    if ($('.brand-carousel-2').length) {
        $('.brand-carousel-2').owlCarousel({
            loop: true,
            margin:0,
            nav: true,
            navText: [
                    '<i class="fa fa-angle-left" aria-hidden="true"></i>',
                    '<i class="fa fa-angle-right" aria-hidden="true"></i>'
                ],
            dots: false,
            autoplay: true,
            autoplayTimeout: 3000,
            autoplayHoverPause: true,
            responsive: {
                0: {
                    items: 2
                },
                480: {
                    items: 2
                },
                600: {
                    items: 3
                },
                1000: {
                    items: 3
                },
                1200: {
                    items: 3
                }
            }
        });
    }
}
// 5. Brand Carosule
function Carosuleitem() {
    if ($('.Carosuleitem-2').length) {
        $('.Carosuleitem-2').owlCarousel({
            loop: true,
            margin:28,
            nav: false,
            dots: true,
            autoplay: true,
            autoplayTimeout: 3000,
            autoplayHoverPause: true,
            responsive: {
                0: {
                    items: 1
                },
                480: {
                    items: 1
                },
                600: {
                    items: 2
                },
                1000: {
                    items: 2
                },
                1200: {
                    items: 2
                }
            }
        });
    }
}// 5. Brand Carosule
function Clienttrstimonal() {
    if ($('.client-trstimonal').length) {
        $('.client-trstimonal').owlCarousel({
            loop: true,
            margin:30,
            nav: false,
            dots: false,
            autoplay: true,
            autoplayTimeout: 3000,
            autoplayHoverPause: true,
            responsive: {
                0: {
                    items: 1
                },
                480: {
                    items: 1
                },
                600: {
                    items: 2
                },
                1000: {
                    items: 2
                },
                1200: {
                    items: 2
                }
            }
        });
    }
}
// 4. Sortable Masonary with Filters
function enableMasonry() {
    if ($('.sortable-masonry').length) {

        var winDow = $(window);
        // Needed variables
        var $container = $('.sortable-masonry .items-container');
        var $filter = $('.filter-btns');

        $container.isotope({
            filter: '*',
            masonry: {
                columnWidth: 0
            },
            animationOptions: {
                duration: 500,
                easing: 'linear'
            }
        });


        // Isotope Filter 
        $filter.find('li').click(function () {
            var selector = $(this).attr('data-filter');

            try {
                $container.isotope({
                    filter: selector,
                    animationOptions: {
                        duration: 500,
                        easing: 'linear',
                        queue: false
                    }
                });
            } catch (err) {

            }
            return false;
        });


        winDow.bind('resize', function () {
            var selector = $filter.find('li.active').attr('data-filter');

            $container.isotope({
                filter: selector,
                animationOptions: {
                    duration: 500,
                    easing: 'linear',
                    queue: false
                }
            });
        });


        var filterItemA = $('.filter-btns li');

        filterItemA.click(function () {
            var $this = $(this);
            if (!$this.hasClass('active')) {
                filterItemA.removeClass('active');
                $this.addClass('active');
            }
        });
    }
}

enableMasonry();
//5. Countdown Timer
if ($('#countdown-timer').length) {
    $('#countdown-timer').countdown('2018/2/13', function (event) {
        var $this = $(this).html(event.strftime('' + '<div class="counter-column">Days<br><span class="count">%D</span></div> ' + '<div class="counter-column">Hour<br><span class="count">%H</span><span class="colon"></span></div>  ' + '<div class="counter-column">Mins<br><span class="count">%M</span><span class="colon"></span></div>  ' + '<div class="counter-column">Sec<br><span class="count">%S</span><span class="colon"></span></div>'));
    });
}

// 6. Accordion Box
if ($('.accordion-box').length) {
    $('.accordion-box .acc-btn').click(function () {
        if ($(this).hasClass('active') !== true) {
            $('.accordion-box .acc-btn').removeClass('active');
        }

        if ($(this).next('.acc-content').is(':visible')) {
            $(this).removeClass('active');
            $(this).next('.acc-content').slideUp(500);
        } else {
            $(this).addClass('active');
            $('.accordion-box .acc-content').slideUp(500);
            $(this).next('.acc-content').slideDown(500);
        }
    });
}


//7.  Main menu
function mainmenu() {
    //Submenu Dropdown Toggle
    if ($('.main-menu li.dropdown ul').length) {
        $('.main-menu li.dropdown').append('<div class="dropdown-btn"></div>');

        //Dropdown Button
        $('.main-menu li.dropdown .dropdown-btn').click(function () {
            $(this).prev('ul').slideToggle(500);
        });
    }

}




//9. Hide preloader (must work even if CSS used display:!important — use class + remove node)
window.viyuhaPreloaderDone = window.viyuhaPreloaderDone || false;
function handlePreloader() {
    if (window.viyuhaPreloaderDone) {
        return;
    }
    window.viyuhaPreloaderDone = true;
    var el = document.querySelector(".preloader");
    if (!el) {
        return;
    }
    el.style.transition = "opacity 0.45s ease, visibility 0.45s ease";
    el.style.opacity = "0";
    el.style.visibility = "hidden";
    window.setTimeout(function () {
        el.style.display = "none";
        el.style.pointerEvents = "none";
        if (el.parentNode) {
            el.parentNode.removeChild(el);
        }
    }, 480);
}

//10. Scroll to a Specific Div
if ($('.scroll-to-target').length) {
    $(".scroll-to-target").click(function () {
        var target = $(this).attr('data-target');
        // animate
        $('html, body').animate({
            scrollTop: $(target).offset().top
        }, 1000);

    });
}


//11. Update Scroll to Top
function headerStyle() {
    if ($('.main-header').length) {
        var windowpos = $(window).scrollTop();
        if (windowpos >= 200) {
            $('.main-header').addClass('fixed-header');
            $('.scroll-to-top').fadeIn(300);
        } else {
            $('.main-header').removeClass('fixed-header');
            $('.scroll-to-top').fadeOut(300);
        }
    }
}

headerStyle();

//12. Contact Form Validation
if ($('.contact-form').length) {
    $('.contact-form').validate({
        rules: {
            username: {
                required: true
            },
            lastname: {
                required: true
            },
            email: {
                required: true,
                email: true
            },
            phone: {
                required: true
            },
            message: {
                required: true
            },
            date: {
                required: true
            },
            category: {
                required: true
            },
            website: {
                required: true
            }
        }
    });

}

// Elements Animation
if ($('.wow').length) {
    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)
    });
    wow.init();
}

// Dom Ready Function
jQuery(document).ready(function () {
    (function ($) {
        // add your functions
        revolutionSliderActiver ();
        CounterNumberChanger();
        serCarosule();
        trstimonial();
        brandCarosule();
        brandCarosuletwo();
        blogCarosule();
        Carosuleitem();
        Clienttrstimonal();
        mainmenu();
        enableMasonry();
        galleryCarousel();
        serviceCarosule();
        
        // Dynamic Active Menu Highlighting
        var path = window.location.pathname;
        var page = path.split("/").pop();
        if (page === "" || page === "/") {
            page = "index.html";
        }
        $('.navigation li').removeClass('current');
        $('.navigation li a').each(function() {
            var href = $(this).attr('href');
            if (href === page || (href === "services.html" && page.indexOf("services") !== -1)) {
                $(this).parent('li').addClass('current');
                if($(this).closest('.dropdown').length) {
                    $(this).closest('.dropdown').addClass('current');
                }
            }
        });
        /* Preloader: hide on DOM ready (do not wait for slow images/iframes) */
        window.setTimeout(handlePreloader, 650);
    })(jQuery);
});

jQuery(window).on("load", function () {
    handlePreloader();
});

/* Hard fallback if anything blocks */
window.setTimeout(handlePreloader, 2800);

(function ($) {

    /* ==========================================================================
       When document is Scrollig, do
       ========================================================================== */
    $(window).scroll(function () {
        headerStyle();

    });
})(window.jQuery);