
function Action(acts) {

	this.action = new Array();
	this.idx = -1;

	var self = this;
	for (var i = 0; i < acts.length; i++) {
		if (acts[i].setActionHandler) {
			acts[i].setActionHandler(function() {
				self.nextAction();
			});
		}
	}

	this.isDoing = false;
}

Action.prototype.add = function(func, delay) {

	this.idx++;
	this.action[this.idx] = new Object();
	this.action[this.idx].func = func;
	this.action[this.idx].delay = delay;
}

Action.prototype.start = function() {

	if (this.idx < 0)
		return;

	this.isDoing = true;
	this.idx = 0;

//alert('action.start()');
	this.doAction(this.idx++);
}

Action.prototype.endAction = function() {

	this.isDoing = false;
}

Action.prototype.nextAction = function() {

//alert('action.nextAction()');
	if (this.idx < 0)
		return;

	if (this.idx >= this.action.length) {
		this.isDoing = false;
		return;
	}

	this.doAction(this.idx++);
}

Action.prototype.doAction = function(idx) {

//alert('action.doAction()');
	if (this.action[idx].delay) {
		var self = this;
		setTimeout(function() {self.action[idx].func();}, this.action[idx].delay);
	}
	else {
		this.action[idx].func();
	}
}


