(function(WIN,DOC){var include=function(filename){var head=DOC.getElementsByTagName('head')[0],script=DOC.createElement('script');script.src=filename;script.type='text/javascript';head.appendChild(script);};if(typeof window.BBCOMVideoEmbed==='function'){return false;}
var VideoEmbed=function(element){this.element=element;this.element.innerHTML="Loading...";this.thumbnailUrl=this.element.getAttribute('data-thumbnail-url');this.videoUrl=this.element.getAttribute('data-video-id');this.videoKey=this.element.getAttribute('data-video-key');this.playOnce=this.element.getAttribute('data-play-once');if(this.element.getAttribute('data-autoplay')=='true'){if(this.playOnce=='true'){this.autoplay=this.checkCookie();}else{this.autoplay=true;}}
else{this.autoplay=false;}
this.useSimplePlayer=(!this.videoKey?true:false);this.videoTag=false;this.mp4=false;this.flash=false;this.userAgent='';this.mobileSafari=false;this.ipad=false;this.videoElement={};this.videoFormatString='video/mp4';this.height=361;this.width=452;this.getDimensions();if(this.detectMobileSafari()){this.buildHTMLPlayer();}
else if(this.detectFlashSupport()){this.buildFlashPlayer();}
else{this.buildErrorMessage();}};VideoEmbed.prototype={checkCookie:function(){var cookieName='BBVideosPlayed',videos='';var current_date=new Date;var cookie_year=current_date.getFullYear()+1;var cookie_month=current_date.getMonth();var cookie_day=current_date.getDate();var expires=new Date(cookie_year,cookie_month,cookie_day);var c=document.cookie.indexOf(cookieName+'=');if(c!=-1){var c_end=document.cookie.indexOf(';',c);if(c_end==-1){c_end=document.cookie.length;}
videos=unescape(document.cookie.substring(c,c_end));videos=videos.replace(cookieName+'=','');if(videos.indexOf(this.videoKey,0)!=-1){return false;}else{document.cookie=cookieName+'='+videos+','+this.videoKey+';expires='+expires;return true;}}
document.cookie=cookieName+'='+videos+','+this.videoKey+';expires='+expires;return true;},getDimensions:function(){try{var dimensions=this.element.getAttribute('data-dimensions').split('x');this.width=(dimensions[0]||this.width)*1;this.height=(dimensions[1]||this.height)*1;}
catch(e){}},createVideoElement:function(){this.videoElement=document.createElement('video');},detectVideoTagSupport:function(){this.videoTag=!!(this.videoElement.canPlayType);return this.videoTag;},detectMP4Support:function(){var probability=this.videoElement.canPlayType(this.videoFormatString);if(probability!=='no'){this.mp4=true;}
return this.mp4;},detectFlashSupport:function(){var flash=navigator.plugins['Shockwave Flash'];if(typeof flash!=='undefined'||this.userAgent.indexOf('msie')>-1){this.flash=true;}
return this.flash;},getUserAgent:function(){this.userAgent=navigator.userAgent.toLowerCase();},detectMobileSafari:function(){this.getUserAgent();if(this.userAgent.indexOf('mobile')>-1||this.userAgent.indexOf('webos')>-1){this.mobileSafari=true;}
return this.mobileSafari;},detectIpad:function(){if(this.userAgent.indexOf('ipad')>-1){this.ipad=true;}
return this.ipad;},buildFlashPlayer:function(){if(this.useSimplePlayer){this.buildSimplePlayer();}
else{this.embedNuevoPlayer();}},embedNuevoPlayer:function(){var config;if(!this.autoplay){config="econfig";}
else{config="config";}
this.element.innerHTML='<div name="mediaspace" id="mediaspace" style="width:'+this.width+'px;height:'+this.height+'px;"><embed type="application/x-shockwave-flash" src="http://videos.bodybuilding.com/nuevo/player/nvplayer.swf?config=http://videos.bodybuilding.com/nuevo/'+config+'.php?key='+this.videoKey+'" width="'+this.width+'" height="'+this.height+'" id="nuevoplayer" name="nuevoplayer" bgcolor="#ffffff" quality="high" allowscriptaccess="always" wmode="transparent" allowfullscreen="true"  flashvars="image='+this.thumbnailUrl+'"></div>';},buildSimplePlayer:function(){this.buildVideoUrl();this.element.innerHTML='<embed src="http://videos.bodybuilding.com/player.swf" wmode="transparent" width="'+this.width+'" height="'+this.height+'" allowscriptaccess="always" allowfullscreen="true" flashvars="height='+this.height+'&amp;width='+this.width+'&amp;file='+this.videoUrl+'&amp;image=http://videos.bodybuilding.com/thumb/'+this.videoShard+'.jpg&amp;displayheight=257&amp;searchbar=false" pluginspage="http://www.macromedia.com/go/getflashplayer" type="application/x-shockwave-flash"></embed>';},buildVideoUrl:function(){this.videoShard=this.videoUrl;this.videoUrl='http://videos.bodybuilding.com/video/mp4/'+this.videoUrl;if(this.detectIpad()||this.flash){this.videoUrl+='m.mp4';}
else{this.videoUrl+='l.mp4';}},buildHTMLPlayer:function(){this.buildVideoUrl();if(this.detectIpad()){this.createVideoElement();this.videoElement.height=this.height;this.videoElement.width=this.width;this.videoElement.setAttribute('controls','controls');this.videoElement.setAttribute('src',this.videoUrl);this.element.innerHTML='';this.element.appendChild(this.videoElement);var src=document.createElement('source');src.type='video/mp4';src.src=this.videoUrl;this.videoElement.appendChild(src);}
else{this.element.innerHTML='<a href="'+this.videoUrl+'"><div></div><img src="'+this.thumbnailUrl+'" /></a>';this.element.style.position='relative';this.element.style.display='inline-block';var div=this.element.getElementsByTagName('div')[0].style;div.height='64px';div.width='64px';div.position='absolute';div.top='50%';div.left='50%';div.marginLeft='-32px',div.marginTop='-32px';div.background='url(http://assets.bodybuilding.com/videos/images/video-embed-play-button.png)';}},buildErrorMessage:function(){this.element.innerHTML='Unable to play the video.';}};var getElementsByClassName=function(cl,scope){if(typeof scope===undefined){scope='*';}
var retnode=[],myclass=new RegExp('\\b'+cl+'\\b'),elem=document.getElementsByTagName(scope);for(var i=0;i<elem.length;i++){var classes=elem[i].className;if(myclass.test(classes)){retnode.push(elem[i]);}}
return retnode;}
window.BBCOMVideoCleanup=function(){var vids=getElementsByClassName('BBCOMVideoEmbed','div');for(var vid=0,len=vids.length;vid<len;vid+=1){vids[vid].parentNode.removeChild(vids[vid]);}}
window.BBCOMVideoEmbed=function(vKey,vId){var vids=getElementsByClassName('BBCOMVideoEmbed','div');for(var vid=0,len=vids.length;vid<len;vid+=1){if(vids[vid].getAttribute('data-video-built')!=='true'){if(vKey===undefined){include('http://videos.bodybuilding.com/bbcomUtil/ajax.php?action=getVideoInfoForEmbedWidget&vKey='+vids[vid].getAttribute('data-video-key'));}
else if(!vids[vid].getAttribute('data-video-key')){new VideoEmbed(vids[vid]);}
else{if(vKey===vids[vid].getAttribute('data-video-key')){vids[vid].setAttribute('data-video-id',vId);new VideoEmbed(vids[vid]);vids[vid].setAttribute('data-video-built','true');}}}}
window.onunload=window.BBCOMVideoCleanup;};})(window,document);window.BBCOMVideoEmbed();
