


/* %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%  */
/* JAVASCRIPT STREAMING ANIMATION LIBRARY  */
/* %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%  */
/* %%% FLX ALBORATORIES 2004 %%%%%%%%%%%%  */
/* %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%  */
/* %%% UNDER THE TERMS OF GPL %%%%%%%%%%%  */
/* %%% %%%% HTTP://WWW.GPL.ORG %%%%%%%%%%  */
/* %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%  */

/* animation class */
function jsStreamAnimation(docimgname){
	this.docimgname = docimgname
	this.framePos = 0
	this.frames = new Array()
	this.startFrame = 0
	this.endFrame = 0
	this.stepCount = 1
	this.direction = 1
	this.speed = 1.0
	this.tOut = null
	this.loop = 1
	this.playing = 0
	this.setLoop = jsStreamAnimation_setLoop
	this.setFrameStep = jsStreamAnimation_setFrameStep
	this.getSpeed = jsStreamAnimation_getSpeed
	this.setSpeed = jsStreamAnimation_setSpeed
	this.speedUp = jsStreamAnimation_speedUp
	this.speedDown = jsStreamAnimation_speedDown
	this.setRegion = jsStreamAnimation_setRegion
	this.loadFrame = jsStreamAnimation_loadFrame
	this.loadMultiple = jsStreamAnimation_loadMultiple
	this.loadDir = jsStreamAnimation_loadDir
	this.play = jsStreamAnimation_start
	this.start = jsStreamAnimation_start
	this.stop = jsStreamAnimation_stop
	this.onFrameCallback = null
	this.setOnFrameCB = jsStreamAnimation_setOnFrameCB
	// this.step = jsStreamAnimation_step
	// alert(eval('document.'+this.docimgname+'.src'))
}
function jsStreamAnimation_setLoop(boolvar){
	this.loop = boolvar
}
function jsStreamAnimation_setOnFrameCB(func){
	this.onFrameCallback = func
}
function jsStreamAnimation_setFrameStep(numr){
	if(numr>0){
		this.stepCount = numr
	}
}
function jsStreamAnimation_speedUp(){
	if(this.speed>0){
		this.speed = this.speed*2.0
	}
	else{
		this.speed = 1.0
	}	
}
function jsStreamAnimation_speedDown(){
	if(this.speed>0){
		this.speed = this.speed*0.5
	}
	else{
		this.speed = 1.0
	}	
}
function jsStreamAnimation_setSpeed(sp){
	if(sp>0){
		this.speed = sp
	}
}
function jsStreamAnimation_getSpeed(){
	return this.speed
}
function jsStreamAnimation_setRegion(startf,endf){
	if(endf <= startf){
		nstartf = endf
		endf = startf
		startf = nstartf
	}
	if(endf > this.frames.length){
		endf = this.frames.length-1
	}
	if(startf < 0){
		startf = 0
	}
	if(startf < endf && startf>=0 && startf<this.frames.length){
		this.startFrame = startf
		this.endFrame = endf
		this.framePos = startf
		// alert("start:"+this.startFrame+"/"+this.endFrame)
	}
}
function jsStreamAnimation_loadFrame(path,framelen){
	frameobj = new jsStreamAnimation_frame(path,framelen)
	this.frames[this.frames.length] = frameobj
	this.endFrame = this.frames.length-1
}
function jsStreamAnimation_loadMultiple(names,interval){
	for(i=0; i< names.length; i++){
		// alert(names[i])
		this.loadFrame(names[i],interval)
	}
}
function jsStreamAnimation_loadDir(path, suffix, minNum, maxNum, numchars, interval, framestep){
	// alert(framestep)
	// alert(path+","+ suffix+","+ minNum+","+ maxNum+","+ numchars)
	for(i=minNum; i<= maxNum; i+=framestep){
		nam = "0000000"+i
		nam = path + nam.substr(nam.length-numchars,nam.length) + suffix
		this.loadFrame(nam,interval)
	}
}
function jsStreamAnimation_start(){
	this.stop()
	this.playing = 1
	obj = this
	this.tOut = setTimeout('jsStreamAnimation_step(obj)',this.frames[this.framePos].framelen)
}
function jsStreamAnimation_stop(){
	this.playing = 0
	if(this.tOut != null){
	  clearTimeout(this.tOut)
	}
}
function jsStreamAnimation_step(obj){
	if(obj.framePos < obj.frames.length){
		if(obj.frames[obj.framePos].isPreloaded() == true){
			// call callback function
			if(obj.onFrameCallback != null){
				obj.onFrameCallback(obj.framePos)
			}
			// set new img src
			docimg = eval("document." + obj.docimgname + "")
			docimg.src = obj.frames[obj.framePos].img.src
			// increment frame counter
			obj.framePos+=obj.stepCount*obj.direction
			if(obj.direction == 1){
				if(obj.framePos >= obj.endFrame || obj.framePos > obj.frames.length){
					obj.framePos = obj.startFrame
					if(obj.loop == 0){
						obj.stop()
						return null
					}
				}
			}
			else if(obj.direction == -1){
				if(obj.framePos < 0  || obj.framePos > obj.frames.length){
					obj.framePos = obj.endFrame-1
					if(obj.loop == 0){
						obj.stop()
						return null
					}
				}
			}
			// startloading the next document
			obj.frames[obj.framePos].preload()
			obj.tOut = setTimeout('jsStreamAnimation_step(obj)',obj.frames[obj.framePos].framelen*obj.speed)
		}
		else{
			// alert("not loaded: "+obj.frames[obj.framePos].img.src2)
			obj.tOut = setTimeout('jsStreamAnimation_step(obj)',50)
		}
	}
	else{
		obj.framePos = 0
	}
}
/* frame class */
function jsStreamAnimation_frame(path,framelen){
	this.path = path
	this.framelen = framelen
	this.preload = jsStreamAnimation_frame_preload
	this.isPreloaded = jsStreamAnimation_frame_isPreloaded
	this.img = null
}
function jsStreamAnimation_frame_preload(){
	if(this.img == null){
		this.img = new Image()
		this.img.src = this.path
		// alert("load: "+this.img.src)
	}
}
function jsStreamAnimation_frame_isPreloaded(){
	if(this.img != null){
		return this.img.complete
	}
	else{	
		this.preload()
		return false
	}
}






