var kShowSizeDidChangeEvent="ScriptManager:ShowSizeDidChangeEvent";var kScriptDidDownloadEvent="ScriptManager:ScriptDidDownloadEvent";var kScriptDidNotDownloadEvent="ScriptManager:ScriptDidNotDownloadEvent";var kSlideDidDownloadEvent="SlideManager:SlideDidDownloadEvent";var kSlideDidNotDownloadEvent="SlideManager:SlideDidNotDownloadEvent";var ScriptManager=Class.create({initialize:function(a){this.script=null;this.showUrl=a;this.slideManager=null;document.observe(kSlideDidDownloadEvent,this.handleSlideDidDownloadEvent.bind(this));document.observe(kSlideDidNotDownloadEvent,this.handleSlideDidDownloadEvent.bind(this))},handleSlideDidDownloadEvent:function(c){var k=true;for(var l in this.slideManager.slides){if(this.slideManager.slides.hasOwnProperty(l)){if(!this.slideManager.slides[l].downloaded){k=false;break}}}if(k){this.script.events=[];this.script.originalEvents=[];this.script.slideIndexFromSceneIndexLookup={};this.script.sceneIndexFromSlideIndexLookup={};this.script.slides={};this.script.originalSlides={};var m,g,h,f,j=0,b=0,a=0;for(var l in this.slideManager.slides){if(this.slideManager.slides.hasOwnProperty(l)){h=this.slideManager.slides[l].script;f=this.slideManager.slides[l].originalScript;m=h.events;g=f.events;this.script.slides[l]=h;this.script.originalSlides[l]=f;this.script.sceneIndexFromSlideIndexLookup[j]=b;for(var e=0,d=m.length;e0){var t=k.layers[0];k.layers[0]=k.layers[1];k.layers[1]=t;k.layers[1].initialState.hidden=true;var p=g.layers[0];g.layers[0]=g.layers[1];g.layers[1]=p;g.layers[1].initialState.hidden=true;var l=k.layers[1].animations[0].beginTime;var i=k.layers[1].animations[0].duration;var q=k.layers[1].animations[0].animations[0].beginTime;var a=k.layers[1].animations[0].animations[0].duration;var c;if(l==q){for(var r=0,h=k.layers[1].animations[0].animations.length;r1){for(var r=0,h=k.layers[1].animations[0].animations.length;r0){var l=q.layers[0];q.layers[0]=q.layers[1];q.layers[1]=l;q.layers[1].initialState.hidden=true;var f=k.layers[0];k.layers[0]=k.layers[1];k.layers[1]=f;k.layers[1].initialState.hidden=true;var a=q.layers[1].animations[0].beginTime;var c=q.layers[1].animations[0].duration;var h=q.layers[1].animations[0].animations[0].beginTime;var e=q.layers[1].animations[0].animations[0].duration;var i;if(a==h){for(var g=0,o=q.layers[1].animations[0].animations.length;g1){for(var g=0,o=q.layers[1].animations[0].animations.length;g0){var l=q.layers[0];q.layers[0]=q.layers[1];q.layers[1]=l;q.layers[1].initialState.hidden=true;var f=k.layers[0];k.layers[0]=k.layers[1];k.layers[1]=f;k.layers[1].initialState.hidden=true;var a=q.layers[1].animations[0].beginTime;var c=q.layers[1].animations[0].duration;var h=q.layers[1].animations[0].animations[0].beginTime;var e=q.layers[1].animations[0].animations[0].duration;var i;if(a==h){for(var g=0,o=q.layers[1].animations[0].animations.length;g1){for(var g=0,o=q.layers[1].animations[0].animations.length;g0){var l=JSON.parse(JSON.stringify(q.layers[1]));q.layers.splice(0,0,l);var f=JSON.parse(JSON.stringify(k.layers[1]));k.layers.splice(0,0,f);var a=q.layers[1].animations[0].beginTime;var c=q.layers[1].animations[0].duration;var h=q.layers[1].animations[0].animations[0].beginTime;var e=q.layers[1].animations[0].animations[0].duration;var i;if(a==h){for(var g=0,o=q.layers[1].animations[0].animations.length;gG){G=l}if(z>g){g=z}}C.particleCount={x:G+1,y:g+1}}this.applyScaleFactorForLayer(M.baseLayer,n.baseLayer,k,M.name,I,C)}for(var O=0,t=T.hyperlinks.length;OG){G=l}if(z>g){g=z}}C.particleCount={x:G+1,y:g+1}}this.applyScaleFactorForLayer(R.baseLayer,S.baseLayer,k,R.name,I,C)}}}}for(var p in this.script.slides){if(this.script.slides.hasOwnProperty(p)){var a=this.script.slides[p];var v=this.script.originalSlides[p];for(var E in a.assets){if(a.assets.hasOwnProperty(E)){var r=a.assets[E];var P=v.assets[E];r.width=P.width*k;r.height=P.height*k}}}}},adjustForCropAnimation:function(a,b,i,h){var d=this.script.slideWidth;var f=this.script.slideHeight;var j=Math.floor(d/i);var g=Math.floor(f/h);var e=Math.round(b.x/b.width);var c=Math.round(b.y/b.height);if(b.width!=1||b.height!=1){if(e!=i-1){a.width=j}else{a.width=d-j*(i-1)}if(c!=h-1){a.height=g}else{a.height=f-g*(h-1)}a.position.pointX=j*e+a.width/2;a.position.pointY=g*c+a.height/2;a.contentsRect.x=j*e/d;a.contentsRect.y=g*c/f;a.contentsRect.width=a.width/d;a.contentsRect.height=a.height/f}},downloadScript:function(b){this.delegate=b;if(this.delegate.getKPFJsonStringForShow){this.script=JSON.parse(this.delegate.getKPFJsonStringForShow());if(this.script==null){debugMessageAlways(kDebugScriptMangaer_DownloadScript,"An error occured on the server. KPF header json is null.");return}this.slideManager=new SlideManager({header:this.script});this.slideManager.getSlides(this.script.slideList,this.delegate);return}this.downloadTimeout=setTimeout(this.scriptDidNotDownload.bind(this),kMaxScriptDownloadWaitTime);this.downloadAlreadyFailed=false;var c=this.showUrl+"header.json";if(window.location.protocol==="file:"){c=c+"p";window.local_header=(function(d){this.scriptDidDownload(d,true)}).bind(this);var a=document.createElement("script");a.setAttribute("src",c);document.head.appendChild(a)}else{new Ajax.Request(c,{method:"get",onSuccess:this.scriptDidDownload.bind(this),onFailure:this.scriptDidNotDownload.bind(this)})}},scriptDidDownload:function(b,a){clearTimeout(this.downloadTimeout);if(a){this.script=b}else{this.script=JSON.parse(b.responseText)}this.slideManager=new SlideManager({header:this.script});this.slideManager.downloadSlides(this.script.slideList)},scriptDidNotDownload:function(a){this.downloadAlreadyFailed=true;if(a){clearTimeout(this.downloadTimeout)}document.fire(kScriptDidNotDownloadEvent,{})},sceneIndexFromSlideIndex:function(a){if((this.script==null)||(a<0)||(a>=this.script.slideList.length)){return -1}return this.script.sceneIndexFromSlideIndexLookup[a]},slideIndexFromSceneIndex:function(a){if((this.script==null)||(a<0)||(a>=this.script.events.length)){return -1}return this.script.slideIndexFromSceneIndexLookup[a]}});