function Exhibitionist_transitionController(){
	this.transitionStep = 0.5;
	this.exhibitionist;
	this.toImageObject;
	this.fromImageObject;
	this.stillWorking = false;
	this.waitingThreads = 0;
	this.fromImageObject = null;
	this.init = function(exhibitionist){
		this.exhibitionist = exhibitionist;
		this.transitionStep = this.exhibitionist.galleryEffectSpeedStep;
	}
	//handels what transition function to use
	this.changeImage = function(toImageObject){
		this.exhibitionist.trace("Transition Controler: Changing Image");
		if (this.waitingThreads == 0){
			this.waitingThreads++;
			if (this.fromImageObject != toImageObject){
				this.toImageObject = toImageObject;
				switch (this.exhibitionist.optionsArray['effect']){
					case "default":
						this.defaultTransition();
					break;
					case "fadeInOut":
						this.transitionStep = this.exhibitionist.galleryEffectSpeedStep * 2;
						this.fadeInOutTransition();
					break;
					case "crossfade":
						this.crossfadeTransition();
					break;
				}
			}
			this.waitingThreads--;
		}
		return false;
	}
	//the default transition function.
	this.defaultTransition = function(){
		if (this.toImageObject != null){
			this.toImageObject.setOpacity(100);
			this.exhibitionist.bigImageHolder.appendChild(this.toImageObject.holder);
		}
		if (this.fromImageObject != null){
			this.exhibitionist.bigImageHolder.removeChild(this.fromImageObject.holder);		
		}
		this.fromImageObject = this.toImageObject;
		this.stillWorking = false;
		this.onFadeOutExtraTrigger();
		return;
	}
	//the fade in out transition
	this.fadeInOutTransition = function(){
		//if it is the first image we just add it and fade in
		this.waitingThreads++;
		if (this.fromImageObject == null){
			this.toImageObject.setOpacity(0);
			this.toImageObject.setPosition("relative");
			this.exhibitionist.bigImageHolder.appendChild(this.toImageObject.holder);
			this.toImageObject.self = this;
			this.toImageObject.onFadedIn = function(){
				this.self.fromImageObject = this.self.toImageObject;
				this.self.stillWorking = false;
				this.self.waitingThreads--;
			}
			this.toImageObject.fadeIn(this.transitionStep);
		}else{
			this.fromImageObject.self = this;
			this.fromImageObject.onFadedOut = function(){
				if (this.self.toImageObject != null){
					this.self.toImageObject.setOpacity(0);
					this.self.exhibitionist.bigImageHolder.removeChild(this.self.fromImageObject.holder);
					this.self.exhibitionist.bigImageHolder.appendChild(this.self.toImageObject.holder);
					this.self.toImageObject.self = this.self;
					this.self.toImageObject.onFadedIn = function(){
						this.self.fromImageObject = this.self.toImageObject;
						this.self.waitingThreads--;
					}
					this.self.toImageObject.fadeIn(this.self.transitionStep);
				}else{
					this.self.exhibitionist.bigImageHolder.removeChild(this.self.fromImageObject.holder);
					this.self.fromImageObject = this.self.toImageObject;
					this.self.waitingThreads--;
				}
				this.self.onFadeOutExtraTrigger();
			}
			this.fromImageObject.fadeOut(this.transitionStep);
		}
		return;
	}
	// the crossfade transition
	this.crossfadeTransition = function(){
		this.waitingThreads++;
		if (this.toImageObject != null){
			this.waitingThreads++;
			this.exhibitionist.trace("CrossfadeTransition: Adding Image and Fading In");
			this.toImageObject.setOpacity(0);
			this.toImageObject.setPosition("relative");
			this.exhibitionist.bigImageHolder.appendChild(this.toImageObject.holder);
			this.toImageObject.fadeIn(this.transitionStep);
			this.toImageObject.self = this;
			this.toImageObject.onFadedIn = function(){
				this.self.waitingThreads--;
				this.self.exhibitionist.trace("CrossfadeTransition: Fade In Complete");
			}
		}
		
		if (this.fromImageObject != null){
			this.waitingThreads++;
			this.exhibitionist.trace("CrossfadeTransition: Fading out image and Removing");
			this.fromImageObject.fadeOut(this.transitionStep);
			this.fromImageObject.self = this;
			if (this.toImageObject != null){
				this.fromImageObject.setPosition("absolute");
			}
			this.fromImageObject.onFadedOut = function(){
				this.self.exhibitionist.trace("CrossfadeTransition: Fade out complete, Removing");
				this.self.exhibitionist.bigImageHolder.removeChild(this.self.fromImageObject.holder);
				this.self.fromImageObject = this.self.toImageObject;
				this.self.waitingThreads--;
				this.self.onFadeOutExtraTrigger();
			}
		}else{
			this.fromImageObject = this.toImageObject;
		}
		this.waitingThreads--;
		return;
	}
	this.onFadeOutExtraTrigger = function(){
	}
}