/*
* Media Element
* HTML5 <video> and <audio> Shim
* http://mediaelementjs.com/
*
* Creates a JavaScript object that mimics HTML5 media object
* for browsers that don't understand HTML5 or can't play the provided codec
* Can also play MP4 (H.264), Ogg, WebM, FLV, WMV, WMA, ACC, and MP3
*
* Copyright 2010, John Dyer
* Dual licensed under the MIT or GPL Version 2 licenses.
*
* Version: 1.1.0
*/
var html5=html5||{};html5.meIndex=0;html5.plugins={silverlight:[{version:[3,0],types:["video/mp4","video/m4v","video/mov","video/wmv","audio/wma","audio/mp4","audio/m4a","audio/mp3"]}],flash:[{version:[9,0,124],types:["video/mp4","video/m4v","video/mov","video/flv","audio/flv","audio/mp3","audio/m4a","audio/mp3"]}]};html5.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(h,b,c,l){var j=[0,0,0],k,f,a;if(typeof(this.nav.plugins)!="undefined"&&typeof this.nav.plugins[h]=="object"){k=this.nav.plugins[h].description;if(k&&!(typeof this.nav.mimeTypes!="undefined"&&this.nav.mimeTypes[b]&&!this.nav.mimeTypes[b].enabledPlugin)){j=k.replace(h,"").replace(/^\s+/,"").replace(/\sr/gi,".").split(".");for(f=0;f<j.length;f++){j[f]=parseInt(j[f],10)}}}else{if(typeof(window.ActiveXObject)!="undefined"){try{a=new ActiveXObject(c);if(a){j=l(a)}}catch(g){}}}return j}};html5.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});html5.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});if(html5.PluginDetector.ua.match(/Android 2\.[12]/)!==null){HTMLMediaElement.canPlayType=function(a){return(a.match(/video\/(mp4|m4v)/gi)!==null)?"probably":""}}html5.MediaFeatures={init:function(){var e=html5.PluginDetector.nav,c=html5.PluginDetector.ua,b,a,d=["source","track","audio","video"];this.isiPad=(c.match(/iPad/i)!==null);this.isiPhone=(c.match(/iPhone/i)!==null);this.isAndroid=(c.match(/Android/i)!==null);this.isIE=(e.appName.indexOf("Microsoft")!=-1);for(b=0;b<d.length;b++){a=document.createElement(d[b])}this.hasNativeFullScreen=(typeof a.webkitEnterFullScreen!=="undefined");if(c.match(/Chrome/gi)){this.hasNativeFullScreen=false}}};html5.MediaFeatures.init();html5.Utility={escapeHTML:function(a){return a.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(b){b=Math.round(b);var a=Math.floor(b/60);a=(a>=10)?a:"0"+a;b=Math.floor(b%60);b=(b>=10)?b:"0"+b;return a+":"+b}};html5.HtmlMediaElement={pluginType:"native",setCurrentTime:function(a){this.currentTime=a},setMuted:function(a){this.muted=a},setVolume:function(a){this.volume=a},setSrc:function(a){if(typeof a=="string"){this.src=a}else{var b,c;for(b=0;b<a.length;b++){c=a[b];if(this.canPlayType(c.type)){this.src=c.src}}}},setVideoSize:function(b,a){this.width=b;this.height=a}};html5.PluginMediaElement=function(a,b){this.id=a;this.pluginType=b;this.events={}};html5.PluginMediaElement.prototype={pluginElement:null,pluginType:"",playbackRate:-1,defaultPlaybackRate:-1,seekable:[],played:[],paused:true,ended:false,seeking:false,duration:0,muted:false,volume:1,currentTime:0,play:function(){this.pluginApi.playMedia();this.paused=false},load:function(){this.pluginApi.loadMedia();this.paused=false},pause:function(){this.pluginApi.pauseMedia();this.paused=true},canPlayType:function(e){var d,c,a,b=html5.plugins[this.pluginType];for(d=0;d<b.length;d++){a=b[d];if(html5.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(html5.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(html5.Utility.absolutizeUrl(c.src))}}}},setCurrentTime:function(a){this.pluginApi.setCurrentTime(a);this.currentTime=a},setVolume:function(a){this.pluginApi.setVolume(a);this.volume=a},setMuted:function(a){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"}this.pluginApi.setVideoSize(b,a)},setFullscreen:function(a){this.pluginApi.setFullscreen(a)},addEventListener:function(b,c,a){this.events[b]=this.events[b]||[];this.events[b].push(c)},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)}}}};html5.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.SilverlightApp;break}if(a.success){a.success(a,b)}},fireEvent:function(h,c,b){var g,f,a,d=this.pluginMediaElements[h];d.ended=false;d.paused=false;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)}};html5.MediaElementDefaults={enablePluginDebug:false,plugins:["silverlight","flash"],type:"",pluginPath:html5.Utility.getScriptPath(["mediaelement.js","mediaelement.min.js","mediaelement-and-player.js","mediaelement-and-player.min.js"]),flashName:"flashmediaelement.swf",silverlightName:"silverlightmediaelement.xap",defaultVideoWidth:480,defaultVideoHeight:270,pluginWidth:-1,pluginHeight:-1,success:function(){},error:function(){}};html5.MediaElement=function(a,b){html5.HtmlMediaElementShim.create(a,b)};html5.HtmlMediaElementShim={create:function(f,e){var j=html5.MediaElementDefaults,h=(typeof(f)=="string")?document.getElementById(f):f,a=(h.tagName.toLowerCase()=="video"),b=(typeof(h.canPlayType)!="undefined"),c={method:"",url:""},i=h.getAttribute("poster"),g=h.getAttribute("autoplay"),d;for(d in e){j[d]=e[d]}i=(i=="undefined"||i===null)?"":i;c=this.determinePlayback(h,j,a,b);if(c.method=="native"){this.updateNative(h,j)}else{if(c.method!==""){this.createPlugin(h,j,a,c.method,(c.url!==null)?html5.Utility.absolutizeUrl(c.url):"",i,g)}else{this.createErrorMessage(h,j,c.url,i)}}},determinePlayback:function(r,u,a,b){var t=[],h,g,f,e,d,c,p,s={method:"",url:""},m,o,q;if(typeof(u.type)!="undefined"&&u.type!==""){t.push({type:u.type,url:null})}else{if(r.getAttribute("src")!="undefined"&&r.getAttribute("src")!==null){c=r.getAttribute("src");p=this.checkType(c,r.getAttribute("type"),a);t.push({type:p,url:c})}else{for(h=0;h<r.childNodes.length;h++){d=r.childNodes[h];if(d.nodeType==1&&d.tagName.toLowerCase()=="source"){c=d.getAttribute("src");p=this.checkType(c,d.getAttribute("type"),a);t.push({type:p,url:c})}}}}if(b){for(h=0;h<t.length;h++){if(r.canPlayType(t[h].type).replace(/no/,"")!==""){s.method="native";s.url=t[h].url;return s}}}for(h=0;h<t.length;h++){p=t[h].type;for(g=0;g<u.plugins.length;g++){m=u.plugins[g];o=html5.plugins[m];for(f=0;f<o.length;f++){q=o[f];if(html5.PluginDetector.hasPluginVersion(m,q.version)){for(e=0;e<q.types.length;e++){if(p==q.types[e]){s.method=m;s.url=t[h].url;return s}}}}}}return s},checkType:function(a,c,d){var b;if(a&&!c){b=a.substring(a.lastIndexOf(".")+1);return((d)?"video":"audio")+"/"+b}else{return c}},createErrorMessage:function(c,b,f,g){var a=document.createElement("div");a.className="me-cannotplay";try{a.style.width=c.width+"px";a.style.height=c.height+"px"}catch(d){}a.innerHTML=(g!=="")?'<a href="'+f+'"><img src="'+g+'" /></a>':'<a href="'+f+'">Download file</a>';c.parentNode.insertBefore(a,c);c.style.display="none";b.error(c)},createPlugin:function(i,m,b,f,h,j,g){var d=1,k=1,e="me_"+f+"_"+(html5.meIndex++),l=new html5.PluginMediaElement(e,f),c=document.createElement("div"),a;if(b){d=(m.videoWidth>0)?m.videoWidth:(i.getAttribute("width")!==null)?i.getAttribute("width"):m.defaultVideoWidth;k=(m.videoHeight>0)?m.videoHeight:(i.getAttribute("height")!==null)?i.getAttribute("height"):m.defaultVideoHeight}else{if(m.enablePluginDebug){d=320;k=240}}l.success=m.success;html5.MediaPluginBridge.registerPluginElement(e,l,i);c.className="me-plugin";i.parentNode.insertBefore(c,i);a=["id="+e,"poster="+j,"autoplay="+g,"width="+d,"height="+k];if(h!==null){a.push("file="+h)}if(m.enablePluginDebug){a.push("debug=true")}switch(f){case"silverlight":c.innerHTML='<object data="data:application/x-silverlight-2," type="application/x-silverlight-2" id="'+e+'" name="'+e+'" width="'+d+'" height="'+k+'"><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="'+m.pluginPath+m.silverlightName+'" /></object>';break;case"flash":if(html5.MediaFeatures.isIE){c.outerHTML='<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab" id="'+e+'" width="'+d+'" height="'+k+'"><param name="movie" value="'+m.pluginPath+m.flashName+"?x="+(new Date())+'" /><param name="flashvars" value="'+a.join("&")+'" /><param name="quality" value="high" /><param name="bgcolor" value="#000000" /><param name="wmode" value="transparent" /><param name="allowScriptAccess" value="sameDomain" /><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="sameDomain" allowFullScreen="true" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" src="'+m.pluginPath+m.flashName+"?"+a.join("&")+'" width="'+d+'" height="'+k+'"></embed>'}break}i.style.display="none"},updateNative:function(c,b){for(var a in html5.HtmlMediaElement){c[a]=html5.HtmlMediaElement[a]}b.success(c,c)}};window.html5=html5;window.MediaElement=html5.MediaElement;
