$(function () {

    gallerfy();
    var curPicPos = 0;
    //Pictures details view

    $('#impact-btn').click(function(){
        analytics.track('Partner CTA Button Clicked', {
          name: 'partnerships_page',
          platform: 'Wordpress'
        });

        console.log('Partner CTA Button Clicked');
    })

    $(".picflex .resultitem .mission_slider .card-image a").click(function() {
        var c = $(this).attr('data-company'),
            h = $(this).attr('data-hashtag');

        analytics.track('Partner Mission Clicked', {
          partner_name: c,
          hashtag: h,
          platform: 'Wordpress'
        });
        console.log('Partner Mission Clicked - ' + c + ', ' + h);
    });

    var openPicFlex =  function(e) {
        $(".picflex .resultitem.open").removeClass("open").css('min-height', 0);

        var _me = $(e.target).closest('.resultitem');
        _me.addClass("open");

        if(!$(e.target).attr('no-scroll') == '1') {
            curPicPos = _me.find('.box').attr('data-pos');
            curPicPos = parseInt(curPicPos) + 60; /*+ _me.find('.box').height()*/
            $(window).scrollTop(curPicPos);
            //$(window).animate({ scrollTop: curPicPos }, 200);

            var c = _me.attr('data-company');

            analytics.track('Partner See More', {
              partner_name: c,
              platform: 'Wordpress'
            });
            console.log('Partner See More - ' + c);
        }
        $(e.target).removeAttr('no-scroll');
        $('.viewchange .resultitem .box').addClass('is-active');

        var heigh_count =  _me.find('.detailview.container .row').height();
        var counterH = $('.viewchange .resultitem .box').height();

        var addH  = heigh_count + counterH;

        _me.css('min-height', addH);

        e.preventDefault();
    };

    var closePicFlex = function(e) {
        $(".picflex .resultitem.open").removeClass("open").css('min-height', 0)
            .find('.box').removeClass('is-active');
        e.preventDefault();
    }

    $(".picflex .resultitem > .box a.clickevent, .picflex .resultitem > .box a.detailClose").click(function (e) {
        if($(this).closest('.resultitem').hasClass('open')) {
            closePicFlex(e);
        } else {
            openPicFlex(e)
        }
    });


    $(window).bind("load resize", function() {
        if($(".picflex .resultitem.open").size() > 0) {
            var heigh_count =  $(".picflex .resultitem.open .detailview.container").height();
            var counterH = $('.viewchange .resultitem .box').height();

            var addH  = heigh_count + counterH;

            $(".picflex .resultitem.open").css('min-height',addH );
        }

    });

    $(window).scroll(function() {
        if($(".picflex .resultitem.open").size() > 0) {
            var heigh_count =  $(".picflex .resultitem.open .detailview.container").height();
            var counterH = $('.viewchange .resultitem .box').height();

            var addH  = heigh_count + counterH;

            $(".picflex .resultitem.open").css('min-height',addH );
        }
    });

    // open the third partner
      $(window).on("load", function() {
        $(".pictureView .resultitem:nth-child(3) a.clickevent").attr('no-scroll', '1').click();
    });

    /*scroll to top start*/
    $(window).scroll(function () {
        if ($(this).scrollTop() > 150) {
            $('a[href="#top"]').show();
        } else {
            $('a[href="#top"]').hide();
        }
    });

    // scroll body to 0px on click
    $('a[href="#top"]').click(function () {
        $(window).animate({
            scrollTop: 0
        }, 800);
        return false;
    });

    $('header button.navbar-toggler').click(function() {
        $('#header-mobile-nav').show();
        return false;
    });

    $('#close-header-mobile-nav').click(function() {
        $('#header-mobile-nav').hide();
        return false;
    });

});



//$.getScript('//cdn.rawgit.com/xremix/xGallerify/master/dist/jquery.xgallerify.min.js', function () {
function gallerfy() {
    $('.picflex .box').each(function () {
        /*var boxWidth = $(this).attr('data-imgWidth'),
            boxHeight = $(this).attr('data-imgHeight');
        (boxWidth > boxHeight) ? $(this).parent().attr('style', "width:" + parseInt(boxWidth * 200 / boxHeight) + "px"): $(this).parent().attr('style', "width:" + parseInt(180 / boxHeight * boxWidth) + "px");*/
        $(this).attr('data-pos', parseInt($(this).offset().top) - 65);
    });
    //var gallery = $('.picflex').gallerify({
    //    mode: {
    //        maxHeight: screen.height * 0.5,
    //        breakPoints: [
    //      {
    //          minWidth: 1170,
    //          columns: 5,
    //      }, {
    //          minWidth: 970,
    //          columns: 4,
    //      }, {
    //          minWidth: 750,
    //          columns: 3,
    //      }, {
    //          maxWidth: 750,
    //          columns: 2,
    //      }
    //        ]
    //    },
    //    lastRow: 'adjust'
    //});
}
//});


$(function() {
        var swiper = new Swiper(".mission_Swipper", {
        slidesPerView: 1.5,
        spaceBetween: 20,
        //slidesPerGroup: 4,
        freeMode: true,
        grabCursor: true,
        centeredSlides: false,
        loop: false,
        pagination: {
            el: ".swiper-pagination",
            clickable: true
        },
        //            autoplay: {
        //                delay: 4000,
        //                disableOnInteraction: false
        //            },
        navigation: {
            nextEl: ".swiper-button-next",
            prevEl: ".swiper-button-prev"
        },

        breakpoints: {
            640: {
                slidesPerView: 2
            },
            1024: {
                slidesPerView: 3,
                spaceBetween: 24,
            }
        }
    });


    var swiper = new Swiper(".Upcoming_Swipper", {
        slidesPerView: 1.5,
        spaceBetween: 15,
        centeredSlides: false,
        //slidesPerGroup: 4,
        freeMode: true,
        grabCursor: true,
        loop: false,
        pagination: {
            el: ".swiper-pagination",
            clickable: true
        },
        //            autoplay: {
        //                delay: 4000,
        //                disableOnInteraction: false
        //            },
        navigation: {
            nextEl: ".swiper-button-next",
            prevEl: ".swiper-button-prev"
        },

        breakpoints: {
            640: {
                slidesPerView: 2,
                spaceBetween: 10
            },
            768: {
                slidesPerView: 2,
                spaceBetween: 24,
            },
            1024: {
                slidesPerView: 3,
                spaceBetween: 24,
            }
        }
    });
})