


function exsAnimation(config) {
	this.config=config;
	this.currentstep=0;
	this.waitingfor=0;
	this.defaultduration=500;
	this.run = function() {
		this.step();
	};
	this.step = function() {
		if(this.config.length>this.currentstep) {
			var delayed=false;
			var me=this;
			if(this.config[this.currentstep].delay != null) {
				if(this.config[this.currentstep].delay>0) {
					delayed=true;
					var timeoutID = this.delaydone.delay((this.config[this.currentstep].delay),this);
				}
			}
			if(!delayed) {
				if(this.config[this.currentstep].tiles != null) {
					var duration=this.defaultduration;
					if(this.config[this.currentstep].duration != null) duration=this.config[this.currentstep].duration;
					for(var x=0;x<this.config[this.currentstep].tiles.length;x++) {
						$(this.config[this.currentstep].tiles[x]).setStyle('display','block');
						$(this.config[this.currentstep].tiles[x]).set('opacity',0.0);
						$(this.config[this.currentstep].tiles[x]).set('tween',{ duration: duration, onComplete: function() { me.tweendone(); } });
						$(this.config[this.currentstep].tiles[x]).tween('opacity',0.0,1.0);
						
						this.waitingfor++;
	
					}
				}
				if(this.config[this.currentstep].redirecturl != null) {
					document.location=this.config[this.currentstep].redirecturl;
					//alert(this.config[this.currentstep].redirecturl);
				}
			}
		}
	};
	
	this.nextstep = function() {
		this.currentstep++;
		this.step();
		
	};
	
	this.tweendone = function(e) {
		//alert('one done ' + this.waitingfor);
		this.waitingfor--;
		if(this.waitingfor<=0) {
			this.waitingfor=0;	
			this.nextstep();
		}
	};
	
	this.delaydone = function(e) {
		if(this.config[this.currentstep].delay != null) {
			if(this.config[this.currentstep].delay>0) {
				this.config[this.currentstep].delay=0;
			}
		}
		this.step();
	};
}

