var Pixastic=function(){function g(a,c,b){if(a.addEventListener)a.addEventListener(c,b,false);else a.attachEvent&&a.attachEvent("on"+c,b)}function h(d){var c=false,b=function(){if(!c){c=true;d()}};document.write('<script defer src="//:" id="__onload_ie_pixastic__"><\/script>');var a=document.getElementById("__onload_ie_pixastic__");a.onreadystatechange=function(){if(a.readyState=="complete"){a.parentNode.removeChild(a);b()}};document.addEventListener&&document.addEventListener("DOMContentLoaded",b,false);g(window,"load",b)}function k(){for(var e=b("pixastic",null,"img"),d=b("pixastic",null,"canvas"),c=e.concat(d),a=0;a<c.length;a++)(function(){for(var b=c[a],d=[],i=b.className.split(" "),g=0;g<i.length;g++){var j=i[g];if(j.substring(0,9)=="pixastic-"){var h=j.substring(9);h!=""&&d.push(h)}}if(d.length)if(b.tagName.toLowerCase()=="img"){var e=new Image;e.src=b.src;if(e.complete)for(var f=0;f<d.length;f++){var k=Pixastic.applyAction(b,b,d[f],null);if(k)b=k}else e.onload=function(){for(var a=0;a<d.length;a++){var c=Pixastic.applyAction(b,b,d[a],null);if(c)b=c}}}else setTimeout(function(){for(var a=0;a<d.length;a++){var c=Pixastic.applyAction(b,b,d[a],null);if(c)b=c}},1)})()}typeof pixastic_parseonload!="undefined"&&pixastic_parseonload&&h(k);function b(e,a,c){var d=[];if(a==null)a=document;if(c==null)c="*";var b=a.getElementsByTagName(c),g=b.length,f=new RegExp("(^|\\s)"+e+"(\\s|$)");for(i=0,j=0;i<g;i++)if(f.test(b[i].className)){d[j]=b[i];j++}return d}var f;function a(a,b){if(!Pixastic.debug)return;try{switch(b){case"warn":console.warn("Pixastic:",a);break;case"error":console.error("Pixastic:",a);break;default:console.log("Pixastic:",a)}}catch(c){}!f}var d=function(){var b=document.createElement("canvas"),a=false;try{a=!!(typeof b.getContext=="function"&&b.getContext("2d"))}catch(c){}return function(){return a}}(),c=function(){var c=document.createElement("canvas"),b=false,a;try{if(typeof c.getContext=="function"&&(a=c.getContext("2d")))b=typeof a.getImageData=="function"}catch(d){}return function(){return b}}(),e=function(){var f=false,e=document.createElement("canvas");if(d()&&c()){e.width=e.height=1;var a=e.getContext("2d");a.fillStyle="rgb(255,0,0)";a.fillRect(0,0,1,1);var b=document.createElement("canvas");b.width=b.height=1;var g=b.getContext("2d");g.fillStyle="rgb(0,0,255)";g.fillRect(0,0,1,1);a.globalAlpha=.5;a.drawImage(b,0,0);var h=a.getImageData(0,0,1,1).data;f=h[2]!=255}return function(){return f}}();return{parseOnLoad:false,debug:false,applyAction:function(b,q,e,d){d=d||{};var i=b.tagName.toLowerCase()=="canvas";if(i&&Pixastic.Client.isIE()){Pixastic.debug&&a("Tried to process a canvas element but browser is IE.");return false}var c,p,n=false;if(Pixastic.Client.hasCanvas()){n=!!d.resultCanvas;c=d.resultCanvas||document.createElement("canvas");p=c.getContext("2d")}var g=b.offsetWidth,f=b.offsetHeight;if(i){g=b.width;f=b.height}if(g==0||f==0)if(b.parentNode==null){var s=b.style.position,r=b.style.left;b.style.position="absolute";b.style.left="-9999px";document.body.appendChild(b);g=b.offsetWidth;f=b.offsetHeight;document.body.removeChild(b);b.style.position=s;b.style.left=r}else{Pixastic.debug&&a("Image has 0 width and/or height.");return}if(e.indexOf("(")>-1){var l=e;e=l.substr(0,l.indexOf("("));var h=l.match(/\((.*?)\)/);if(h[1]){h=h[1].split(";");for(var m=0;m<h.length;m++){thisArg=h[m].split("=");if(thisArg.length==2)if(thisArg[0]=="rect"){var j=thisArg[1].split(",");d[thisArg[0]]={left:parseInt(j[0],10)||0,top:parseInt(j[1],10)||0,width:parseInt(j[2],10)||0,height:parseInt(j[3],10)||0}}else d[thisArg[0]]=thisArg[1]}}}if(!d.rect)d.rect={left:0,top:0,width:g,height:f};else{d.rect.left=Math.round(d.rect.left);d.rect.top=Math.round(d.rect.top);d.rect.width=Math.round(d.rect.width);d.rect.height=Math.round(d.rect.height)}var o=false;if(Pixastic.Actions[e]&&typeof Pixastic.Actions[e].process=="function")o=true;if(!o){Pixastic.debug&&a('Invalid action "'+e+'". Maybe file not included?');return false}if(!Pixastic.Actions[e].checkSupport()){Pixastic.debug&&a('Action "'+e+'" not supported by this browser.');return false}if(Pixastic.Client.hasCanvas()){if(c!==b){c.width=g;c.height=f}if(!n){c.style.width=g+"px";c.style.height=f+"px"}p.drawImage(q,0,0,g,f);if(!b.__pixastic_org_image){c.__pixastic_org_image=b;c.__pixastic_org_width=g;c.__pixastic_org_height=f}else{c.__pixastic_org_image=b.__pixastic_org_image;c.__pixastic_org_width=b.__pixastic_org_width;c.__pixastic_org_height=b.__pixastic_org_height}}else if(Pixastic.Client.isIE()&&typeof b.__pixastic_org_style=="undefined")b.__pixastic_org_style=b.style.cssText;var k={image:b,canvas:c,width:g,height:f,useData:true,options:d},t=Pixastic.Actions[e].process(k);if(!t)return false;if(Pixastic.Client.hasCanvas()){if(k.useData)if(Pixastic.Client.hasCanvasImageData()){c.getContext("2d").putImageData(k.canvasData,d.rect.left,d.rect.top);c.getContext("2d").fillRect(0,0,0,0)}if(!d.leaveDOM){c.title=b.title;c.imgsrc=b.imgsrc;if(!i)c.alt=b.alt;if(!i)c.imgsrc=b.src;c.className=b.className;c.style.cssText=b.style.cssText;c.name=b.name;c.tabIndex=b.tabIndex;c.id=b.id;b.parentNode&&b.parentNode.replaceChild&&b.parentNode.replaceChild(c,b)}d.resultCanvas=c;return c}return b},prepareData:function(b,d){var f=b.canvas.getContext("2d"),a=b.options.rect,c=f.getImageData(a.left,a.top,a.width,a.height),e=c.data;if(!d)b.canvasData=c;return e},process:function(a,e,f,b){if(a.tagName.toLowerCase()=="img"){var c=new Image;c.src=a.src;if(c.complete){var d=Pixastic.applyAction(a,c,e,f);b&&b(d);return d}else c.onload=function(){var d=Pixastic.applyAction(a,c,e,f);b&&b(d)}}if(a.tagName.toLowerCase()=="canvas"){var d=Pixastic.applyAction(a,a,e,f);b&&b(d);return d}},revert:function(a){if(Pixastic.Client.hasCanvas()){if(a.tagName.toLowerCase()=="canvas"&&a.__pixastic_org_image){a.width=a.__pixastic_org_width;a.height=a.__pixastic_org_height;a.getContext("2d").drawImage(a.__pixastic_org_image,0,0);a.parentNode&&a.parentNode.replaceChild&&a.parentNode.replaceChild(a.__pixastic_org_image,a);return a}}else if(Pixastic.Client.isIE())if(typeof a.__pixastic_org_style!="undefined")a.style.cssText=a.__pixastic_org_style},Client:{hasCanvas:d,hasCanvasImageData:c,hasGlobalAlpha:e,isIE:function(){return!!document.all&&!!window.attachEvent&&!window.opera}},Actions:{}}}();Pixastic.Actions.desaturate={process:function(c){var h=!!(c.options.average&&c.options.average!="false");if(Pixastic.Client.hasCanvasImageData()){var a=Pixastic.prepareData(c),g=c.options.rect,j=g.width,i=g.height,f=j*i,b=f*4,d,e;if(h)while(f--)a[b-=4]=a[d=b+1]=a[e=b+2]=(a[b]+a[d]+a[e])/3;else while(f--)a[b-=4]=a[d=b+1]=a[e=b+2]=a[b]*.3+a[d]*.59+a[e]*.11;return true}else if(Pixastic.Client.isIE()){c.image.style.filter+=" gray";return true}},checkSupport:function(){return Pixastic.Client.hasCanvasImageData()||Pixastic.Client.isIE()}};
