function onYouTubeIframeAPIReady() { //console.log('Api ready'); window.___youtubeInitialized = true; window.___youtubeLoadFromQueue(); } if (!window.___youtubeIframeApiTriggered) { var tag = document.createElement('script'); tag.src = "https://www.youtube.com/iframe_api"; var firstScriptTag = document.getElementsByTagName('script')[0]; firstScriptTag.parentNode.insertBefore(tag, firstScriptTag); window.___youtubeIframeApiTriggered = true; } if (!window.___youtubeBuildPlayer) { window.___youtubeBuildPlayer = function (divid, youtubeid, musaid, height, width) { new YT.Player(divid, { allowfullscreen: true, height: height, width: width, videoId: youtubeid, events: { 'onReady': function (){}, 'onStateChange': function (event) { switch (event.data) { case YT.PlayerState.PLAYING: //console.log('playing'); this.paused = false; this.start = new Date(); break; case YT.PlayerState.ENDED: //not needed, video triggers paused before ended break; case YT.PlayerState.PAUSED: if (!this.paused) { this.paused = true; var date = new Date(); var logstring = Number((((date - this.start) / 1000)).toFixed()); _gaq.push(['_trackEvent', 'youtube-logger', 'played', musaid+'', logstring]); // _gaq.push(['_trackEvent', 'youtube-logger', musaid+'', logstring]); //console.log('pushed to _gaq:'+musaid+'|'+logstring); } break; case YT.PlayerState.BUFFERING: break; case YT.PlayerState.CUED: break; } } } }); }; } if (!window.___youtubeLoadFromQueue) { window.___youtubeQueue = new Array(); window.___youtubeLoadFromQueue = function () { if (window.___youtubeQueue.length > 0) { //console.log('loading queue'); for (var i = 0; i < window.___youtubeQueue.length; i++) { window.___youtubeBuildPlayer(window.___youtubeQueue[i][0], window.___youtubeQueue[i][1], window.___youtubeQueue[i][2], window.___youtubeQueue[i][3], window.___youtubeQueue[i][4]); } } }; } if (!window.___youtubeQueueOrBuild) { window.___youtubeQueueOrBuild = function (divid, youtubeid, musaid, height, width) { if (window.___youtubeInitialized) { //console.log('buildplayer'); window.___youtubeBuildPlayer(divid, youtubeid, musaid, height, width); } else { //console.log('queue'); window.___youtubeQueue[window.___youtubeQueue.length] = [divid, youtubeid, musaid, height, width]; } }; } if (!window.___youtubeS4) { window.___youtubeS4 = function () { return Math.floor((1 + Math.random()) * 0x10000) .toString(16) .substring(1); }; } var tag = document.createElement('div'); tag.id = window.___youtubeS4() + window.___youtubeS4() + '-' + window.___youtubeS4() + '-' + window.___youtubeS4() + '-' + window.___youtubeS4() + '-' + window.___youtubeS4() + window.___youtubeS4() + window.___youtubeS4(); var tags = document.getElementsByTagName('script'); var lastScriptTag = tags[tags.length - 1]; lastScriptTag.parentNode.insertBefore(tag, lastScriptTag); window.addEvent('domready', function() { window.___youtubeQueueOrBuild(tag.id, 'IyYnnUcgeMc', '2320571-1-3', '349', '620'); }); document.getElementById("myyoutube").style.display='block';