var tdYoutubePlayers={};jQuery().ready(function(){tdYoutubePlayers.init()});
(function(){tdYoutubePlayers={tdPlayerContainer:"player_youtube",players:[],init:function(){for(var c=jQuery(".td_wrapper_playlist_player_youtube"),e=0;e<c.length;e++){var a=jQuery(c[e]),b=tdYoutubePlayers.addPlayer(a),g=b.tdPlayerContainer;a.parent().find(".td_youtube_control").data("player-id",g);for(var d=a.parent().find(".td_click_video_youtube"),f=0;f<d.length;f++)jQuery(d[f]).data("player-id",g),f+1<d.length?jQuery(d[f]).data("next-video-id",jQuery(d[f+1]).data("video-id")):jQuery(d[f]).data("next-video-id",
jQuery(d[0]).data("video-id"));"1"==a.data("autoplay")&&(b.autoplay=1,b.mute=1);a=a.data("first-video");""!==a&&(b.tdPlaylistIdYoutubeVideoRunning=a,b.playVideo(a))}jQuery(".td_click_video_youtube").on("click",function(){var a=jQuery(this).data("video-id"),b=jQuery(this).data("player-id");void 0!==b&&""!==b&&void 0!==a&&""!==a&&tdYoutubePlayers.operatePlayer(b,"play",a)});jQuery(".td_youtube_control").on("click",function(){var a=jQuery(this).data("player-id");void 0!==a&&""!==a&&(jQuery(this).hasClass("td-sp-video-play")?
tdYoutubePlayers.operatePlayer(a,"play"):tdYoutubePlayers.operatePlayer(a,"pause"))})},addPlayer:function(c){c=tdYoutubePlayers.createPlayer(tdYoutubePlayers.tdPlayerContainer+"_"+tdYoutubePlayers.players.length,c);tdYoutubePlayers.players.push(c);return c},operatePlayer:function(c,e,a){for(var b=0;b<tdYoutubePlayers.players.length;b++)if(tdYoutubePlayers.players[b].tdPlayerContainer==c){c=tdYoutubePlayers.players[b];c.playStatus();"play"===e?(c.autoplay=1,c.mute=0,void 0===a?c.playerPlay():c.playVideo(a)):
"pause"==e&&tdYoutubePlayers.players[b].playerPause();break}},createPlayer:function(c,e){var a={tdYtPlayer:"",tdPlayerContainer:c,autoplay:0,mute:0,tdPlaylistIdYoutubeVideoRunning:"",jqTDWrapperVideoPlaylist:e.closest(".td_wrapper_video_playlist"),jqPlayerWrapper:e,jqControlPlayer:"",_videoId:"",playVideo:function(b){a._videoId=b;"undefined"===typeof YT||"undefined"===typeof YT.Player?(window.onYouTubePlayerAPIReady=function(){for(var a=0;a<tdYoutubePlayers.players.length;a++)tdYoutubePlayers.players[a].loadPlayer()},
jQuery.getScript("https://www.youtube.com/player_api").done(function(a,b){})):a.loadPlayer(b)},loadPlayer:function(b){var c=a._videoId;void 0!==b&&(c=b);if(void 0!==c){a.tdPlaylistIdYoutubeVideoRunning=c;b=window.td_youtube_list_ids["td_"+a.tdPlaylistIdYoutubeVideoRunning].title;var d=window.td_youtube_list_ids["td_"+a.tdPlaylistIdYoutubeVideoRunning].time;a.jqTDWrapperVideoPlaylist.find(".td_click_video_youtube").removeClass("td_video_currently_playing");a.jqTDWrapperVideoPlaylist.find(".td_"+c).addClass("td_video_currently_playing");
a.jqTDWrapperVideoPlaylist.find(".td_current_video_play_title_youtube").html(b);a.jqTDWrapperVideoPlaylist.find(".td_current_video_play_time_youtube").html(d);a.jqPlayerWrapper.html("<div id="+a.tdPlayerContainer+' class="td-youtube-player"></div>');a.jqControlPlayer=a.jqTDWrapperVideoPlaylist.find(".td_youtube_control");a.tdYtPlayer=new YT.Player(a.tdPlayerContainer,{playerVars:{autoplay:a.autoplay,mute:a.mute},height:"100%",width:"100%",videoId:c,events:{onReady:a.onPlayerReady,onStateChange:a.onPlayerStateChange}})}},
onPlayerReady:function(a){if("undefined"!==typeof tdShowVideo)tdShowVideo.onYoutubeReadyEvent(a)},onPlayerStateChange:function(b){if(b.data===YT.PlayerState.PLAYING)a.pauseStatus();else if(b.data===YT.PlayerState.ENDED){a.playStatus();a.autoplay=1;a.mute=0;var c="",d=a.jqTDWrapperVideoPlaylist.find(".td_video_currently_playing");d.length&&(d=jQuery(d).next(".td_click_video_youtube"),d.length&&(c=jQuery(d).data("video-id")));""!==c&&a.playVideo(c)}else YT.PlayerState.PAUSED&&a.playStatus();if("undefined"!==
typeof tdShowVideo)tdShowVideo.onYoutubeStateChangeEvent(b)},playerPlay:function(){a.tdYtPlayer.playVideo()},playerPause:function(){a.tdYtPlayer.pauseVideo()},playStatus:function(){a.jqControlPlayer.removeClass("td-sp-video-pause").addClass("td-sp-video-play")},pauseStatus:function(){a.jqControlPlayer.removeClass("td-sp-video-play").addClass("td-sp-video-pause")}};return a}}})();
