(function($){$.fn.noisy=function(options){options=$.extend({},$.fn.noisy.defaults,options);var uri,cachedUri;if(JSON&&localStorage.getItem){cachedUri=localStorage.getItem(JSON.stringify(options))}if(cachedUri){uri=cachedUri}else{var canvas=document.createElement('canvas');if(!canvas.getContext){uri=options.fallback}else{canvas.width=canvas.height=options.size;var ctx=canvas.getContext('2d'),imgData=ctx.createImageData(canvas.width,canvas.height),numPixels=options.intensity*Math.pow(options.size,2),maxAlpha=255*options.opacity;while(numPixels--){var x=~~(Math.random()*canvas.width),y=~~(Math.random()*canvas.height),index=(x+y*imgData.width)*4;var colorChannel=numPixels%255;imgData.data[index]=colorChannel;imgData.data[index+1]=options.monochrome?colorChannel:~~(Math.random()*255);imgData.data[index+2]=options.monochrome?colorChannel:~~(Math.random()*255);imgData.data[index+3]=~~(Math.random()*maxAlpha)}ctx.putImageData(imgData,0,0);uri=canvas.toDataURL('image/png');if(uri.indexOf('data:image/png')!=0||$.browser.msie&&$.browser.version.substr(0,1)<9&&uri.length>32768){uri=options.fallback}}if(JSON&&localStorage){localStorage.setItem(JSON.stringify(options),uri)}}return this.each(function(){$(this).css('background-image',"url('"+uri+"'),"+$(this).css('background-image'))})};$.fn.noisy.defaults={intensity:0.9,size:200,opacity:0.08,fallback:'',monochrome:false}})(jQuery);
