(function($){$.runloop=function(settings){var config={'roundType':'floor','base':5};if(settings)$.extend(config,settings);var version="1.0.1",runloop=document.createElement('div'),map={},execLog={},currentDuration=false,remainingDuration=false,currentStep=0,makeAt=function(at){var val=parseInt(at.toString().match(/[0-9]+/g));return(isNaN(val))?false:"at"+val;};return{addKey:function(atPercentage,func){var at=makeAt(atPercentage);if(at){var oldAt=map[at];if(typeof map[at]!='function'){map[at]=func;}else{map[at]=function(){if(oldAt){oldAt();}
func();};}}},removeKey:function(atPercentage){var at=makeAt(atPercentage);if(at){delete map[at];}},addMap:function(newMap){for(var key in newMap){at=makeAt(key);if(at&&typeof newMap[key]=="function"){this.addKey(at,newMap[key]);}}},getMap:function(){return map;},reset:function(){currentDuration=false;remainingDuration=false;currentStep=0;execLog={};$(runloop).css({'top':0});},pause:function(){remainingDuration=currentDuration-Math.round(currentDuration*(Math.floor(currentStep)/100));$(runloop).stop();},play:function(duration,callback){duration=parseInt(duration)||500;if(duration<500){config.base=10;}
if(remainingDuration){duration=remainingDuration;$(runloop).css('top',Math.floor(currentStep));}
if(typeof callback=="function"){this.addKey('100%',callback);}
currentDuration=duration;$(runloop).animate({'top':'100'},{duration:duration,step:function(step){currentStep=step;if(config.roundType=="round"){step=Math.round(step/config.base)*config.base;}else{step=Math.floor(step/config.base)*config.base;}
if(!(step in execLog)&&map['at'+step]){execLog[step]=true;map['at'+step]();}},easing:'linear',complete:function(){currentDuration=false;remainingDuration=false;currentStep=0;execLog={};}});}};};})(jQuery);
