(function($){"use strict";$.fn.hook=function(data){for(var ev in data.actions){var func;if(typeof data.actions[ev]=='function')func=data.actions[ev];else if(typeof data[data.actions[ev]]=='function')func=data[data.actions[ev]];else continue;ev=ev.split(':');if(ev[0]==='')this.on(ev[1],data,func);else this.find(ev[0]).off(ev[1]).on(ev[1],data,func)}return this};yotu_check=null;window.yotuwp={data:{ready:false,players:{},videos:{},actions:{},filters:{}},init:function(){yotuwp.data.ready=true;clearInterval(yotu_check);$(document).ready(function(){var ua=navigator.userAgent,hash=window.location.hash;$('.yotu-playlist').each(function(ind){var that=$(this),player=that.data('yotu'),settings=yotuwp.helper.settings(that),loaded_ids=[],loaded_page=[1],firstId=that.find('.yotu-videos li:first-child a').data('videoid');if(settings.player['autoplay']==0)delete settings.player['autoplay'];if(player!=='modal'&&firstId!==false&&typeof yotuwp.data.players[player]==='undefined'){if(settings.player.loop){settings.player['playlist']=firstId}var player_setting=settings.player,delete_keys=['scrolling','width','mode','playing','playing_description'];delete_keys.map(function(key){if(typeof player_setting[key]!=='undefined')delete player_setting[key]});yotuwp.data.players[player]=new YT.Player('yotu-player-'+player,{width:1000,height:600,playerVars:player_setting,videoId:firstId,events:{'onStateChange':function(e){yotuwp.do_action('player_status',e)}}})}that.find('.yotu-videos a.yotu-video').each(function(ind){var video=$(this),videoId=video.data('videoid'),thumb=video.find('img').attr('src');if(typeof yotuwp.data.videos[videoId]==='undefined')yotuwp.data.videos[videoId]=[];yotuwp.data.videos[videoId].push(thumb);loaded_ids.push(videoId)});that.data('loaded',loaded_ids);that.data('loaded_page',loaded_page);that.data('last_token',settings.next)});$('body').hook({actions:{'.yotu-pagination a:click':'load_more','.yotu-videos a.yotu-video:click':yotuwp.list.events},load_more:function(e){e.preventDefault();var target=$(e.target),wrp=target.closest('.yotu-playlist');if(target.hasClass('yotu-active'))return;target.addClass('yotu-active');yotuwp.list.load(wrp,yotuwp.list.update,{page:target.data('page'),current:wrp.data('page'),func:'pagination'})}});yotuwp.add_action('player_status',yotuwp.player.status);yotuwp.add_action('player_status_modal',yotuwp.player.status);if(hash!=''&&typeof yotuwp.data.videos[hash.replace('#','')]!=='undefined'){setTimeout(function(){$("a[href='"+hash+"']").trigger('click')},1000)}})},helper:{decode:function(str){return JSON.parse(decodeURIComponent(window.atob(str)))},encode:function(obj){return window.btoa(encodeURIComponent(JSON.stringify(obj)))},settings:function(elm){return JSON.parse(decodeURIComponent(window.atob(elm.data('settings'))))},},add_action:function(name,callback){if(yotuwp.data.actions[name]===undefined)yotuwp.data.actions[name]=[];yotuwp.data.actions[name].push(callback)},do_action:function(name){var params=Array.prototype.slice.call(arguments,1);if(yotuwp.data.actions[name]!==undefined){var res;yotuwp.data.actions[name].map(function(func){if(typeof func=='function'){try{res=func.apply(null,params)}catch(e){console.warn('action '+name+':'+e.message)}}})}},apply_filter:function(name,val){var params=Array.prototype.slice.call(arguments,2,arguments.length);params.push(val);if(yotuwp.data.filters[name]!==undefined){yotuwp.data.filters[name].map(function(func){if(typeof func=='function'){try{val=func.apply(null,params)}catch(e){console.warn('action '+name+':'+e.message)}}})}return val},add_filter:function(name,callback){if(yotuwp.data.filters[name]===undefined)yotuwp.data.filters[name]=[];yotuwp.data.filters[name].push(callback)},l:function(ind){return(yotujs.lang[ind]!=='undefined')?yotujs.lang[ind]:''},player:{data:{},current:{'player':null,'video':null,'list':null},play:function(video,list){var player=list.data('yotu'),settings=yotuwp.helper.settings(list),loaded_ids=list.data('loaded');if(typeof yotuwp.data.players[player]!=='undefined'||player=='modal'){if(player==='modal'){yotuwp.player.lightbox.open(video,settings,list)}else{var playtimer=setInterval(function(){if(typeof yotuwp.data.players[player]['loadVideoById']=='function'){yotuwp.data.players[player].loadVideoById(video);var pos=list.offset().top-settings.player.scrolling;if(settings.player.scrolling==0){var pheight=jQuery('#yotu-player-'+player).outerHeight(),wheight=jQuery(window).height();pos=list.offset().top-parseInt((wheight-pheight)/2)}$('html, body').animate({scrollTop:pos},500);clearInterval(playtimer)}},10)}this.current={'player':player,'video':video,'list':list};yotuwp.do_action('after_play_video',loaded_ids,video,player);this.info();this.pause()}},pause:function(){for(var p in yotuwp.data.players){if(p!==yotuwp.player.current.player&&typeof yotuwp.data.players[p]!=='undefined'&&typeof yotuwp.data.players[p]['pauseVideo']=='function')yotuwp.data.players[p].pauseVideo()}},gen_thumbs:{},info:function(){var wrp=$('#yotu-player-'+yotuwp.player.current.player).closest('.yotu-wrapper-player');wrp.find('.yotu-playing').html(yotuwp.data.videos[this.current.video][0]);wrp.find('.yotu-playing-description').html(yotuwp.data.videos[this.current.video][1])},lightbox:{loaded:false,render:function(){var html_a=['
'];html_a=yotuwp.apply_filter('next_prev',html_a);var elm=$(html_a.join('')).appendTo('body');elm.hook({actions:{'.yotu-lightbox-overlay, .yotu-lightbox-close:click':yotuwp.player.lightbox.close,'.yotu-lightbox-func:click':'start_hook',},start_hook:function(e){e.preventDefault();yotuwp.do_action('lightbox_actions',this)}});this.loaded=true},open:function(video,settings,list){if(!this.loaded){this.render()}if(!list.is(yotuwp.player.current.list)){settings.player['enablejsapi']=1;var player_setting=settings.player,delete_keys=['scrolling','width','mode','playing','playing_description'];delete_keys.map(function(key){if(typeof player_setting[key]!=='undefined')delete player_setting[key]});player_setting['origin']=document.location.protocol+"//"+document.location.hostname;player_setting['enablejsapi']=1;player_setting['iv_load_policy']=3;player_setting['widgetid']=3;yotuwp.player.current.list=list;$('#yotu-player-modal').replaceWith('');yotuwp.data.players['modal']=new YT.Player('yotu-player-modal',{width:1000,height:600,playerVars:player_setting,videoId:video,events:{'onStateChange':function(e){yotuwp.do_action('player_status_modal',e)}}})}else{yotuwp.data.players['modal'].loadVideoById(video)}if(settings.player.playing){$('.yotu-lightbox').addClass('yotu-show-title')}if(settings.player.thumbnails&&settings.pagination){var loaded_ids=list.data('loaded'),thumbs=$('#yotu-thumbnails'),loaded_page=list.data('loaded_page'),current=Math.max.apply(Math,loaded_page),total=list.data('total');$('.yotu-lightbox .yotu-thumbnails').removeClass('yotu-thumb-169');if(list.hasClass('yotu-thumb-169'))$('.yotu-lightbox .yotu-thumbnails').addClass('yotu-thumb-169');if(current