function Player() {

	this.play_list = Array();
	
	this.push = function(c) {
		this.play_list.push(c);
	}
	
	this.play = function() {
	
		//alert('this.play_list: ' + this.play_list[0]);
	
		if (this.play_list.length) {
			eval(this.play_list.shift());
		}
	
	}
	this.clear = function() {
		this.play_list = Array();
	}
}


var mover_counter = 0;
var fader_counter = 0; 

function Mover(div,player,endX,endY,duration) {

	this.div = div;
	this.player = player;
	
	this.startX = 0;;
	this.startY = 0;;
	this.endX = endX;
	this.endY = endY;

	
	this.duration = duration;
	this.timer;
	mover_counter++;
	this.obj = "Mover" + mover_counter;
	eval(this.obj + "=this");
	
	this.move = function () {
	
		//alert('this.div.style.left: ' + this.div.style.left);
		this.startX = parseInt(this.div.style.left);
		this.startY = parseInt(this.div.style.top);
		

	
		var clock = new Date();
		this.startTime = clock.getTime();
		
		this._move();
	}
	
	this._move = function () {
	
		var clock = new Date();
		var now = clock.getTime();
		
		if (now<(this.startTime+this.duration)) {
			var prop = Math.sin(Math.PI*0.5*((now - this.startTime)/this.duration));
			var dX = ((this.endX-this.startX)*prop) + this.startX;
			var dY = ((this.endY-this.startY)*prop) + this.startY;
			this.div.style.left = dX + 'px';
			this.div.style.top = dY + 'px';

			this.timer = window.setTimeout(this.obj+'._move();',30);
			//this.timer = window.setTimeout(function() { obj._move(); },30);

		} else {

			this.div.style.left = this.endX + 'px';
			this.div.style.top = this.endY + 'px';

			window.clearTimeout(this.timer);
			this.player.play();

		}

	}

}


function Fader(div,player,direction,duration) {

	this.div = div;
	this.player = player;
	
	this.direction = direction;
	
	if ( this.direction=='in' ) {
		this.startO = 0;
		this.endO = 100;
	} else {
		this.startO = 100;
		this.endO = 0;
	
	}
	
	//this.startX = 0;;
	//this.startY = 0;;
	//this.endX = endX;
	//this.endY = endY;

	
	this.duration = duration;
	this.timer;
	fader_counter++;
	this.obj = "Fader" + fader_counter;
	eval(this.obj + "=this");
	
	this.fade = function () {

	if ( !isIE() ) {

		if ( this.direction=='in' ) {

			this.player.play();
				this.div.style.visibility='visible';
				
	//} else { this.div.style.visibility='hidden'
		return 0;
		}
		
		if ( this.direction=='out' ) {

			this.player.play();
				this.div.style.visibility='hidden';
				
	//} else { this.div.style.visibility='hidden'
		return 0;
		}
	}

		//alert('this.div.style.left: ' + this.div.style.left);
		//this.startX = parseInt(this.div.style.left);
		//this.startY = parseInt(this.div.style.top);
		
		if ( this.div.style.filter.indexOf('alpha',0)==-1 ) {
			if ( this.direction=='in' ) {
				this.div.style.filter += 'alpha(opacity=0)';
				//this.div.style.visibility='visible';
			} else {
				this.div.style.filter += 'alpha(opacity=100)';
			}
		}
	
		var clock = new Date();
		this.startTime = clock.getTime();
		
		this._fade();
	}
	
	this._fade = function () {
	
		var clock = new Date();
		var now = clock.getTime();
		
		if (now<(this.startTime+this.duration)) {
			var prop = Math.sin(Math.PI*0.5*((now - this.startTime)/this.duration));
			var dO = ((this.endO-this.startO)*prop) + this.startO;
			//var dX = ((this.endX-this.startX)*prop) + this.startX;
			//var dY = ((this.endY-this.startY)*prop) + this.startY;
			//this.div.style.left = dX + 'px';
			//this.div.style.top = dY + 'px';
			this.div.filters.alpha.opacity = dO;

			this.timer = window.setTimeout(this.obj+'._fade();',30);
		} else {

			this.div.filters.alpha.opacity = this.endO;
			//this.div.style.visibility='hidden';

			//this.div.style.left = this.endX + 'px';
			//this.div.style.top = this.endY + 'px';

			window.clearTimeout(this.timer);
			this.player.play();

		}

	}

}	

