text: // WebcamJS v1.0 - http://github.com/jhuckaby/webcamjs - MIT Licensed
  var Webcam={version:"1.0.0",ie:!!navigator.userAgent.match(/(MSIE|Trident)/),protocol:location.protocol.match(/https/i)?"https":"http",swfURL:"",loaded:!1,live:!1,userMedia:!0,params:{width:0,height:0,dest_width:0,dest_height:0,image_format:"jpeg",jpeg_quality:90,force_flash:!1},hooks:{load:null,live:null,uploadcomplete:null,uploadprogress:null,error:function(a){alert("Webcam.js Error: "+a)}},init:function(){navigator.getUserMedia=navigator.getUserMedia||navigator.webkitGetUserMedia||navigator.mozGetUserMedia||navigator.msGetUserMedia,window.URL=window.URL||window.webkitURL||window.mozURL||window.msURL,this.userMedia=this.userMedia&&!!navigator.getUserMedia&&!!window.URL},attach:function(a){if("string"==typeof a&&(a=document.getElementById(a)||document.querySelector(a)),!a)return this.dispatch("error","Could not locate DOM element to attach to.");if(this.container=a,this.params.width||(this.params.width=a.offsetWidth),this.params.height||(this.params.height=a.offsetHeight),this.params.dest_width||(this.params.dest_width=this.params.width),this.params.dest_height||(this.params.dest_height=this.params.height),this.userMedia&&!this.params.force_flash){var b=document.createElement("video");b.setAttribute("autoplay","autoplay"),b.style.width=""+this.params.dest_width+"px",b.style.height=""+this.params.dest_height+"px";var c=this.params.width/this.params.dest_width,d=this.params.height/this.params.dest_height;(1!=c||1!=d)&&(a.style.overflow="visible",b.style.webkitTransformOrigin="0px 0px",b.style.mozTransformOrigin="0px 0px",b.style.msTransformOrigin="0px 0px",b.style.oTransformOrigin="0px 0px",b.style.transformOrigin="0px 0px",b.style.webkitTransform="scaleX("+c+") scaleY("+d+")",b.style.mozTransform="scaleX("+c+") scaleY("+d+")",b.style.msTransform="scaleX("+c+") scaleY("+d+")",b.style.oTransform="scaleX("+c+") scaleY("+d+")",b.style.transform="scaleX("+c+") scaleY("+d+")"),a.appendChild(b),this.video=b;var e=document.createElement("canvas");e.width=this.params.dest_width,e.height=this.params.dest_height;var f=e.getContext("2d");this.context=f,this.canvas=e,navigator.getUserMedia({audio:!1,video:!0},function(a){b.src=window.URL.createObjectURL(a)||a,Webcam.loaded=!0,Webcam.live=!0,Webcam.dispatch("load"),Webcam.dispatch("live")},function(a){return this.dispatch("error","Could not access webcam: "+a)})}else a.innerHTML=this.getSWFHTML()},reset:function(){this.userMedia&&(delete this.canvas,delete this.context,delete this.video),this.container.innerHTML="",delete this.container,this.loaded=!1,this.live=!1},set:function(){if(1==arguments.length)for(var a in arguments[0])this.params[a]=arguments[0][a];else this.params[arguments[0]]=arguments[1]},on:function(a,b){if(a=a.replace(/^on/i,"").toLowerCase(),"undefined"==typeof this.hooks[a])throw"Event type not supported: "+a;this.hooks[a]=b},dispatch:function(){var a=arguments[0].replace(/^on/i,"").toLowerCase(),b=Array.prototype.slice.call(arguments,1);return this.hooks[a]?("function"==typeof this.hooks[a]?this.hooks[a].apply(this,b):"array"==typeof this.hooks[a]?this.hooks[a][0][this.hooks[a][1]].apply(this.hooks[a][0],b):window[this.hooks[a]]&&window[this.hooks[a]].apply(window,b),!0):!1},setSWFLocation:function(a){this.swfURL=a},getSWFHTML:function(){var a="";if(location.protocol.match(/file/))return'<h1 style="color:red">Sorry, the Webcam.js Flash fallback does not work from local disk.  Please upload it to a web server first.</h1>';if(!this.swfURL){for(var b="",c=document.getElementsByTagName("script"),d=0,e=c.length;e>d;d++){var f=c[d].getAttribute("src");f&&f.match(/webcam(\.min)?\.js/)&&(b=f.replace(/\/webcam(\.min)?\.js.*$/,""),d=e)}this.swfURL=b?b+"/webcam.swf":"webcam.swf"}window.localStorage&&!localStorage.getItem("visited")&&(this.params.new_user=1,localStorage.setItem("visited",1));var g="";for(var h in this.params)g&&(g+="&"),g+=h+"="+escape(this.params[h]);return a+=this.ie?'<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="'+this.protocol+'://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,0,0" width="'+this.params.width+'" height="'+this.params.height+'" id="webcam_movie" align="middle"><param name="allowScriptAccess" value="always" /><param name="allowFullScreen" value="false" /><param name="movie" value="'+this.swfURL+'" /><param name="loop" value="false" /><param name="menu" value="false" /><param name="quality" value="best" /><param name="bgcolor" value="#ffffff" /><param name="flashvars" value="'+g+'"/></object>':'<embed id="webcam_movie" plugin="'+this.swfURL+'" loop="false" menu="false" quality="best" bgcolor="#ffffff" width="'+this.params.width+'" height="'+this.params.height+'" name="webcam_movie" align="middle" allowScriptAccess="always" allowFullScreen="false" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" flashvars="'+g+'" />'},getMovie:function(){if(!this.loaded)return this.dispatch("error","Flash Movie is not loaded yet");var a=document.getElementById("webcam_movie");return a||this.dispatch("error","Cannot locate Flash movie 'webcam_movie' in DOM"),a},snap:function(){if(!this.loaded)return this.dispatch("error","Webcam is not loaded yet");if(!this.live)return this.dispatch("error","Webcam is not live yet");if(this.userMedia)return this.context.drawImage(this.video,0,0,this.params.dest_width,this.params.dest_height),this.canvas.toDataURL("image/"+this.params.image_format,this.params.jpeg_quality/100);var a=this.getMovie()._snap();return"data:image/"+this.params.image_format+";base64,"+a},configure:function(a){a||(a="camera"),this.getMovie()._configure(a)},flashNotify:function(a,b){switch(a){case"flashLoadComplete":this.loaded=!0,this.dispatch("load");break;case"cameraLive":this.live=!0,this.dispatch("live");break;case"error":this.dispatch("error",b)}},b64ToUint6:function(a){return a>64&&91>a?a-65:a>96&&123>a?a-71:a>47&&58>a?a+4:43===a?62:47===a?63:0},base64DecToArr:function(a,b){for(var g,h,c=a.replace(/[^A-Za-z0-9\+\/]/g,""),d=c.length,e=b?Math.ceil((3*d+1>>2)/b)*b:3*d+1>>2,f=new Uint8Array(e),i=0,j=0,k=0;d>k;k++)if(h=3&k,i|=this.b64ToUint6(c.charCodeAt(k))<<18-6*h,3===h||1===d-k){for(g=0;3>g&&e>j;g++,j++)f[j]=255&i>>>(24&16>>>g);i=0}return f},upload:function(a,b,c){c&&Webcam.on("uploadComplete",c);var d="webcam",e="";if(!a.match(/^data\:image\/(\w+)/))throw"Cannot locate image format in Data URI";e=RegExp.$1;var f=a.replace(/^data\:image\/\w+\;base64\,/,""),g=new XMLHttpRequest;g.open("POST",b,!0),g.upload&&g.upload.addEventListener&&g.upload.addEventListener("progress",function(a){if(a.lengthComputable){var b=a.loaded/a.total;Webam.dispatch("uploadProgress",b,a)}},!1),g.onload=function(){Webcam.dispatch("uploadComplete",g.status,g.responseText,g.statusText)};var h=new Blob([this.base64DecToArr(f)],{type:"image/"+e}),i=new FormData;i.append(d,h,d+"."+e.replace(/e/,"")),g.send(i)}};Webcam.init();