
  /* ==============================================
  Main Elements
  =============================================== */
  jQuery(document).ready(function ($) {
    'use strict';
       $(function () {
        $('a[href*=#]:not([href=#])').on('click', function () {
            if (location.pathname.replace(/^\//, '') == this.pathname.replace(/^\//, '') && location.hostname == this.hostname) {
                var target = $(this.hash);
                target = target.length ? target : $('[name=' + this.hash.slice(1) + ']');
                if (target.length) {
                    $('html,body').animate({
                        scrollTop: target.offset().top
                    }, 1000);
                    return false;
                }
            }
        });
    });
   
    // One Page Nav
    $('.navbar-nav').onePageNav({
			currentClass: 'active',
			changeHash: false,
			scrollSpeed: 750
		});
     // Fit Video
    try {
        $(".fit-videos").fitVids();
    }
    catch(err) {
        
    }
// Side menu toggle
$(".navbar .navbar-nav li a").on('click', function (event) {
    var $this = $(this);
    
    // Check if the clicked item has a dropdown
    if ($this.parent().hasClass('menu-item-has-children')) {
        event.preventDefault(); // Prevent closing the navbar when clicking a parent menu item
        $this.next('.dropdown-menu').toggle(); // Toggle the dropdown menu
    } else {
        // If it’s a regular menu item, close the navbar
        $(".navbar-collapse").removeClass("show");
    }
});

// Close menu on clicking the close button
$(".close-menu").on('click', function () {
    $(".navbar-collapse").removeClass("show");
});

// Optional: Close dropdowns when clicking outside
$(document).on('click', function (e) {
    if (!$(e.target).closest('.navbar').length) {
        $(".navbar-collapse").removeClass("show");
    }
});
   /* ==============================================
    Preloader
    =============================================== */
	$(window).on("load", function() {
        $("#preloader").fadeOut(600);
        $(".preloader-bg").delay(400).fadeOut(600);
		
        setTimeout(function() {
            $(".fadeIn-element").delay(600).css({
                display: "none"
            }).fadeIn(800);
        }, 0);
    }); 
   /* ==============================================
    Hero Section
    =============================================== */
    function parallax() {
        var scrollPosition = $(window).scrollTop();
        $('.hero').css('opacity', ((100 - scrollPosition / 2) * 0.01));
    }
        $(window).on('scroll', function () {
            parallax();
        });
	   
    /* ==============================================
    OnScroll Animation
    =============================================== */
    	$('.animated').appear(function() {

	        var elem = $(this);
	        var animation = elem.data('animation');

	        if ( !elem.hasClass('visible') ) {
	        	var animationDelay = elem.data('animation-delay');
	            if ( animationDelay ) {
	                setTimeout(function(){
	                    elem.addClass( animation + " visible" );
	                }, animationDelay);

	            } else {
	                elem.addClass( animation + " visible" );
	            }
	        }
	    });
    /* ==============================================
    CountTo
    =============================================== */
	$('.numbers-value').countTo();
    /* ==============================================
    Home Slide
    =============================================== */ 
    function initHomeSlider(forceInit) {

        if( !forceInit ) {

            if( ! $( '.hiddenslide' ).length ) {
                return false;
            }

        }

        var hslides = [];

        jQuery( '.hiddenslide').each( function() {

            var $this = jQuery( this );
            hslides.push( $this.attr('data-src') );

        });

        $.backstretch( hslides, {duration: 2600, fade: 1000, centeredY: false});

    }

    initHomeSlider(false);
    
    $('.home-slider').flexslider({
        animation: "slide",
        directionNav: false,
        controlNav: false,
        direction: "vertical",
        slideshowSpeed: 3600,
        animationSpeed: 1000,
        smoothHeight: true
    });
    /* ==============================================
    Video Background
    =============================================== */ 
    if( $( '.video-bg' ).length ) {

        if(jQuery.browser.mobile) {
            initHomeSlider(true);
        } else {
            $( '.video-bg' ).mb_YTPlayer();
        }      

    }
    /* ==============================================
    FlexSlider
    =============================================== */ 
    function initFlexSlider(){

        $('.flexslider').flexslider({
            animation: "slide",
            directionNav: false,
            slideshowSpeed: 3500,
            animationSpeed: 1000
        });

    }
    
    initFlexSlider();
    /* ==============================================
    Testimonials
    =============================================== */ 
      $('.testimonials-slider').flexslider({
        animation: "slide",
        animationSpeed: 1000,
        slideshow: true
    });

});
