﻿



var Devign={};
// Devign.Sequence class
Devign.Sequence=function () {
	// private fields
	// a list of functions
	this.list=[];
	this.index=-1;
	// /private fields

	// public fields
	this.Finished=false;
	// /public fields
};

// public methods
Devign.Sequence.prototype={
	// adds a new function
	Add:function (sequenceFunction) {
		this.list.push(sequenceFunction);
	},
	// starts the sequence from the first function
	// fires 'OnStart' if exists
	Start:function () {
		this.Abort();
		this.Next();
		if (typeof(this.OnStart)=="function") this.OnStart(); 
	},
	// ends the sequence
	// fires 'OnEnd' if exists
	End:function () {
		if (typeof(this.OnEnd)=="function") this.OnEnd();
		this.Finished=true;
	},
	// proceeds the sequence
	// if the sequence has finished calls 'End'
	Next:function () {
		this.index++;

		if (this.index==this.list.length) return this.End();

		var tf=this.list[this.index];

		// calls the function with the sequence as an argument
		tf(this);
	},
	// aborts the sequence by setting the index to 'not started'
	Abort:function () {
		this.index=-1;
	}
};
// /public methods
// /Devign.Sequence class
