/* Copyright (c) 2010-2011 attosoft. Licensed under the MIT License: http://www.opensource.org/licenses/mit-license.php */
var Animations={delay:500,repeat:-1,rewind:false,className:'animation',idPrefix:'animateImage',idIndex:1};function generateAnimationId(){var id;do{id=Animations.idPrefix+Animations.idIndex++;}while(document.getElementById(id));return id;}
function Animation(files,id,repeat,rewind){this.id=id;this.index=0;this.images=generateImages(files);this.repeat=this.count=repeat;this.rewind=rewind;}
function generateImages(files){var isArray=files instanceof Array;var startIndex,endIndex,substr;if(isArray){startIndex=0;endIndex=files.length;}else{var result=files.match(/\[(\d+)-(\d+)\]/);substr=result[0];startIndex=result[1];endIndex=parseInt(result[2],10)+1;}
var images=new Array();for(var i=startIndex;i<endIndex;i++){var image=new Image();image.src=isArray?files[i]:files.replace(substr,padZero(i,startIndex.length));images[images.length]=image;}
return images;}
function padZero(number,digit){var str=''+number;while(str.length<digit){str='0'+str;}
return str;}
function ImageAnimator(files,title,id,delay,repeat,rewind){id=id||generateAnimationId();delay=delay||Animations.delay;repeat=typeof repeat=='number'?repeat:Animations.repeat;rewind=typeof rewind=='boolean'?rewind:Animations.rewind;var anim=new Animation(files,id,repeat,rewind);var imgElem='<img id="'+id+'" src="'+anim.images[0].src+'"';if(typeof title=='string'){imgElem+=' alt="'+title+'" title="'+title+'"';}
if(Animations.className){imgElem+=' class="'+Animations.className+'"';}
imgElem+=' />';document.write(imgElem);this.animate=function(replay){if(anim.repeat==0){return;}else if(replay){this.stopAnimate();anim.index=-1;anim.count=anim.repeat;}else if(anim.intervalID){return;}else if(anim.count==0){anim.count=anim.repeat;}
anim.intervalID=setInterval(function(){_animate(anim);},delay);}
this.stopAnimate=function(){if(!anim.intervalID){return;}
clearInterval(anim.intervalID);delete anim.intervalID;}}
function animateImage(files,title,id,delay,repeat,rewind){var animator=new ImageAnimator(files,title,id,delay,repeat,rewind);animator.animate();return animator;}
function _animate(anim){document.getElementById(anim.id).src=anim.images[++anim.index].src;if(anim.index==anim.images.length-1){anim.index=-1;if(anim.count<0){return;}else{anim.count--;}}
if(anim.count==0&&(!anim.rewind||anim.index==0)){clearInterval(anim.intervalID);delete anim.intervalID;}}
