var shufflePlayerObject=null;
function shufflePlayer(g){this.objName=window.shufflePlayerObject=g;this.mtvnp=null;this.videos=[];this.sortOrder=[];this.sortRandom=true;this.sortCustom=[];this.current=-1;this.dom={title:null,link:null,description:null};this.mgidSuffix="";this.lastMediaEnded=0;this.callback=function(){};this.gameIsPlaying=false;this.gameObj=null;this.isAd=function(){return this.mtvnp.getMetadata().isAd};this.config=function(b){var c=jQuery;if(typeof b=="object"&&b.playerId&&b.videos.length>0){console.log("Begin Config");
this.videos=b.videos;this.playerId=b.playerId;if(typeof b.sortRandom=="boolean")this.sortRandom=b.sortRandom;this.dom.title=b.dom.title;this.dom.link=b.dom.link;this.dom.description=b.dom.description;if(typeof b.callback=="function")this.callback=b.callback;this.opts=b;this.controller=new MTVNPlayerController(b.playerId,this.objName+".loaded");this.mgidSuffix=b.mgidSuffix?b.mgidSuffix:"";if(b.sortCustom&&b.sortCustom.length>0)this.sortCustom=[].concat(b.sortCustom);this.playerParent=b.playerParent?
c(b.playerParent):c("#"+b.playerId);this.swfobject=b.swfobject}this.sort();c(document).ready(function(){var a=window[shufflePlayerObject];if(typeof swfobject=="object"&&c("#"+a.playerId).size()<1&&c("#"+a.swfobject.playerContainer).size()>0){var d={autoPlay:"true",configParams:"nid%3D82125"},e={id:a.playerId,name:a.playerId};if(a.swfobject.sid)d.sid=a.swfobject.sid;a.current=a.sortOrder.shift();swfobject.embedSWF(a.swfobject.playerBaseUrl+a.videos[a.current].mgid+a.mgidSuffix,a.swfobject.playerContainer,
""+a.swfobject.width,""+a.swfobject.height,"9.0.0","",d,{allowScriptAccess:"always",bgcolor:"#000000",allowFullScreen:"true",wmode:"transparent"},e)}a.updateVideo()})};this.jumpToMGID=function(b,c){for(var a=window[shufflePlayerObject],d=0;d<a.videos.length;d++)if(a.videos[d].mgid==b||a.videos[d].urlkey==b){console.log("current: "+d);if(c)return d;else{a.current=d;a.split();a.updateVideo()}}if(c)return-1};this.isLoaded=false;this.loaded=function(b){console.log("PLAYER LOADED");var c=window[shufflePlayerObject],
a=false,d="";d=/[?&]v(?:=([^&#]*))?/;(c.mtvnp=b.player)&&b.player.addEventListener&&b.player.addEventListener("MEDIA_ENDED",c.objName+".mediaEnd");if(!c.isLoaded){c.isLoaded=true;if(d.test(location.search)){b=unescape(d.exec(location.search)[1]);c.playVideo(c.jumpToMGID(b,true));c.updateVideo();a=true}if(!a)if((d=c.mtvnp.src?c.mtvnp.src:c.mtvnp.movie)&&d!==""&&d.indexOf("mgid")>=0){d="mgid"+d.split("mgid")[1];c.jumpToMGID(d)}}typeof c.callback=="function"&&c.callback(c.current,c.sortOrder[0])};this.mediaEnd=
function(){console.log("MEDIA_ENDED");this.playNext("media_ended")};this.playNext=function(b){console.log("********** playNext() ***********");var c=jQuery,a=window[shufflePlayerObject],d;d=a.mtvnp&&typeof a.mtvnp.getMetadata=="function"&&a.mtvnp.getMetadata()?a.mtvnp.getMetadata():{isAd:false,url:""};if((!(a.mtvnp&&typeof a.mtvnp.getPlaylist=="function"&&a.mtvnp.getPlaylist()?a.mtvnp.getPlaylist():{hasNext:false}).hasNext||b=="user_select")&&(b!="media_ended"||!d.isAd&&b=="media_ended")&&!/mgid:hcx:content:atom.com:fadb8395-39c2-4a0c-8d24-784376449cc0/.test(d.url)&&
a.videos.length>0){console.log("begin playback");if(!a.__isAd||b=="user_select"||b=="media_ended"){a.sortOrder.length<=0&&a.sort();a.current=a.sortOrder.shift()}a.__isAd=d.isAd;if(a.videos[a.current].contentType&&a.videos[a.current].contentType=="Game"){console.log("Game Time!");if(!a.gameIsPlaying&&b!="media_ended")try{a.mtvnp.pause()}catch(e){console&&console.warn&&console.warn(e)}a.gameIsPlaying=true;d=c("object#"+a.mtvnp.id);if(!a.gameObj){a.gameObj=c('<div id="jg-'+Math.floor(Math.random()*1E8)+
'"/>').css({width:d.width()+"px",height:d.height()+"px"});d.after(a.gameObj)}d.hide();c=a.videos[a.current];a.gameObj.html('<iframe class="jukebox-gameplayer" src="/fun_games/embed/'+c.urlkey+'/" width="'+d.width()+'" height="'+d.height()+'" style="width: '+d.width()+"px; height: "+d.height()+'px; border: none;" frameborder="0"></iframe>').show()}else{if(a.gameIsPlaying){c("object#"+a.mtvnp.id).show();a.gameObj.hide().empty();a.gameIsPlaying=false}var h=40,f=function(){if(typeof a.mtvnp.playUri==
"function"){a.mtvnp.playUri(a.videos[a.current].mgid+a.mgidSuffix);try{a.mtvnp.unpause()}catch(j){console&&console.warn&&console.warn(j)}}else h-- >0&&setTimeout(f,200)};f()}a.updateVideo(b);console.log("playNext complete")}};this.updateVideo=function(b){console.log("*** update video ***");var c=jQuery,a=window[shufflePlayerObject],d;if(a.current>=0&&a.current<a.videos.length){a.sortOrder.length<1&&a.sort();d=a.videos[a.current];a.dom.title&&a.dom.title!==""&&typeof d.title!="undefined"&&c(a.dom.title).html(d.title);
if(a.dom.link&&a.dom.link!==""&&typeof d.title!="undefined"){c(a.dom.link).attr("href",d.link);a.dom.title&&a.dom.title!==""&&c(a.dom.link).attr("title",d.title)}a.dom.description&&a.dom.description!==""&&typeof d.description!=="undefined"&&c(a.dom.description).html(d.description);console.log("callback");typeof a.callback=="function"&&a.callback(a.current,a.sortOrder[0],b)}};this.playVideo=function(b){console.log("video selected: "+b);if(!isNaN(b)&&b!=this.current&&b>=0&&b<this.videos.length){if(this.sortRandom)this.sortOrder[0]!=
b&&this.sortOrder.unshift(b);else{this.sortOrder=[];var c=false;for(i=0;i<this.sortCustom.length;i++)if(this.sortCustom[i]==b||c){this.sortOrder.push(this.sortCustom[i]);c=true}if(this.sortOrder.length===0)this.sortOrder=[b]}this.playNext("user_select")}};this.sort=function(){for(var b=0;b<this.videos.length;b++)this.sortOrder[b]=b;if(this.sortCustom.length>0)this.sortOrder=[].concat(this.sortCustom);if(this.sortRandom)this.sortOrder=this.sortOrder.slice(0,this.videos.length).sort(function(){return Math.round(Math.random())-
0.5})};this.split=function(b){var c=window[shufflePlayerObject];if(!b)b=c.current;if(!isNaN(b)&&b>=0&&b<=c.videos.length)for(var a=0;a<c.sortOrder.length;a++)if(c.sortOrder[a]==b){c.sortOrder=c.sortOrder.slice(a+1);c.sortOrder.length<1&&c.sort();break}c.sortOrder[0]==c.current&&c.sortOrder.shift()}}
