(function(h){var g={images:[],sequence:"",from:0,to:1,step:1,folder:"pic/",grid:{height:800,width:600,rows:1,columns:1},loader:{path:"img/loader2.png",height:50,width:50,rows:2,columns:4},fps:12,width:640,height:480,loadParallel:1,repeat:true,playOnLoad:false,playBackwards:false,showPreLoader:false,verbose:true,clipQueue:[]};var f={init:function(k){_settings=h.extend(true,{},g);if(k!=undefined){h.extend(_settings,k)}return this.each(function(){var p=h(this).data("jsMovie");if(!p){h(this).data("settings",_settings);h(this).data("jsMovie",h(this));if(h(this).data("settings").sequence!==""){h(this).data("settings").images=[];var r;for(var o=h(this).data("settings").from;o<=h(this).data("settings").to;o=o+h(this).data("settings").step){var l=1;if(o>0){l=(Math.floor(Math.log(o)/Math.log(10))+1)}r=new RegExp("^(.*?)([#]{1,"+l+"}?)([^#]+)","g");var s=r.exec(h(this).data("settings").sequence);h(this).data("settings").images.push((s[1]+o+s[3]).replace(/#/g,"0"))}}h(this).data("restoreCss",{width:h(this).width(),height:h(this).height(),overflow:h(this).css("overflow")});h(this).css({width:h(this).data("settings").width,height:h(this).data("settings").height,overflow:"hidden"});h(this).data("currentFrame",h(this));var n=0;for(var q=0;q<h(this).data("settings").images.length;q++){for(var u=0;u<h(this).data("settings").grid.rows;u++){for(var m=0;m<h(this).data("settings").grid.columns;m++){h(this).data("frame"+n,h("<div class='jsMovieFrame' />"));h(this).append(h(this).data("frame"+n));h(this).data("currentFrame",h(this).data("frame"+n));h(this).data("currentFrame").hide();h(this).data("frame"+n).css({width:h(this).data("settings").width,height:h(this).data("settings").height,"background-position":(-h(this).data("settings").grid.width*m)+"px "+(-h(this).data("settings").grid.height*u)+"px","background-repeat":"no-repeat"}).data("frame",n+1);n++}}}h(this).data("currentStatus","stopped");h(this).bind("play",e);h(this).bind("stop",c);h(this).bind("pause",b);h(this).data("frame0").show();h(this).data("currentFrame",h(this).data("frame0"));h(this).data("currentFrame").css({"background-image":'url("'+h(this).data("settings").folder+h(this).data("settings").images[0]+'")'});h(this).append("<div id='jsMovie_event_overlay'></div>");h(this).append("<div id='jsMovie_image_preload_container'></div>");var t=h(this);h("#jsMovie_event_overlay").css({width:h(t).data("settings").width,height:h(t).data("settings").height*2,"margin-top":"-"+(h(t).data("settings").height*2)+"px"});a.apply(h(this));d.apply(h(this))}else{f.throwError(1)}})},option:function(k,l){if(l==undefined){return this.data("settings")[k]}else{this.data("settings")[k]=l;return this}},realFps:function(){return h(this).data("realFps")},play:function(k,m,n){if(this.data("loadStatus")!="loaded"){var l=this;this.bind("loaded.playDeferrer",function(){f.play.apply(l,[k,m,n])});return this}if(k===undefined){k=1}if(m===undefined){m=h(this).data("settings").images.length*h(this).data("settings").grid.rows*h(this).data("settings").grid.columns}if(n===undefined){n=h(this).data("settings").repeat}h(this).data("currentStatus","play");h(this).trigger("play",[k,m,n]);return this},pause:function(){h(this).data("currentStatus","paused");h(this).trigger("pause");return this},stop:function(){h(this).data("currentStatus","stopped");h(this).trigger("stop");return this},playUntil:function(k){f.play.apply(this,[1,k]);return this},gotoFrame:function(l){var k=this;h(this).find(".jsMovieFrame").each(function(m,n){if(l==h(this).data("frame")&&h(this).data("loaded")!==undefined){h(k).find(".jsMovieFrame").hide();h(k).data("currentFrame",h(this));h(k).data("currentFrame").show()}else{h(k).data("gotoFrameOnLoaded",l)}});return this},nextFrame:function(){if(h(this).data("currentFrame").next(".jsMovieFrame").length==0){h(this).data("frame0").show();h(this).data("currentFrame").hide();h(this).data("currentFrame",h(this).data("frame0"))}else{h(this).data("currentFrame").next().show();h(this).data("currentFrame").hide();h(this).data("currentFrame",h(this).data("currentFrame").next())}return this},previousFrame:function(){if(h(this).data("currentFrame").data("frame")!=1){h(this).data("currentFrame").prev().show();h(this).data("currentFrame").hide();h(this).data("currentFrame",h(this).data("currentFrame").prev())}else{h(this).data("currentFrame").siblings(".jsMovieFrame").last().show();h(this).data("currentFrame").hide();h(this).data("currentFrame",h(this).data("currentFrame").siblings(".jsMovieFrame").last())}return this},playClip:function(k,l){if(l===undefined){l=h(this).data("settings").repeat}if(k===undefined){f.play.apply(this)}if(typeof k=="object"){_clip=k}if(typeof k=="string"){_clip=f.getClip.apply(this,[k])}if(typeof k=="function"){_clip=k()}if(typeof k=="number"){if(k<0){k=0}if(k>this.data("settings").clipQueue.length){k=this.data("settings").clipQueue.length-1}_clip=this.data("settings").clipQueue[parseInt(k)]}if(_clip){if(this.data("settings").playBackwards){f.gotoFrame.apply(this,[_clip.end])}else{f.gotoFrame.apply(this,[_clip.start])}f.play.apply(this,[_clip.start,_clip.end,l])}else{f.throwError(3)}return this},playClips:function(){var l=this;if(this.data("settings").clipQueue.length<1){f.play.apply(this)}else{if(this.data("currentClip")===undefined){this.data("currentClip",l.data("settings").playBackwards?l.data("settings").clipQueue.length-1:0)}var k=this.data("settings").clipQueue[this.data("currentClip")<=0?this.data("settings").clipQueue.length-1:this.data("currentClip")-1];var m=this.data("settings").clipQueue[this.data("currentClip")];f.playClip.apply(this,[this.data("currentClip"),false]);this.bind("ended.playClips",function(n){h(this).unbind(".playClips");if(!(m.pause>0)){m.pause=0}f.gotoFrame.apply(h(this),[l.data("settings").playBackwards?m.start:m.end]);setTimeout(function(){if(l.data("settings").playBackwards){if(l.data("settings").repeat){l.data("currentClip",l.data("currentClip")<=0?l.data("settings").clipQueue.length-1:l.data("currentClip")-1);f.playClips.apply(l)}else{if(l.data("currentClip")>0){l.data("currentClip",l.data("currentClip")-1);f.playClips.apply(l)}}}else{if(l.data("settings").repeat){l.data("currentClip",l.data("currentClip")==l.data("settings").clipQueue.length-1?0:l.data("currentClip")+1);f.playClips.apply(l)}else{if(l.data("currentClip")<l.data("settings").clipQueue.length-1){l.data("currentClip",l.data("currentClip")+1);f.playClips.apply(l)}}}},h(this).data("settings").playBackwards?k.pause:m.pause)})}},addClip:function(l,o,k,n,m){if(n===undefined){n=0}if(m===undefined){m=h(this).data("settings").clipQueue.length}if(o>=1&&k<=h(this).data("settings").images.length*h(this).data("settings").grid.rows*h(this).data("settings").grid.columns&&m<=h(this).data("settings").clipQueue.length){newClip={name:l,start:o,end:k,pause:n};h(this).data("settings").clipQueue.splice(m,0,newClip)}else{f.throwError(2)}return this},getClip:function(k){for(var l in h(this).data("settings").clipQueue){if(h(this).data("settings").clipQueue[l].name==k){return h(this).data("settings").clipQueue[l]}}return undefined},removeClip:function(l){for(var k in h(this).data("settings").clipQueue){if(h(this).data("settings").clipQueue[k].name==l||h(this).data("settings").clipQueue[k]===l){}}return this},getClipQueue:function(){return h(this).data("settings").clipQueue},destroy:function(){return this.each(function(){h(this).children().remove();h(this).css(h(this).data("restoreCss"));clearInterval(h(this).data("playingInterval"));h(this).removeData()})},throwError:function(l){var k="";if(l!=undefined){if(l==1){k="This Objekt has already been initialized!"}else{if(l==2){k="Clip out of Range!"}else{if(l==3){k="Clip not Found!"}else{if(true){k="Unknown Error"}}}}}else{k="Unknown Error"}if(window.console){console.log(k)}else{alert(k)}return this}};function e(o,k,m,n){if(k===undefined||k<1){k=1}if(m===undefined||m>h(this).data("settings").images.length*h(this).data("settings").grid.rows*h(this).data("settings").grid.columns){m=h(this).data("settings").images.length*h(this).data("settings").grid.rows*h(this).data("settings").grid.columns}if(n===undefined){n=h(this).data("settings").repeat}if(h(this).data("currentStatus")=="play"){clearInterval(h(this).data("playingInterval"));h(this).data("currentStatus","playing");var l=this;h(this).data("playingInterval",setInterval(function(){if(h(l).data("realFpsTimeStamp")!=undefined){h(l).data("realFps",1/(((new Date()).getTime()-h(l).data("realFpsTimeStamp"))/1000))}else{h(l).data("realFps",h(l).data("settings").fps)}h(l).data("realFpsTimeStamp",(new Date()).getTime());if(h(l).data("settings").playBackwards){if(h(l).data("currentFrame").data("frame")==k&&!n){h(l).trigger("stop");h(l).trigger("ended")}else{h(l).trigger("playing");if(h(l).data("currentFrame").data("frame")!=k){f.previousFrame.apply(h(l))}else{f.gotoFrame.apply(h(l),[m])}}}else{if(h(l).data("currentFrame").data("frame")==m&&!n){h(l).trigger("stop");h(l).trigger("ended")}else{h(l).trigger("playing");if(h(l).data("currentFrame").data("frame")!=m){f.nextFrame.apply(h(l))}else{f.gotoFrame.apply(h(l),[k])}}}},1000/h(this).data("settings").fps))}}function c(k){clearInterval(h(this).data("playingInterval"));h(this).find(".jsMovieFrame").hide();h(this).data("currentFrame",h(this).data("frame0"));h(this).data("currentFrame").show();h(this).data("currentStatus","stop");h(this).data("playUntil",-1)}function b(k){clearInterval(h(this).data("playingInterval"))}function a(m){if(m==undefined){m=0;this.data("loadStatus","loading");for(loadParralelCount=1;loadParralelCount<=this.data("settings").loadParallel;loadParralelCount++){a.apply(h(this),[loadParralelCount])}return}if(m>this.data("settings").images.length){this.data("loadStatus","loaded");this.trigger("loaded");if(this.data("settings").playOnLoad){f.play.apply(h(this))}return}var l=new Image();var k=this;l.onload=function(){var p=h(k).data("settings").grid.rows*h(k).data("settings").grid.columns;for(var o=0;o<p;o++){h(k).data("frame"+(o+((m-1)*p))).css({"background-image":"url("+h(k).data("settings").folder+h(k).data("settings").images[m-1]+")"});h(k).data("frame"+(o+((m-1)*p))).data("loaded",true)}if(h(k).data("gotoFrameOnLoaded")!=undefined&&Math.ceil(h(k).data("gotoFrameOnLoaded")/p)==m){var n=h(k).data("gotoFrameOnLoaded");h(k).removeData("gotoFrameOnLoaded");f.gotoFrame.apply(h(k),[n])}a.apply(h(k),[m+k.data("settings").loadParallel]);j.apply(k,["Image #"+(m)+" has been loaded"]);i.apply(h(k))};l.src=h(this).data("settings").folder+h(this).data("settings").images[m-1];h("#jsMovie_image_preload_container").append(l);h(l).css({height:"1px",width:"1px"})}function d(){if(this.data("loadStatus")!="loaded"&&h(this).data("settings").showPreLoader){this.append("<div class='laoderOverlay' />").children(".laoderOverlay").css({"background-color":"black",opacity:0.8,height:this.height()+"px",width:this.width()+"px",position:"absolute",top:this.offset().top+"px",left:this.offset().left+"px"});this.append("<div class='laoderAnimation' />").children(".laoderAnimation").css({"background-image":"url("+h(this).data("settings").loader.path+")",height:h(this).data("settings").loader.height+"px",width:h(this).data("settings").loader.width+"px",position:"absolute",top:(this.offset().top+(this.height()/2)-(h(this).data("settings").loader.height/2))+"px",left:(this.offset().left+(this.width()/2)-(h(this).data("settings").loader.width/2))+"px","background-repeat":"no-repeat"});this.children(".laoderAnimation").data("currentFrame",0);var k=this;var l=setInterval(function(){if(k.data("loadStatus")=="loaded"){k.children(".laoderOverlay, .laoderAnimation").remove();clearInterval(l)}var m=k.children(".laoderAnimation").data("currentFrame");k.children(".laoderAnimation").css({"background-position":(-h(k).data("settings").loader.width*(m%h(k).data("settings").loader.columns))+"px "+(-h(k).data("settings").loader.height*Math.floor(m/h(k).data("settings").loader.columns))+"px"});k.children(".laoderAnimation").data("currentFrame",(m+1)%(h(k).data("settings").loader.rows*h(k).data("settings").loader.columns));i.apply(h(k))},100)}}function i(){this.children(".laoderOverlay").css({top:this.offset().top+"px",left:this.offset().left+"px"});this.children(".laoderAnimation").css({top:(this.offset().top+(this.height()/2)-(h(this).data("settings").loader.height/2))+"px",left:(this.offset().left+(this.width()/2)-(h(this).data("settings").loader.width/2))+"px"})}function j(k){this.trigger("verbose",k)}h.fn.jsMovie=function(k){if(f[k]){return f[k].apply(this,Array.prototype.slice.call(arguments,1))}else{if(typeof k==="object"||!k){return f.init.apply(this,arguments)}else{h.error("Method "+k+" does not exist on jQuery.jsMovie")}}}})(jQuery);
