jQuery('#carouselVideos').on('slide.bs.carousel', function onSlide (ev) {
    var id = ev.relatedTarget.id;
    callWebService(id);
});
jQuery('#carouselFotos').on('slide.bs.carousel', function onSlide (ev) {
    var id = ev.relatedTarget.id;
    callWebService(id);
});
jQuery('#carouselMusica').on('slide.bs.carousel', function onSlide (ev) {
    var id = ev.relatedTarget.id;
    callWebService(id);
});
jQuery('#carouselCalendario').on('slide.bs.carousel', function onSlide (ev) {
    var id = ev.relatedTarget.id;
    callWebService(id);
});
jQuery('#carouselTimeline').on('slide.bs.carousel', function onSlide (ev) {
    var id = ev.relatedTarget.id;
    callWebService(id);
});

jQuery(document).ready(function() {
    callWebService('carouselFotosItem_0');
    callWebService('carouselMusicaItem_0');
    callWebService('carouselVideosItem_0');
    callWebService('carouselCalendarioItem_0');
    callWebService('carouselTimelineItem_0');
});

function callWebService(id){
	var altoIframe = 446; //Math.trunc(jQuery('#main').height()-96-24);
    var elemento = jQuery('#'+id+ ' .carousel-item-inner');
    if(elemento.length>0){
        var item = listaContenido[id];
        if(!elemento.hasClass( "cargado" )){
            jQuery.ajax({
                url: urlSitio+'/wp-content/plugins/u99_redessociales/u99_redessociales_content.php',
                cache: false,
                dataType: 'json',
                data: { 
                    ll: u99_ll,
                    ca: u99_ca,
                    sitioID: item['sitio_id'],
                    postID: item['post_id'],
                    tipo: item['tipo'],
                    fuente: item['fuente'],
                    altoIframe: altoIframe
                },
                type: 'POST',
                success:  function (response) {
                    if(response.codigorespuesta === 'S'){
                        elemento.html(response.respuestas);
                        elemento.addClass('cargado');
                        switch (item['fuente']) {
                            case 'facebook':
                                FB.init({
                                    appId      : '187264734654184',
                                    status     : true,
                                    xfbml      : true,
                                    version    : 'v2.7' // or v2.6, v2.5, v2.4, v2.3
                                });
                                break;
                            case 'instagram':
                                window.instgrm.Embeds.process();
                            case 'twitter':
                                twttr.widgets.load();
                                break;
                            default:
                                break;
                        }
                        
                    }
                    //console.log(response);
                },
                fail: function(response){
                    //volverAcargar();
                },
                error: function(xhr, textStatus, errorThrown){
                    //volverAcargar();
                }
            });
        }else{
            if(item['fuente']==='facebook'){
                FB.init({
                    appId      : '187264734654184',
                    status     : true,
                    xfbml      : true,
                    version    : 'v2.7' // or v2.6, v2.5, v2.4, v2.3
                });
            }
        }
    }
}