var SwapImageFromMemory = function(pngAnimationObject){
	this.pngAnimation = pngAnimationObject;
	this.currentImageItem = null;
	this.previousImageItem = null;
	this.currentImageNumber = 0;
	this.minSpeed = 200;
	this.delayTime = this.pngAnimation.delayTime;
	this.start = function(){
		this.currentImageItem = this.pngAnimation.images[this.currentImageNumber];
		this.previousImageItem = this.currentImageItem;
		this.pngAnimation.container.appendChild(this.currentImageItem);
		this.loop();
	}
	this.checkCutout = function(){
		if (this.pngAnimation.cutout != null){
			//clearDebug();
			this.delayTime = this.pngAnimation.cutout.scrollAnimator.progress * this.minSpeed;
			//debug(this.delayTime);
		}
	}
	this.loop = function(){
		this.checkCutout();
		var object = this;
		setTimeout(function(){
			if ((object.delayTime < object.minSpeed) && (object.delayTime > 10)){
				object.doFrame();
			}
			object.loop();
		},this.delayTime / 6);
	}
	this.doFrame = function(){
		this.currentImageNumber++;
		if (this.currentImageNumber >= this.pngAnimation.images.length){
			this.currentImageNumber = 0;
		}
		this.currentImageItem = this.pngAnimation.images[this.currentImageNumber];
		this.pngAnimation.container.appendChild(this.currentImageItem);
		this.pngAnimation.container.removeChild(this.previousImageItem);
		this.previousImageItem = this.currentImageItem;
	}
}

var SwapImageWithCSSVisibility = function(pngAnimationObject){
	this.pngAnimation = pngAnimationObject;
	this.currentImageItem = null;
	this.previousImageItem = null;
	this.currentImageNumber = 0;
	this.start = function(){
		for (imageNum in this.pngAnimation.images){
			var image = this.pngAnimation.images[imageNum];
			image.style.visibility = "hidden";
			this.pngAnimation.container.appendChild(image);
		}
		this.currentImageItem = this.pngAnimation.images[this.currentImageNumber];
		this.currentImageItem.style.visibility = "visible";
		this.previousImageItem = this.currentImageItem;
		this.loop();
	}
	this.loop = function(){
		var object = this;
		setTimeout(function(){
			object.doFrame();
			object.loop();
		},this.pngAnimation.delayTime);
	}
	this.doFrame = function(){
		this.currentImageNumber++;
		if (this.currentImageNumber >= this.pngAnimation.images.length){
			this.currentImageNumber = 0;
		}
		//console.log(this.currentImageNumber);
		this.currentImageItem = this.pngAnimation.images[this.currentImageNumber];
		this.currentImageItem.style.visibility = "visible";
		this.previousImageItem.style.visibility = "hidden";
		this.previousImageItem = this.currentImageItem;
		//alert(this.currentImageItem.src);
	}
	
}

var SwapImageWithCSSDisplay = function(pngAnimationObject){
	this.pngAnimation = pngAnimationObject;
	this.currentImageItem = null;
	this.previousImageItem = null;
	this.currentImageNumber = 0;
	this.start = function(){
		for (imageNum in this.pngAnimation.images){
			var image = this.pngAnimation.images[imageNum];
			image.style.display = "none";
			this.pngAnimation.container.appendChild(image);
		}
		this.currentImageItem = this.pngAnimation.images[this.currentImageNumber];
		this.currentImageItem.style.display = "block";
		this.previousImageItem = this.currentImageItem;
		this.loop();
	}
	this.loop = function(){
		var object = this;
		setTimeout(function(){
			object.doFrame();
			object.loop();
		},this.pngAnimation.delayTime);
	}
	this.doFrame = function(){
		this.currentImageNumber++;
		if (this.currentImageNumber >= this.pngAnimation.images.length){
			this.currentImageNumber = 0;
		}
		this.currentImageItem = this.pngAnimation.images[this.currentImageNumber];
		this.currentImageItem.style.display = "block";
		this.previousImageItem.style.display = "none";
		this.previousImageItem = this.currentImageItem;
	}
	
}


var SwapImageWithTop = function(pngAnimationObject){
	this.pngAnimation = pngAnimationObject;
	this.currentImageTop = 0;
	this.imageCount = 0;
	this.start = function(){
		this.pngAnimation.image.style.position = "relative";
		this.pngAnimation.container.appendChild(this.pngAnimation.image);
		this.loop();
	}
	this.loop = function(){
		var object = this;
		setTimeout(function(){
			object.doFrame();
			object.loop();
		},this.pngAnimation.delayTime);
	}
	this.doFrame = function(){
		this.currentImageTop -= this.pngAnimation.height;
		if (this.currentImageTop <= -this.pngAnimation.image.offsetHeight){
			this.currentImageTop = 0;
		}
		//alert(this.currentImageTop);
		this.pngAnimation.image.style.top = this.currentImageTop + "px";
		//console.log(this.pngAnimation.image.style.top);
	}
	
}

