
function VRS()
{
	this.ViewUrls = new Array();

	this.Add = _VRS_Add;

	this.Count = 0;
	this.Objname = null;
	this.Loop = 0;
	this.Loop_backup;

	this.timePtr = null;
		
	this.changeCallFunc = null;

	this.Play = _VRS_Play;
	this.Stop = _VRS_Stop;
	this.onStop = _VRS_onStop;
	this.Init = _VRS_Init;
}

function _VRS_Add ( url )
{
	this.ViewUrls [ this.ViewUrls.length ] = url;
}

function _VRS_Init ( objname, loopn, changeCallFunc )
{
	if ( !loopn ) loopn = 1;
	this.Count = 0;
	this.Loop = loopn;
	this.Objname = objname;
	
	if ( changeCallFunc )
		this.changeCallFunc = changeCallFunc;

	this.Loop_backup = loopn;
}

function _VRS_Stop()
{
	var Obj = eval(this.Objname);

	if ( this.relayActiveno )
	{
		this.Loop = 0;
		Obj.Stop();
	}
	
	if ( this.timePtr )
	{
		clearTimeout ( this.timePtr );
	}
}

function _VRS_onStop()
{
	var Obj = eval(this.Objname);
	var PlayVRS=0;

	this.Count++;

	if ( this.Loop )
	{
		if ( this.Count < this.ViewUrls.length )
		{
			PlayVRS = 1;
		}
		else
		{
			if ( this.Loop != -1 ) 
				this.Loop--;

			this.Count=0;

			if ( this.Loop )
				PlayVRS = 1;
		}
	}
	else this.Stop();

	if ( PlayVRS )
	{
		Obj.src = this.ViewUrls[ this.Count ];
		Obj.FileName = this.ViewUrls[ this.Count ];
		if ( this.changeCallFunc != null )
			eval ( this.changeCallFunc ) (this.Count+1);
		Obj.Play();
	}
}

function _VRS_Play()
{
	var Obj = eval(this.Objname);
	this.Loop = this.Loop_backup;
	this.Count = 0;

	if ( Obj.PlayState != 2 && Obj.readyState == 'complete' )
	{
		Obj.src = this.ViewUrls[ this.Count ];
		Obj.FileName = this.ViewUrls[ this.Count ];
		Obj.Play();	
	}

	relayActive(this.relayActiveno);
}



var RelayActiveObj = new Array();

function init_relayActive ( obj )
{
	var objvalue = obj.valueOf();

	RelayActiveObj [ RelayActiveObj.length ]  = objvalue;
	obj.relayActiveno = RelayActiveObj.length-1;
}

function relayActive ( stack )
{
	if ( stack == null ) stack = 0;
	var raObj = eval(RelayActiveObj[stack]);
	var Obj = eval(raObj.Objname);

	if ( Obj.readyState == 'complete' )
	{
		if ( Obj.PlayState == 0 )
			raObj.onStop();
	}
	
	if ( raObj.Count <= raObj.ViewUrls.length-1 && raObj.Loop )
	{
		//raObj.timePtr = setTimeout ( 'relayActive('+stack+')', 1000 );
	}
}
