(function(m){function l(){function l(a,b){"undefined"==typeof a&&(a={});for(var c in b)a[c]=b[c];return a}function m(a){var b=[],c;for(c in a)a.hasOwnProperty(c)&&b.push(encodeURIComponent(c)+"="+encodeURIComponent(a[c]));return b.join("&")}function n(a){var b={"3gp":"video/3gpp",aif:"audio/x-aiff",aifc:"audio/x-aiff",aiff:"audio/x-aiff",asf:"video/x-ms-asf",asr:"video/x-ms-asf",asx:"video/x-ms-asf",au:"audio/basic",avi:"video/x-msvideo",bin:"application/octet-stream",bmp:"image/bmp",c:"text/plain", "class":"application/octet-stream",cmx:"image/x-cmx",cod:"image/cis-cod",css:"text/css",exe:"application/octet-stream",flv:"video/x-flv",f4v:"video/x-flv",gif:"image/gif",gtar:"application/x-gtar",gz:"application/x-gzip",h:"text/plain",htm:"text/html",html:"text/html",ico:"image/x-icon",ief:"image/ief",jfif:"image/pipeg",jpe:"image/jpeg",jpeg:"image/jpeg",jpg:"image/jpeg",js:"application/x-javascript",lsf:"video/x-la-asf",lsx:"video/x-la-asf",m3u:"audio/x-mpegurl",m4v:"video/x-m4v",mid:"audio/mid", mov:"video/quicktime",movie:"video/x-sgi-movie",mp2:"video/mpeg",mp3:"audio/mpeg",mp4:"video/mp4",mpa:"video/mpeg",mpe:"video/mpeg",mpeg:"video/mpeg",mpg:"video/mpeg",mpv2:"video/mpeg",mxf:"video/mxf",ogg:"audio/ogg",pbm:"image/x-portable-bitmap",pdf:"application/pdf",pgm:"image/x-portable-graymap",png:"image/png",ppm:"image/x-portable-pixmap",qt:"video/quicktime",ra:"audio/x-pn-realaudio",ram:"audio/x-pn-realaudio",ras:"image/x-cmu-raster",rgb:"image/x-rgb",rmi:"audio/mid",rtx:"text/richtext",sh:"application/x-sh", snd:"audio/basic",srt:"text/plain",stm:"text/html",svg:"image/svg+xml",swf:"application/x-shockwave-flash",tar:"application/x-tar",tex:"application/x-tex",tgz:"application/x-compressed",tif:"image/tiff",tiff:"image/tiff",txt:"text/plain",uls:"text/iuls",wav:"audio/x-wav",webm:"video/webm",wma:"audio/x-ms-wma",wmv:"video/x-ms-wmv",xbm:"image/x-xbitmap",xpm:"image/x-xpixmap",xwd:"image/x-xwindowdump",z:"application/x-compress",zip:"application/zip"};a=a.name.split(".");a=2<=a.length?""==a[0]?"n/a": a[a.length-1]:"n/a";a&&(a=a.toLowerCase());return a in b?b[a]:"n/a"}function q(a){switch(n(a).split("/")[0]){case "video":return"VIDEO";case "audio":return"AUDIO";case "image":return"IMAGE";case "text":return"CAPTION";default:return"OTHER"}}var h=function(a){this.LIQUID_BASE_URL="//api.sambavideos.sambatech.com/v1";this.LIQUID_CREATE_MEDIA="/medias/widget";this.QUALIFIER_MAP={AUDIO:[],VIDEO:[]};this.ERROR_MAP={onCreateMedia:"Could not create media. Please try again",onUploadId:"Could not initialize the upload to our servers. Please try again", onPartSendEndAttemp:"Could not send the file to our servers. Please try again",onPartSend:"Could not send one of the file's part to our servers. Trying again in 5 seconds"};this.TIMEOUT=6E5;this.wEvents=k;this.options=l({maxConcurrentParts:5,retries:3,template:"bootstrap",progressIntervalMS:500},a);this.multipartSupported=!("undefined"==typeof File||"undefined"==typeof Blob||!(Blob.prototype.webkitSlice||Blob.prototype.mozSlice||Blob.prototype.slice));if(!0!==this.multipartSupported)return alert("Browser isn't supported. Please update to Chrome 15+ or Firefox 14+"), !1;this.wFiles=[];this.concurrentParts=0;this.mustCalculateConcurrentParts=!0;this._init()};h.prototype._init=function(){for(var a=document.getElementsByTagName("script"),b=a.length;b--;)null!==a[b].getAttribute("samba-upload-widget")&&this._appendWidget(a[b].parentNode);"bootstrap"===this.options.template&&this._events()};h.prototype._appendWidget=function(a){var b=this,c=document.createElement("div");c.innerHTML="bootstrap"===b.options.template?b._getBootstrapTemplate():b._getSimpleTemplate();a.appendChild(c); document.querySelector("#samba-upload").addEventListener("change",function(a){for(var c=a.target.files.length;c--;)b._add(a.target.files[c])})};h.prototype._getBootstrapTemplate=function(){return'

'};h.prototype._getSimpleTemplate=function(){return'
'}; h.prototype._events=function(){"bootstrap"===this.options.template&&(k.addEventListener("media_created",function(a){document.querySelector("div.samba-progress-container").innerHTML=document.querySelector("div.samba-progress-container").innerHTML+'
0%
'}),k.addEventListener("upload_progress",function(a){var b=document.querySelector("div.progress-bar.media-"+ a.media.id);a=(a.media.totalSent/a.media.file.size*100).toFixed(0)+"%";b.style.width=a;b.innerHTML=a}),k.addEventListener("upload_completed",function(a){var b=document.querySelector("div.progress-bar.media-"+a.media.id);b.style.width="100%";b.innerHTML="media upload #"+a.media.id+" completed"}),k.addEventListener("error",function(a){document.querySelector("div.samba-progress").innerHTML='
Error. Please try again
'}))}; h.prototype._add=function(a){var b=this;a={file:a,totalSent:0,status:"PENDING",xhr:[]};a.queryParams=m({type:"multipart",size:a.file.size,name:a.file.name,mime:n(a.file)});(function(a){var d=b.LIQUID_BASE_URL+b.LIQUID_CREATE_MEDIA+"?uk="+b.options.upload_key,e=JSON.stringify({qualifier:q(a.file)}),f=new XMLHttpRequest;f.open("POST",d,!0);f.setRequestHeader("Content-Type","application/json;charset=UTF-8");f.send(e);f.onreadystatechange=function(){4==f.readyState&&(200==f.status?(a=l(a,JSON.parse(f.responseText)), b.wFiles.push(a),1==b.wFiles.length&&b._getUploadId(a),k.dispatch("media_created",a)):(a.status="ERROR",a.error={response:JSON.parse(f.responseText),type:b.ERROR_MAP.onCreateMedia},k.dispatch("error",a)))}})(a)};h.prototype._getUploadId=function(a){var b=this,c=new XMLHttpRequest;c.open("POST",a.uploadProxyUrl+"&"+a.queryParams,!0);c.setRequestHeader("Content-Type","application/json;charset=UTF-8");c.send();c.onreadystatechange=function(){if(4==c.readyState)if(200==c.status){a.uploadInfo=JSON.parse(c.responseText); var d=a.uploadInfo,e;e=a.uploadProxyUrl.split("?")[1];e=JSON.parse('{"'+decodeURI(e.replace(/&/g,'","').replace(/=/g,'":"'))+'"}');d.key=e.key;a.uploadInfo.rawUrl=a.uploadProxyUrl.split("?")[0]+"/"+a.uploadInfo.id;b._initUpload(a)}else if(500===c.status||0===c.status)a.status="ERROR",a.error={response:0=a.uploadInfo.parts)&&this.mustCalculateConcurrentParts){var c= this._calcBandwidth(b);null!=c&&(this.options.maxConcurrentParts=7E5>c?1:1E6>c?2:15E5>c?3:2E6>c?4:25E5>c?5:6,this.mustCalculateConcurrentParts=!1)}};h.prototype._calcBandwidth=function(a){var b=a.endTime.getTime()-a.startTime.getTime();a=a.loadedBytes;return 0>=b||null==a?null:8*a/(b/1E3)};h.prototype.abortUpload=function(a){for(a=a.xhr.length;a--;)try{xhr[a].abort()}catch(b){}};h.prototype.completeNotify=function(a){var b=this,c=b.LIQUID_BASE_URL+a.widgetNotifyPath+"?uk="+b.options.upload_key,d= JSON.stringify({type:"UPLOAD",status:"COMPLETED",input:{path:a.uploadInfo.path,format:n(a.file),fileSize:a.file.size,assetId:a.uploadInfo.assetId,assetName:a.uploadInfo.assetName,container:a.uploadInfo.container}}),e=new XMLHttpRequest;e.open("POST",c,!0);e.setRequestHeader("Content-Type","application/json;charset=UTF-8");e.send(d);e.onreadystatechange=function(){if(4==e.readyState)if(200==e.status){k.dispatch("upload_completed",a);for(var c=b.wFiles.length;c--;)b.wFiles[c].id==a.id&&b.wFiles.splice(c, 1)}else if(500===e.status||0===e.status)a.status="ERROR",a.error={response:"Error creating media",type:b.ERROR_MAP.onCreateMedia},k.dispatch("error",a)}};var p={},p=function(){this.listeners={}};p.prototype={addEventListener:function(a,b,c){for(var d=[],e=arguments.length,f=0;f