/*  ==================================
 *           js content
 *    ==================================*/

(function ($) {

    "use strict";

    var $mainwindow = $(window);
    $mainwindow.on('load', function () {
        $('.preloader').fadeOut(500);
    });

    /*====================================
        Sticky js
    ======================================*/
    var navbar = $('.affix');
    var mobile_navbar = $('.mobile-menu');
    var scrolled = false;
    $mainwindow.on('scroll', function () {
        if (200 < $mainwindow.scrollTop() && !scrolled) {
            navbar.addClass('sticky_menu animated fadeInDown').animate({
                'margin-top': '0px'
            });
            mobile_navbar.addClass('sticky_menu animated fadeInDown').animate({
                'margin-top': '0px'
            });
            scrolled = true;
        }
        if (200 > $mainwindow.scrollTop() && scrolled) {
            navbar.removeClass('sticky_menu animated fadeInDown').css('margin-top', '0px');
            mobile_navbar.removeClass('sticky_menu animated fadeInDown').css('margin-top', '0px');
            scrolled = false;
        }
    });
    // main slider 
    var owlmain = $('.slider-main');
    owlmain.owlCarousel({
        margin: 0,
        loop: true,
        autoplay: false,
        nav: true,
        navText: ["<i class='fa fa-angle-left'></i>", "<i class='fa fa-angle-right'></i>"],
        items: 1,
        lazyLoad: true,
        navContainer: '.inner-con',
        // move dotsContainer outside the primary owl wrapper
        dotsContainer: '.slider-dot-con',


    });
    $(".sld-prev").on('click', function () {
        owlmain.trigger('prev.owl.carousel');

    });
    $(".sld-next").on('click', function () {
        owlmain.trigger('next.owl.carousel');

    });
    var service_slider = $('.service-slider');
    service_slider.owlCarousel({
        margin: 30,
        loop: true,
        dots: false,
        navContainer: '.service-nav',
        nav: true,
        navText: ["<i class='fa fa-angle-left'></i>", "<i class='fa fa-angle-right'></i>"],
        responsive: {
            0: {
                items: 1,
                nav: false,
                dots: true
            },
            600: {
                items: 2,
                dots: true
            },
            768: {
                items: 2
            },
            1000: {
                items: 3
            },
            1200: {
                items: 3
            }
        }

    });
    var feature_slider = $('.feature-slider');
    feature_slider.owlCarousel({
        margin: 30,
        loop: true,
        dots: true,
        items: 4,
        nav: false,
        navText: ["<i class='fa fa-angle-left'></i>", "<i class='fa fa-angle-right'></i>"],
        responsive: {
            0: {
                items: 1,
                nav: false,
                dots: true
            },
            600: {
                items: 2,
                dots: true
            },
            768: {
                items: 2
            },
            1000: {
                items: 3
            },
            1200: {
                items: 4
            }
        }

    });

    var owltestimonial = $('.testimonial-slider');
    owltestimonial.owlCarousel({
        margin: 0,
        loop: true,
        dots: true,
        nav: false,
        navText: ["<i class='fa fa-angle-left'></i>", "<i class='fa fa-angle-right'></i>"],
        responsive: {
            0: {
                items: 1,
                nav: false,
                dots: true
            },
            600: {
                items: 1
            },
            1000: {
                items: 1
            },
            1200: {
                items: 1
            }
        }

    });

    var owltestimonial2 = $('.testimonial-slider2');
    owltestimonial2.owlCarousel({
        margin: 30,
        loop: true,
        dots: true,
        nav: false,
        navText: ["<i class='fa fa-angle-left'></i>", "<i class='fa fa-angle-right'></i>"],
        responsive: {
            0: {
                items: 1,
                nav: false,
                dots: true
            },
            600: {
                items: 1,
                nav: false,
                dots: true
            },
            768: {
                items: 2
            },
            1000: {
                items: 2
            },
            1200: {
                items: 2
            }
        }

    });
    var owlpartnerslider = $('.partner-slider');
    owlpartnerslider.owlCarousel({
        margin: 30,
        loop: true,
        dots: false,
        nav: false,
        navText: ["<i class='fa fa-angle-left'></i>", "<i class='fa fa-angle-right'></i>"],
        responsive: {
            0: {
                items: 2,
                nav: false,
                dots: false
            },
            600: {
                items: 3
            },
            1000: {
                items: 5
            },
            1200: {
                items: 6
            }
        }

    });

    $('.marquee-rates').marquee({
        //duration in milliseconds of the marquee
        duration: 15000,
        //gap in pixels between the tickers
        gap: 0,
        //time in milliseconds before the marquee will start animating
        delayBeforeStart: 0,
        //'left' or 'right'
        direction: 'left',
        //true or false - should the marquee be duplicated to show an effect of continues flow
        duplicated: true,
        startVisible: true,
        pauseOnHover: true
    });
    $('a[href="#search"]').on('click', function (event) {
        $('#search').addClass('open');
        $('#search > form > input[type="search"]').focus();
    });
    $('#search, #search button.close').on('click keyup', function (event) {
        if (event.target == this || event.target.className == 'close' || event.keyCode == 27) {
            $(this).removeClass('open');
        }
    });
    $('.count').counterUp({
        delay: 10,
        time: 1000
    });
    /*====================================
            slick nav
        ======================================*/
    var logo_path = $('.logo-container').html();
    $('#main-menu').slicknav({
        appendTo: '.mobile-menu',
        removeClasses: true,
        label: '',
        closedSymbol: '<i class="fa fa-angle-right"><i/>',
        openedSymbol: '<i class="fa fa-angle-down"><i/>',
        brand: logo_path
    });
    /*====================================
            skip content
        ======================================*/
    $(document).ready(function() {
    $('#main-menu').accessibleDropDown();
    });

    $.fn.accessibleDropDown = function () {
        var el = $(this);

        /* Make dropdown menus keyboard accessible */

        $("a", el).focus(function() {
            $(this).parents("li").addClass("on-focus");
        }).blur(function() {
            $(this).parents("li").removeClass("on-focus");
        });
    }

    /* ----------------------------------------------------------- */
    /*  BACK TO TOP
    /* ----------------------------------------------------------- */

    $(window).scroll(function () {
        if ($(this).scrollTop() > 800) {
            $("#back-to-top").addClass("show-back-to-top");
        } else {
            $("#back-to-top").removeClass("show-back-to-top");
        }
    });
    $("#back-to-top").on("click", function () {
        $("html, body").animate({
            scrollTop: 0
        }, 800);
        return false;
    });

    var BoxHover = function () {
        jQuery('.team').on('mouseenter', function () {
            jQuery(this).closest('.row').find('.team').removeClass('active');
            jQuery(this).addClass('active');
        });
    };
    BoxHover();


    $('.bs-btn').on('click', function () {
        $('.bs-btn').removeClass('active');
        $(this).addClass('active');
    });

})(jQuery);


/* =========================================
    buy and sell filtering
  ===========================================*/

forexn_filterSelection("all");

function forexn_filterSelection(c) {
    var x, i;
    x = document.getElementsByClassName("filterDiv");
    if (c == "all") c = "";
    for (i = 0; i < x.length; i++) {
        forexn_w3RemoveClass(x[i], "show");
        if (x[i].className.indexOf(c) > -1) forexn_addClass(x[i], "show");
    }
}

function forexn_addClass(element, name) {
    var i, arr1, arr2;
    arr1 = element.className.split(" ");
    arr2 = name.split(" ");
    for (i = 0; i < arr2.length; i++) {
        if (arr1.indexOf(arr2[i]) == -1) {
            element.className += " " + arr2[i];
        }
    }
}

function forexn_w3RemoveClass(element, name) {
    var i, arr1, arr2;
    arr1 = element.className.split(" ");
    arr2 = name.split(" ");
    for (i = 0; i < arr2.length; i++) {
        while (arr1.indexOf(arr2[i]) > -1) {
            arr1.splice(arr1.indexOf(arr2[i]), 1);
        }
    }
    element.className = arr1.join(" ");
}
