/*!
* MediaElement.js
* HTML5 <video> and <audio> shim and player
* http://mediaelementjs.com/
*
* Creates a JavaScript object that mimics HTML5 MediaElement API
* for browsers that don't understand HTML5 or can't play the provided codec
* Can play MP4 (H.264), Ogg, WebM, FLV, WMV, WMA, ACC, and MP3
*
* Copyright 2010-2011, John Dyer (http://j.hn)
* Dual licensed under the MIT or GPL Version 2 licenses.
*
*/
var mejs=mejs||{};mejs.version="2.3.2";mejs.meIndex=0;mejs.plugins={silverlight:[{version:[3,0],types:["video/mp4","video/m4v","video/mov","video/wmv","audio/wma","audio/m4a","audio/mp3","audio/wav","audio/mpeg"]}],flash:[{version:[9,0,124],types:["video/mp4","video/m4v","video/mov","video/flv","video/x-flv","audio/flv","audio/x-flv","audio/mp3","audio/m4a","audio/mpeg"]}]};mejs.Utility={encodeUrl:function(a){return encodeURIComponent(a)},escapeHTML:function(a){return a.toString().split("&").join("&amp;").split("<").join("&lt;").split('"').join("&quot;")},absolutizeUrl:function(a){var b=document.createElement("div");b.innerHTML='<a href="'+this.escapeHTML(a)+'">x</a>';return b.firstChild.href},getScriptPath:function(b){var f=0,e,g="",d="",c,a=document.getElementsByTagName("script");for(;f<a.length;f++){c=a[f].src;for(e=0;e<b.length;e++){d=b[e];if(c.indexOf(d)>-1){g=c.substring(0,c.indexOf(d));break}}if(g!==""){break}}return g},secondsToTimeCode:function(c,g,a,b){if(typeof a=="undefined"){a=false}else{if(typeof b=="undefined"){b=25}}var f=Math.floor(c/3600)%24,d=Math.floor(c/60)%60,h=Math.floor(c%60),e=Math.floor(((c%1)*b).toFixed(3)),j=((g||f>0)?(f<10?"0"+f:f)+":":"")+(d<10?"0"+d:d)+":"+(h<10?"0"+h:h)+((a)?":"+(e<10?"0"+e:e):"");return j},timeCodeToSeconds:function(c,k,d,e){if(typeof d=="undefined"){d=false}else{if(typeof e=="undefined"){e=25}}var f=c.split(":"),a=parseInt(f[0]),b=parseInt(f[1]),h=parseInt(f[2]),j=0,g=0;if(d){j=parseInt(f[3])/e}g=(a*3600)+(b*60)+h+j;return g}};mejs.PluginDetector={hasPluginVersion:function(c,a){var b=this.plugins[c];a[1]=a[1]||0;a[2]=a[2]||0;return(b[0]>a[0]||(b[0]==a[0]&&b[1]>a[1])||(b[0]==a[0]&&b[1]==a[1]&&b[2]>=a[2]))?true:false},nav:window.navigator,ua:window.navigator.userAgent.toLowerCase(),plugins:[],addPlugin:function(d,c,e,a,b){this.plugins[d]=this.detectPlugin(c,e,a,b)},detectPlugin:function(g,b,c,k){var h=[0,0,0],j,d,a;if(typeof(this.nav.plugins)!="undefined"&&typeof this.nav.plugins[g]=="object"){j=this.nav.plugins[g].description;if(j&&!(typeof this.nav.mimeTypes!="undefined"&&this.nav.mimeTypes[b]&&!this.nav.mimeTypes[b].enabledPlugin)){h=j.replace(g,"").replace(/^\s+/,"").replace(/\sr/gi,".").split(".");for(d=0;d<h.length;d++){h[d]=parseInt(h[d].match(/\d+/),10)}}}else{if(typeof(window.ActiveXObject)!="undefined"){try{a=new ActiveXObject(c);if(a){h=k(a)}}catch(f){}}}return h}};mejs.PluginDetector.addPlugin("flash","Shockwave Flash","application/x-shockwave-flash","ShockwaveFlash.ShockwaveFlash",function(b){var a=[],c=b.GetVariable("$version");if(c){c=c.split(" ")[1].split(",");a=[parseInt(c[0],10),parseInt(c[1],10),parseInt(c[2],10)]}return a});mejs.PluginDetector.addPlugin("silverlight","Silverlight Plug-In","application/x-silverlight-2","AgControl.AgControl",function(b){var a=[0,0,0,0],c=function(f,d,e,g){while(f.isVersionSupported(d[0]+"."+d[1]+"."+d[2]+"."+d[3])){d[e]+=g}d[e]-=g};c(b,a,0,1);c(b,a,1,1);c(b,a,2,10000);c(b,a,2,1000);c(b,a,2,100);c(b,a,2,10);c(b,a,2,1);c(b,a,3,1);return a});mejs.MediaFeatures={init:function(){var e=this,h=document,g=mejs.PluginDetector.nav,c=mejs.PluginDetector.ua.toLowerCase(),b,a,f=["source","track","audio","video"];e.isiPad=(c.match(/ipad/i)!==null);e.isiPhone=(c.match(/iphone/i)!==null);e.isiOS=e.isiPhone||e.isiPad;e.isAndroid=(c.match(/android/i)!==null);e.isBustedAndroid=(c.match(/android 2\.[12]/)!==null);e.isIE=(g.appName.toLowerCase().indexOf("microsoft")!=-1);e.isChrome=(c.match(/chrome/gi)!==null);e.isFirefox=(c.match(/firefox/gi)!==null);e.isGecko=(c.match(/gecko/gi)!==null);e.isWebkit=(c.match(/webkit/gi)!==null);e.hasTouch=("ontouchstart" in window);for(b=0;b<f.length;b++){a=document.createElement(f[b])}e.supportsMediaTag=(typeof a.canPlayType!=="undefined"||e.isBustedAndroid);e.hasSemiNativeFullScreen=(typeof a.webkitEnterFullscreen!=="undefined");e.hasWebkitNativeFullScreen=(typeof a.webkitRequestFullScreen!=="undefined");e.hasMozNativeFullScreen=(typeof a.mozRequestFullScreen!=="undefined");e.hasTrueNativeFullScreen=(e.hasWebkitNativeFullScreen||e.hasMozNativeFullScreen);e.nativeFullScreenEnabled=e.hasTrueNativeFullScreen;if(e.hasMozNativeFullScreen){e.nativeFullScreenEnabled=a.mozFullScreenEnabled}if(this.isChrome){e.hasSemiNativeFullScreen=false}if(e.hasTrueNativeFullScreen){e.fullScreenEventName=(e.hasWebkitNativeFullScreen)?"webkitfullscreenchange":"mozfullscreenchange";e.isFullScreen=function(){if(a.mozRequestFullScreen){return h.mozFullScreen}else{if(a.webkitRequestFullScreen){return h.webkitIsFullScreen}}};e.requestFullScreen=function(d){if(e.hasWebkitNativeFullScreen){d.webkitRequestFullScreen()}else{if(e.hasMozNativeFullScreen){d.mozRequestFullScreen()}}};e.cancelFullScreen=function(){if(e.hasWebkitNativeFullScreen){document.webkitCancelFullScreen()}else{if(e.hasMozNativeFullScreen){document.mozCancelFullScreen()}}}}if(e.hasSemiNativeFullScreen&&c.match(/mac os x 10_5/i)){e.hasNativeFullScreen=false;e.hasSemiNativeFullScreen=false}}};mejs.MediaFeatures.init();mejs.HtmlMediaElement={pluginType:"native",isFullScreen:false,setCurrentTime:function(a){this.currentTime=a},setMuted:function(a){this.muted=a},setVolume:function(a){this.volume=a},stop:function(){this.pause()},setSrc:function(a){var c=this.getElementsByTagName("source");while(c.length>0){this.removeChild(c[0])}if(typeof a=="string"){this.src=a}else{var b,d;for(b=0;b<a.length;b++){d=a[b];if(this.canPlayType(d.type)){this.src=d.src}}}},setVideoSize:function(b,a){this.width=b;this.height=a}};mejs.PluginMediaElement=function(b,c,a){this.id=b;this.pluginType=c;this.src=a;this.events={}};mejs.PluginMediaElement.prototype={pluginElement:null,pluginType:"",isFullScreen:false,playbackRate:-1,defaultPlaybackRate:-1,seekable:[],played:[],paused:true,ended:false,seeking:false,duration:0,error:null,muted:false,volume:1,currentTime:0,play:function(){if(this.pluginApi!=null){this.pluginApi.playMedia();this.paused=false}},load:function(){if(this.pluginApi!=null){this.pluginApi.loadMedia();this.paused=false}},pause:function(){if(this.pluginApi!=null){this.pluginApi.pauseMedia();this.paused=true}},stop:function(){if(this.pluginApi!=null){this.pluginApi.stopMedia();this.paused=true}},canPlayType:function(e){var d,c,a,b=mejs.plugins[this.pluginType];for(d=0;d<b.length;d++){a=b[d];if(mejs.PluginDetector.hasPluginVersion(this.pluginType,a.version)){for(c=0;c<a.types.length;c++){if(e==a.types[c]){return true}}}}return false},setSrc:function(a){if(typeof a=="string"){this.pluginApi.setSrc(mejs.Utility.absolutizeUrl(a));this.src=mejs.Utility.absolutizeUrl(a)}else{var b,c;for(b=0;b<a.length;b++){c=a[b];if(this.canPlayType(c.type)){this.pluginApi.setSrc(mejs.Utility.absolutizeUrl(c.src));this.src=mejs.Utility.absolutizeUrl(a)}}}},setCurrentTime:function(a){if(this.pluginApi!=null){this.pluginApi.setCurrentTime(a);this.currentTime=a}},setVolume:function(a){if(this.pluginApi!=null){this.pluginApi.setVolume(a);this.volume=a}},setMuted:function(a){if(this.pluginApi!=null){this.pluginApi.setMuted(a);this.muted=a}},setVideoSize:function(b,a){if(this.pluginElement.style){this.pluginElement.style.width=b+"px";this.pluginElement.style.height=a+"px"}if(this.pluginApi!=null&&this.pluginApi.setVideoSize){this.pluginApi.setVideoSize(b,a)}},setFullscreen:function(a){if(this.pluginApi!=null){this.pluginApi.setFullscreen(a)}},enterFullScreen:function(){this.setFullscreen(true)},enterFullScreen:function(){this.setFullscreen(false)},addEventListener:function(b,c,a){this.events[b]=this.events[b]||[];this.events[b].push(c)},removeEventListener:function(a,c){if(!a){this.events={};return true}var b=this.events[a];if(!b){return true}if(!c){this.events[a]=[];return true}for(i=0;i<b.length;i++){if(b[i]===c){this.events[a].splice(i,1);return true}}return false},dispatchEvent:function(a){var c,b,d=this.events[a];if(d){b=Array.prototype.slice.call(arguments,1);for(c=0;c<d.length;c++){d[c].apply(null,b)}}}};mejs.MediaPluginBridge={pluginMediaElements:{},htmlMediaElements:{},registerPluginElement:function(c,a,b){this.pluginMediaElements[c]=a;this.htmlMediaElements[c]=b},initPlugin:function(c){var a=this.pluginMediaElements[c],b=this.htmlMediaElements[c];switch(a.pluginType){case"flash":a.pluginElement=a.pluginApi=document.getElementById(c);break;case"silverlight":a.pluginElement=document.getElementById(a.id);a.pluginApi=a.pluginElement.Content.MediaElementJS;break}if(a.pluginApi!=null&&a.success){a.success(a,b)}},fireEvent:function(h,c,b){var g,f,a,d=this.pluginMediaElements[h];d.ended=false;d.paused=true;g={type:c,target:d};for(f in b){d[f]=b[f];g[f]=b[f]}a=b.bufferedTime||0;g.target.buffered=g.buffered={start:function(e){return 0},end:function(e){return a},length:1};d.dispatchEvent(g.type,g)}};mejs.MediaElementDefaults={mode:"auto",plugins:["flash","silverlight"],enablePluginDebug:false,type:"",pluginPath:mejs.Utility.getScriptPath(["mediaelement.js","mediaelement.min.js","mediaelement-and-player.js","mediaelement-and-player.min.js"]),flashName:"flashmediaelement.swf",enablePluginSmoothing:false,silverlightName:"silverlightmediaelement.xap",defaultVideoWidth:480,defaultVideoHeight:270,pluginWidth:-1,pluginHeight:-1,timerRate:250,startVolume:0.8,success:function(){},error:function(){}};mejs.MediaElement=function(a,b){return mejs.HtmlMediaElementShim.create(a,b)};mejs.HtmlMediaElementShim={create:function(e,d){var n=mejs.MediaElementDefaults,k=(typeof(e)=="string")?document.getElementById(e):e,h=k.tagName.toLowerCase(),g=(h==="audio"||h==="video"),b=(g)?k.getAttribute("src"):k.getAttribute("href"),l=k.getAttribute("poster"),f=k.getAttribute("autoplay"),j=k.getAttribute("preload"),m=k.getAttribute("controls"),a,c;for(c in d){n[c]=d[c]}b=(typeof b=="undefined"||b===null||b=="")?null:b;l=(typeof l=="undefined"||l===null)?"":l;j=(typeof j=="undefined"||j===null||j==="false")?"none":j;f=!(typeof f=="undefined"||f===null||f==="false");m=!(typeof m=="undefined"||m===null||m==="false");a=this.determinePlayback(k,n,mejs.MediaFeatures.supportsMediaTag,g,b);a.url=(a.url!==null)?mejs.Utility.absolutizeUrl(a.url):"";if(a.method=="native"){if(mejs.MediaFeatures.isBustedAndroid){k.src=a.url;k.addEventListener("click",function(){k.play()},false)}return this.updateNative(a,n,f,j)}else{if(a.method!==""){return this.createPlugin(a,n,l,f,j,m)}else{this.createErrorMessage(a,n,l);return this}}},determinePlayback:function(s,v,b,d,a){var u=[],m,h,g,f,c,q,t={method:"",url:"",htmlMediaElement:s,isVideo:(s.tagName.toLowerCase()!="audio")},o,p,r,e;if(typeof v.type!="undefined"&&v.type!==""){if(typeof v.type=="string"){u.push({type:v.type,url:a})}else{for(m=0;m<v.type.length;m++){u.push({type:v.type[m],url:a})}}}else{if(a!==null){q=this.formatType(a,s.getAttribute("type"));u.push({type:q,url:a})}else{for(m=0;m<s.childNodes.length;m++){c=s.childNodes[m];if(c.nodeType==1&&c.tagName.toLowerCase()=="source"){a=c.getAttribute("src");q=this.formatType(a,c.getAttribute("type"));u.push({type:q,url:a})}}}}if(!d&&u.length>0&&u[0].url!==null&&this.getTypeFromFile(u[0].url).indexOf("audio")>-1){t.isVideo=false}if(mejs.MediaFeatures.isBustedAndroid){s.canPlayType=function(j){return(j.match(/video\/(mp4|m4v)/gi)!==null)?"maybe":""}}if(b&&(v.mode==="auto"||v.mode==="native")){if(!d){e=document.createElement(t.isVideo?"video":"audio");s.parentNode.insertBefore(e,s);s.style.display="none";t.htmlMediaElement=s=e}for(m=0;m<u.length;m++){if(s.canPlayType(u[m].type).replace(/no/,"")!==""||s.canPlayType(u[m].type.replace(/mp3/,"mpeg")).replace(/no/,"")!==""){t.method="native";t.url=u[m].url;break}}if(t.method==="native"){if(t.url!==null){s.src=t.url}return t}}if(v.mode==="auto"||v.mode==="shim"){for(m=0;m<u.length;m++){q=u[m].type;for(h=0;h<v.plugins.length;h++){o=v.plugins[h];p=mejs.plugins[o];for(g=0;g<p.length;g++){r=p[g];if(mejs.PluginDetector.hasPluginVersion(o,r.version)){for(f=0;f<r.types.length;f++){if(q==r.types[f]){t.method=o;t.url=u[m].url;return t}}}}}}}if(t.method===""&&u.length>0){t.url=u[0].url}return t},formatType:function(a,c){var b;if(a&&!c){return this.getTypeFromFile(a)}else{if(c&&~c.indexOf(";")){return c.substr(0,c.indexOf(";"))}else{return c}}},getTypeFromFile:function(a){var b=a.substring(a.lastIndexOf(".")+1);return(/(mp4|m4v|ogg|ogv|webm|flv|wmv|mpeg|mov)/gi.test(b)?"video":"audio")+"/"+b},createErrorMessage:function(c,b,g){var d=c.htmlMediaElement,a=document.createElement("div");a.className="me-cannotplay";try{a.style.width=d.width+"px";a.style.height=d.height+"px"}catch(f){}a.innerHTML=(g!=="")?'<a href="'+c.url+'"><img src="'+g+'" /></a>':'<a href="'+c.url+'"><span>Download File</span></a>';d.parentNode.insertBefore(a,d);d.style.display="none";b.error(d)},createPlugin:function(b,p,l,f,k,m){var j=b.htmlMediaElement,d=1,n=1,e="me_"+b.method+"_"+(mejs.meIndex++),o=new mejs.PluginMediaElement(e,b.method,b.url),c=document.createElement("div"),h,g,a;g=j.parentNode;while(g!==null&&g.tagName.toLowerCase()!="body"){if(g.parentNode.tagName.toLowerCase()=="p"){g.parentNode.parentNode.insertBefore(g,g.parentNode);break}g=g.parentNode}if(b.isVideo){d=(p.videoWidth>0)?p.videoWidth:(j.getAttribute("width")!==null)?j.getAttribute("width"):p.defaultVideoWidth;n=(p.videoHeight>0)?p.videoHeight:(j.getAttribute("height")!==null)?j.getAttribute("height"):p.defaultVideoHeight;d=mejs.Utility.encodeUrl(d);n=mejs.Utility.encodeUrl(n)}else{if(p.enablePluginDebug){d=320;n=240}}o.success=p.success;mejs.MediaPluginBridge.registerPluginElement(e,o,j);c.className="me-plugin";j.parentNode.insertBefore(c,j);a=["id="+e,"isvideo="+((b.isVideo)?"true":"false"),"autoplay="+((f)?"true":"false"),"preload="+k,"width="+d,"startvolume="+p.startVolume,"timerrate="+p.timerRate,"height="+n];if(b.url!==null){if(b.method=="flash"){a.push("file="+mejs.Utility.encodeUrl(b.url))}else{a.push("file="+b.url)}}if(p.enablePluginDebug){a.push("debug=true")}if(p.enablePluginSmoothing){a.push("smoothing=true")}if(m){a.push("controls=true")}switch(b.method){case"silverlight":c.innerHTML='<object data="data:application/x-silverlight-2," type="application/x-silverlight-2" id="'+e+'" name="'+e+'" width="'+d+'" height="'+n+'"><param name="initParams" value="'+a.join(",")+'" /><param name="windowless" value="true" /><param name="background" value="black" /><param name="minRuntimeVersion" value="3.0.0.0" /><param name="autoUpgrade" value="true" /><param name="source" value="'+p.pluginPath+p.silverlightName+'" /></object>';break;case"flash":if(mejs.MediaFeatures.isIE){h=document.createElement("div");c.appendChild(h);h.outerHTML='<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="//download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab" id="'+e+'" width="'+d+'" height="'+n+'"><param name="movie" value="'+p.pluginPath+p.flashName+"?x="+(new Date())+'" /><param name="flashvars" value="'+a.join("&amp;")+'" /><param name="quality" value="high" /><param name="bgcolor" value="#000000" /><param name="wmode" value="transparent" /><param name="allowScriptAccess" value="always" /><param name="allowFullScreen" value="true" /></object>'}else{c.innerHTML='<embed id="'+e+'" name="'+e+'" play="true" loop="false" quality="high" bgcolor="#000000" wmode="transparent" allowScriptAccess="always" allowFullScreen="true" type="application/x-shockwave-flash" pluginspage="//www.macromedia.com/go/getflashplayer" src="'+p.pluginPath+p.flashName+'" flashvars="'+a.join("&")+'" width="'+d+'" height="'+n+'"></embed>'}break}j.style.display="none";return o},updateNative:function(d,c,f,b){var e=d.htmlMediaElement,a;for(a in mejs.HtmlMediaElement){e[a]=mejs.HtmlMediaElement[a]}c.success(e,e);return e}};window.mejs=mejs;window.MediaElement=mejs.MediaElement;
