$(document).ready(function(){
    if($('#categorias_mobile[target-category=""]').length){
        $('.categorias_mobile').owlCarousel({
            loop: true,
            items: 4,
            autoWidth: true,
            autoplay: false,
            touchDrag: true,
            nav: false,
            dots: false
        });

        showCategorias();

        $(window).scroll(function() {
            showCategorias();
        });
    }

    $('.preview-video iframe:not(.js-iframe-vimeo-responsive)').each(function(){
        var iframe_height = $(this).width() * 0.56;
        $(this).height(iframe_height);
    });


    // var areaPost = $('.blog-conteudo').outerWidth();

    // $('.preview-img img').css('width', 'auto !important');

});

function showCategorias(){
    if($('#categorias_mobile').length){
        var height_window = $(window).height() * 0.8;
        var scroll_window = $(window).scrollTop();

        var fadeCategorias = (scroll_window >= height_window) ? true : false;

        if (fadeCategorias) {
            $('.categorias_mobile').stop().addClass('fixed');
            $('#categorias_mobile span.clear').stop().show();
        }
        else {
            $('.categorias_mobile').stop().removeClass('fixed');
            $('#categorias_mobile span.clear').stop().hide();
        }
    }
}

var vid = $(".video_div iframe");
var altura = vid.width() * 0.52;
vid.attr('style','height:'+ altura +'px !important');
window.onresize = function() {
    var altura = vid.width() * 0.52;
    vid.attr('style','height:'+ altura +'px !important');
};

if( $('#player').length && $('.video_div').length ) {
    function onYouTubeIframeAPIReady() {
        player = new YT.Player('meuVideo2', {
            events: {
                'onStateChange': onPlayerStateChange
            }
        });
    }
    function onPlayerStateChange(event) {
        if (event.data == YT.PlayerState.PLAYING) {
            document.getElementById("player").pause();
            $('.buttonsPlayer #pause').hide(0);
            $('.buttonsPlayer #play').show(0);
        }
    }
}

// VIMEO API
function meuVideo(tipo) {
    if( $('#player').length && $('.video_div').length ) {
        if (tipo == 1) { //if vimeo
            $.getScript("https://player.vimeo.com/api/player.js", function () {
            }).done(function () {
                var iframe = document.getElementById("meuVideo");
                var player = new Vimeo.Player(iframe);
                player.on('play', function () {
                    document.getElementById("player").pause();
                    $('.buttonsPlayer #pause').hide(0);
                    $('.buttonsPlayer #play').show(0);
                });
            });
        }
    }
}