//jQuery.h5Video 1.0.0: Plugin to detect flash, and if it isn't avaliable swap to KT html5 video stream 
(function(a){h5Video=function(b){};h5Video.init=function(c,d){var b=this;this.elem=d;b.settings=a.extend({},this.defaults,c);if(!(id=a(b.elem).attr("id"))){id="h5Video"+Math.floor(Math.random()*100000);a(b.elem).attr("id",id)}if(b.settings.swfObject&&b.settings.swfObject.installedVer&&b.settings.swfObject.installedVer.major){b.settings.swfObject.write(id)}else{if(b.settings.wrapOutlet){b.wrapOutlet()}if(b._checkVideoIDs()){b.loadVideo()}}};h5Video._checkVideoIDs=function(){var b=this;if(b.settings.videoId){b.settings.clipPlaylist=String(b.settings.videoId)}if(b.settings.clipPlaylist){var f=b.settings.clipPlaylist.toString().split(/\s*,\s*/);if(f.length){var e=[];var c;for(c=0;c<f.length;c++){var d=parseInt(f[c],10);if(d){e.push(d)}}if(e.length){b.clipPlaylist=e;b.atPlaylist=0;b.settings.videoId=e[0];return true}}}a(b.elem).html(b.settings.unavailableMessage);return false};h5Video.loadVideo=function(){var b=this;a(b.elem).html("");a(b.elem).addClass("wait");a.getJSON(b.settings.servicesURL+b.settings.clipInfoPath+b.settings.videoId,function(c){if(c.metadata){b.metadata=b.processMetadata(c)}else{b.metadata=false}a(b.elem).trigger("updatedMetadata");a.getJSON(b.settings.servicesURL+b.settings.smilPath+b.settings.videoId,function(g){var f=g.head.layout["root-layout"];var e=g.body["switch"].video;b.settings.videoWidth=f.width;b.settings.videoHeight=f.height;var d=false;a(e).each(function(h,j){if(j.type!==undefined&&b.settings.videoTypes.indexOf(j.type)!==-1){d=true;b.settings.videoPath=j.src;a(j.param).each(function(k,l){if(l.name=="content-type"){b.settings.videoMimetype=l.value}});if(!b.setPlayer(b.elem)){d=false}}});a(b.elem).removeClass("wait");if(!d){a(b.elem).html(b.settings.unavailableMessage)}else{a("."+b.settings.videoTagClass,b.elem).bind("ended pause",function(h){b._checkEnded(h)})}})})};h5Video._checkEnded=function(f){var c=false;var d=this;if(f.type=="ended"){c=true}else{if(f.type=="pause"){var b=a("."+d.settings.videoTagClass,d.elem)[0];if(b.duration>0&&b.currentTime==0){c=true}}}if(c){a(d.elem).trigger("clipEnded");if(d.clipPlaylist!==undefined&&d.clipPlaylist.length>1){d.atPlaylist=(d.atPlaylist+1)%d.clipPlaylist.length;d.settings.videoId=d.clipPlaylist[d.atPlaylist];d.loadVideo()}}};h5Video.processMetadata=function(c){if(c.metadata!==undefined){c=c.metadata}if(c.clipid!==undefined){var d=c.headline;var b=c.title;c.title=d;c.subtitle=b;if(c.description===undefined){c.description=""}return{properties:c}}return false};h5Video.wrapOutlet=function(){var b=this;if(window.outletInitted===true){return}window.outletInitted=true;function c(){}c.prototype.getOutletExtension=function(){function d(){}d.prototype.playVideo=function(e){b.settings.videoId=parseInt(e,10);b.loadVideo(b.elem)};d.prototype.addEventListener=function(e,f){switch(e){case"Player.end":a(b.elem).bind("clipEnded",function(){f({})});break;case"CONTENT_METADATA.clip_info_update":a(b.elem).bind("updatedMetadata",function(){f({})});break}};d.prototype.getMetaData=function(){if(b.metadata){return b.metadata}return b.settings.metaDataStub};d.prototype.updateAdData=function(){};window.embeddedPlayer=window.embeddedPlayer!==undefined?window.embeddedPlayer:new d();return window.embeddedPlayer};c.prototype.isAvailable=function(){return false};if(window.Outlet===undefined){window.Outlet=new c();if(window.onOutletEvent!==undefined&&typeof window.onOutletEvent==="function"){window.onOutletEvent({type:"outletInited"})}}};h5Video.setPlayer=function(){var c=this;if(c.settings.videoPath!==undefined){var d=parseInt(c.settings.videoHeight,10);var b=parseInt(c.settings.videoWidth,10);var i=a(c.elem).innerHeight();var g=Math.floor((i-d)/2);var e=a(c.elem).innerWidth();var f=Math.floor((e-b)/2);switch(c.settings.videoSize.toUpperCase()){case"FILL":if(e&&i){c.settings.videoPlayerWidth=e;c.settings.videoPlayerHeight=i;break}default:c.settings.videoPlayerWidth=c.settings.videoWidth;c.settings.videoPlayerHeight=c.settings.videoHeight;c.settings.videoSize="DEFAULT";break}this.createPlayer(c.elem);if(c.settings.videoSize=="DEFAULT"){a("."+c.settings.videoTagClass,c.elem).css({marginTop:g,marginLeft:f});a(c.elem).css({textAlign:"left",padding:0})}if(c.settings.playerAutoPlay){a(window).load(function(){})}return true}return false};h5Video.createPlayer=function(){var c=this;if(c.settings.videoPath!==undefined){a(c.elem).html('<video class="'+c.settings.videoTagClass+'"/>');var b={width:c.settings.videoPlayerWidth,height:c.settings.videoPlayerHeight,src:c.settings.videoPath,type:c.settings.videoMimetype};if(c.settings.playerControls){b.controls="true"}if(c.settings.playerAutoPlay){b.autoplay="true"}if(c.settings.playerPreload){b.preload="true"}if(c.settings.playerLoop){b.loop="true"}if(c.settings.playerPoster===true){if(c.metadata.properties.mezznimagepath!==undefined){b.poster=c.settings.imageBase+"/"+c.metadata.properties.mezznimagepath}}else{if(c.settings.playerPoster){b.poster=c.settings.playerPoster}}if(c.settings.playerAudio===false){b.audio="muted"}a("."+c.settings.videoTagClass,c.elem).attr(b);return true}return false};if(typeof Object.create!=="function"){Object.create=function(c){function b(){}b.prototype=c;return new b()}}if(typeof(a.plugin!=="function")){a.plugin=function(c,b){a.fn[c]=function(e){var d=Array.prototype.slice.call(arguments,1);return this.each(function(){var f=a.data(this,c);if(f){f[e].apply(f,d)}else{f=a.data(this,c,Object.create(b).init(e,this))}})}}}a.plugin("h5Video",h5Video);h5Video.defaults={swfObject:null,videoId:null,clipPlaylist:null,servicesURL:"http://videoservices.nbcuni.com",imageBase:"http://video.nbcuni.com/mezzthumb",unavailableMessage:'<span class="message">This video is not available on your device</span>',smilPath:"/player/smil?version=SMIL21&output=json&callback=?&clipId=",clipInfoPath:"/player/clip?output=json&callback=?&clipId=",wrapOutlet:true,videoTagClass:"html5Video",videoSize:"FILL",videoTypes:["mov"],playerControls:true,playerAutoPlay:true,playerPreload:"auto",playerPoster:true,playerLoop:true,playerAudio:true,metaDataStub:{properties:{path:[],description:"",headline:"",title:"",clipid:0,folderpath:"",showInNav:"",mezznimagepath:"",thumburl:"",geoip:"",publishdate:0,iswidgetable:"",videoads:"",preroll:"",midroll:"",adplaylist:"",cliplength:"",network:{name:"",id:"",active:"",metric0:"",imageurl:"",externalkey:"",fullpageconfigpath:"",placement:0,continuousPlay:"",metric0:"",metric0:"",metric0:"",metric0:"",metric0:"",metric0:"",metric0:"",metric0:"",metric0:"",sponsorImageUrl:"",widgetId:"",commscore_publisher:"",error:null,errordis:null},externalkey:"",guid:"",maturecontent:"",permalink:"",placement:0,showcomments:"",showtime:"",suppressTimer:"",thirdpartyclip:"",useincontinuous:"",usenielsen:"",useomniture:"",geoflag:"",domainflag:"",imageUrl:"",thirdpartclip:"",tab:"",show:"",pageName:"",chapterDetails:{segment:[]},episodesequence:null}}}})(jQuery);
