(function(b){var a={extend:function(d,e){for(var f in e){if(!e.hasOwnProperty(f)){continue}if(typeof e[f]=="object"&&null!==e[f]){d[f]=a.extend(d[f]||{},e[f])}else{d[f]=e[f]}}return d},res_label:function(d){return(/^\d+$/.test(d))?d+"p":d}};b.ResolutionMenuItem=b.MenuItem.extend({init:function(e,d){d.label=a.res_label(d.res);d.selected=(d.res.toString()===e.getCurrentRes().toString());b.MenuItem.call(this,e,d);this.resolution=d.res;this.on("click",this.onClick);e.on("changeRes",b.bind(this,function(){if(this.resolution==e.getCurrentRes()){this.selected(true)}else{this.selected(false)}}));e.on("changeToHighestRes",b.bind(this,function(){if(this.resolution==e.getHighestRes()){c(this,this.resolution)}}));e.on("changeToLowestRes",b.bind(this,function(){if(this.resolution==e.getLowestRes()){c(this,this.resolution)}}));e.on("changeToDefaultRes",b.bind(this,function(){if(this.resolution==360){c(this,this.resolution)}}))}});b.ResolutionMenuItem.prototype.onClick=function(){c(this)};function c(h,e){var f=h.player(),j=f.el().firstChild,k=f.currentTime(),d=f.paused(),i=f.controlBar.resolutionSelector.el().firstChild.children,g=i.length;if(e==f.getHighestRes()){f.isHd=true}if(e){h.resolution=e}if(f.getCurrentRes()==h.resolution){return}if("none"==j.preload){j.preload="metadata"}f.src(f.availableRes[h.resolution]).one("loadedmetadata",function(){f.currentTime(k);if(!d){f.play()}});f.currentRes=h.resolution;while(g>0){g--;if("vjs-current-res"==i[g].className){i[g].innerHTML=a.res_label(h.resolution);break}}f.trigger("changeRes")}b.ResolutionTitleMenuItem=b.MenuItem.extend({init:function(e,d){b.MenuItem.call(this,e,d);this.off("click")}});b.ResolutionSelector=b.MenuButton.extend({init:function(e,d){e.availableRes=d.available_res;b.MenuButton.call(this,e,d)}});b.ResolutionSelector.prototype.createItems=function(){var e=this.player(),d=[],f;d.push(new b.ResolutionTitleMenuItem(e,{el:b.Component.prototype.createEl("li",{className:"vjs-menu-title vjs-res-menu-title",innerHTML:"Quality"})}));for(f in e.availableRes){if("length"==f){continue}d.push(new b.ResolutionMenuItem(e,{res:f}))}d.sort(function(h,g){if(typeof h.resolution=="undefined"){return -1}else{return parseInt(g.resolution)-parseInt(h.resolution)}});return d};b.plugin("resolutionSelector",function(p){var o=this,d=o.options().sources,l=d.length,k,n,g=a.extend({default_res:"",force_types:false},p||{}),m={length:0},h,e,f=(g.default_res&&typeof g.default_res=="string")?g.default_res.split(","):[];while(l>0){l--;if(!d[l]["data-res"]){continue}h=d[l]["data-res"];if(typeof m[h]!=="object"){m[h]=[];m.length++}m[h].push(d[l])}if(g.force_types){for(h in m){if("length"==h){continue}l=g.force_types.length;while(l>0){l--;k=m[h].length;found_types=0;while(k>0){k--;if(g.force_types[l]===m[h][k].type){found_types++}}if(found_typesi){i=parseInt(res)}}return i};o.getLowestRes=function(){var i=9999999999;for(res in o.availableRes){if("length"==res){continue}if(parseInt(res)'+(h||"Quality")+"",role:"button","aria-live":"polite",tabIndex:0}),available_res:m});o.controlBar.resolutionSelector=o.controlBar.addChild(e)})})(videojs);