(function(a){a.fn.extend({html5Loader:function(t){var y=this;var x={preloaderType:"circular",currPercentage:0,getFilesToLoadJSON:null,positionX:y.width()/2,positionY:y.height()/2,lineWidth:5,color:"#ffffff",font:"normal 11px Arial",fullScreen:true,onComplete:function(){},onItemLoaded:function(Q,R){},pathToFallbackGif:"../preloaderFallback.gif",radius:40,glowColor:null,debugMode:false};var t=a.extend(x,t);var n=t.preloaderType,P=t.currPercentage,w=t.positionX,u=t.positionY,o=t.lineWidth,v=t.color,K=t.font,E=t.getFilesToLoadJSON,F=t.onComplete,A=t.onItemLoaded,C=t.pathToFallbackGif,H=t.radius,r=t.fullScreen,m=t.glowColor;debugMode=t.debugMode;var h=null,f=Math.PI,i={startAngle:1.5*f,endAngle:0},M=a(y).attr("id")==undefined?a(y).attr("class"):a(y).attr("id"),c=0,q=0,G=0,d=false,g=[],j=[],s=[],L=[],O=[],D=[],J=Modernizr.video.h264,b=Modernizr.video.ogg,l=Modernizr.video.webm,N=Modernizr.audio.mp3,e=Modernizr.audio.ogg,I=[],k=0,z=[],p=[],B=this;B.fileExtension=function(V){var U=V.lastIndexOf(".");var T=V.length;if(U!=-1&&T!=U+1){var R=V.split(".");var Q=R.length;var S=R[Q-1].toLowerCase()}else{S="No extension found"}return S};B.setFullscreen=function(){debugMode==true?console.log("Setting Full screen"):"";y.css({position:"fixed",height:a(window).height(),width:a(window).width(),"z-index":98,top:0});w=y.width()/2;u=y.height()/2;a(y).html('<canvas id="html5Canvas'+M+'" width="'+a(y).width()+'px "height="'+a(y).height()+'px"></canvas>');h=document.getElementById("html5Canvas"+M);a(h).css({position:"fixed",top:(a(window).height()/2)-(a(h).height()/2),left:(a(window).width()/2)-(a(h).width()/2),"z-index":99});a(window).bind("resize.CenterCanvas",function(){a(h).css({top:(a(window).height()/2)-(a(h).height()/2),left:(a(window).width()/2)-(a(h).width()/2)});y.css({position:"fixed",height:a(window).height(),width:a(window).width(),"z-index":98})})};B.fillFilesArray=function(R,S,Q,T){q+=S;debugMode==true?console.log("Getting file:"+Q+" Size: "+S):"";g.push(R);j.push(S);s.push(Q);L.push(T)};B.startLoadElements=function(){a(g).each(function(S,U){if(j[S]>0){if(L[S]=="IMAGE"){a(g[S]).load(function(){if(a(g[S])){var W=new A(s[S],U)}G+=j[S];B.updatePercentage(G);debugMode==true?console.log("File Loaded:"+s[S]):""});debugMode==true?console.log("Loading file:"+s[S]):""}if(L[S]=="SCRIPT"){a.getScript(g[S],function(){if(a(g[S])){var W=new A(s[S],U)}G+=j[S];B.updatePercentage(G);debugMode==true?console.log("File Loaded:"+s[S]):""});debugMode==true?console.log("Loading file:"+s[S]):""}if(L[S]=="VIDEO"||L[S]=="AUDIO"){var T=k;I[T]=document.getElementById(g[S]);var R=j[S],Q=0,V=0;I[T].addEventListener("progress",z[T]=function(W){if(I[T].buffered!=undefined){if(I[T].buffered.length>0){Q=(R/I[T].duration)*I[T].buffered.end(0)}V=Q-V;j[S]-=V;G+=V;B.updatePercentage(G);V=Q;debugMode==true?console.log("File Loading in progress:"+s[S]):""}},true);I[T].addEventListener("canplaythrough",p[T]=function(W){if(a(g[S])){var X=new A(s[S],I[T])}I[T].removeEventListener("progress",z[T],true);I[T].removeEventListener("canplaythrough",p[T],true);G+=j[S];B.updatePercentage(G);debugMode==true?console.log("File Loaded:"+s[S]):""},true);k++;debugMode==true?console.log("Loading file:"+s[S]):""}}})};B.updatePercentage=function(Q){P=~~(((Q/q)*100)|0)+1;debugMode==true?console.log("Percentage: "+~~(P)+"%"):"";if(t.preloaderType=="line"&&Modernizr.canvas){B.drawLinePreloader(P)}if((t.preloaderType=="circular"&&Modernizr.canvas)){B.draw_CircularPreloader(P)}};B.onComplete=function(){if(c>=100){if(F!=null){var Q=new F}y.delay(1000).fadeOut(function(){a(window).unbind("CenterCanvas");a(this).remove()})}};B.drawLinePreloader=function(Q){debugMode==true?console.log("Drawing line"):"";a({perc:c}).animate({perc:Q},{duration:1000,step:function(){if(this.perc<101){c=Q;var S=h.getContext("2d");var R=(y.width()/100)*this.perc;S.clearRect(0,0,y.width(),y.height());S.restore();S.beginPath();S.font=K;S.fillStyle=v;S.fillText((this.perc|0)+"%",w-8,u-15);S.lineWidth=o;S.strokeStyle=v;if(m!=null){S.shadowOffsetX=0;S.shadowOffsetY=0;S.shadowBlur=10;S.shadowColor=m}S.moveTo(w-(y.width()/2),u);S.lineTo(R,u);S.stroke();S.save()}},complete:B.onComplete})};B.draw_CircularPreloader=function(Q){debugMode==true?console.log("Drawing circle"):"";debugMode==true?console.log(Q):"";a({perc:c}).animate({perc:Q},{queque:false,duration:1000,step:function(){if(this.perc<101){c=Q;var S=h.getContext("2d");var R=(2/100)*this.perc;i.endAngle=(R*f)+i.startAngle;S.clearRect(0,0,y.width(),y.height());S.restore();S.beginPath();S.font=K;S.fillStyle=v;S.fillText((this.perc|0)+"%",w-10,u+3);S.lineWidth=o;S.strokeStyle=v;if(m!=null){S.shadowOffsetX=0;S.shadowOffsetY=0;S.shadowBlur=10;S.shadowColor=m}S.arc(w,u,H,i.startAngle,i.endAngle,false);S.stroke();S.save()}},complete:B.onComplete})};B.init=function(Q){debugMode==true?console.log("Start application!"):"";if(!E&&P==0){alert("plese insert a path to json file")}if(E&&(Modernizr.audio&&Modernizr.video)){a.getJSON(E,function(U){var T=U.files;a.each(U.files,function(ac,V){var W=null,X=null,Z=null,ad=null;W=V.type;var ab=String((new Date()).getTime()).replace(/\D/gi,"");switch(W){case"IMAGE":var X=V.source,Z=V.size,ad=a('img[src="'+X+'"]');a(ad).attr("src",X+"?"+ab);break;case"VIDEO":var Y=V.videoId,ad=Y;a("#"+ad).attr("preload","auto");if(J){X=V.mp4.source;Z=V.mp4.size}if(b){X=V.ogg.source;Z=V.ogg.size}if(l){X=V.webm.source;Z=V.webm.size}break;case"AUDIO":var aa=V.audioId,ad=aa;a("#"+ad).attr("preload","auto");if(Modernizr.audio.mp3!=""&&Modernizr.audio.mp3!=false){X=V.mp3.source;Z=V.mp3.size}if(Modernizr.audio.ogg!=""&&Modernizr.audio.ogg!=false){X=V.ogg.source;Z=V.ogg.size}else{X="we can't detect preferred browser audio format";Z=0}break;case"SCRIPT":var X=V.source,Z=V.size,ad=X;break;default:console.log("something was wrong during json loading!");break}B.fillFilesArray(ad,Z,X,W);var ae=(ac==(T.length-1));if(ae==true){B.startLoadElements()}})})}if(Modernizr.canvas){if(r==true){B.setFullscreen()}else{a(y).html('<canvas id="html5Canvas'+M+'" width="'+a(y).width()+'px "height="'+a(y).height()+'px"></canvas>');h=document.getElementById("html5Canvas"+M)}if(E){B.updatePercentage(0)}if(Q.preloaderType=="line"){B.drawLinePreloader(P)}if(Q.preloaderType=="circular"){B.draw_CircularPreloader(P)}}else{debugMode==true?console.log("Fallback"):"";if(r==true){var R=y.append('<img src="'+C+'" alt="loading page..." /> ');var S=y.find("img").attr("src",C);S.css({position:"fixed",top:(a(window).height()/2)-(S.height()/2),left:(a(window).width()/2)-(S.width()/2),"z-index":99});y.css({position:"fixed",height:a(window).height(),width:a(window).width(),"z-index":98});a(window).bind("resize.CenterCanvas",function(){var T=y.find("img").attr("src",C);T.css({top:(a(window).height()/2)-(T.height()/2),left:(a(window).width()/2)-(T.width()/2)});y.css({position:"fixed",height:a(window).height(),width:a(window).width()})})}else{var R=y.append('<img src="'+C+'" alt="loading page..." /> ');R.css({"float":"left",marginLeft:w,marginTop:u})}a(window).ready(function(){R.delay(1000).fadeOut(function(){a(this).remove()})})}};return B.init(t)}})})(jQuery);
