////////////////////////////////////////////////////////////////////////
//////
////// Stream Management
//////

var arrayStreams			= new Array;
var areStreamsLoaded		= false;

function Stream( id, groupid, name, description, type, features,
				embedStreamSmall,embedStreamLarge,embedChat, archive,
				activelink, activeflag )
{
	//
	// Object methods
	//
	
	//
	// Object properties
	this.m_id 				= id;
	this.m_groupid 			= groupid;
	this.m_name				= name;
	this.m_description		= description;
	this.m_type				= type;
	this.m_features			= features;
	this.m_embedStreamSmall	= embedStreamSmall;
	this.m_embedStreamLarge	= embedStreamLarge;
	this.m_embedChat		= embedChat;
	this.m_archive			= archive;
	this.m_activelink		= activelink;
	this.m_activeflag		= activeflag;
	
	arrayStreams [ this.m_id ] = this;
}

function findStreamById( id )
{
	for ( var oId in arrayStreams )
	{
		var o = arrayStreams[oId];
		if ( o != null && o.m_id == id )
			return o;
	}
	return null;
}

function OnLoadedStreams( jsonArray )
{
	//
	var oObjects = eval(jsonArray);
	//
	if ( HasErrorProperty( oObjects) )
		return null;
	//
	count = 0;
	//
	//
	for ( var oId in oObjects)
	{
		var oObject = oObjects[oId];
		//alert( oObject.m_id+"/"+oObject.m_embedChat )
		oStream = new Stream(
				oObject.m_id,
				oObject.m_groupid,
				oObject.m_name,
				oObject.m_description,
				oObject.m_type,
				oObject.m_features,
				oObject.m_embedStreamSmall,
				oObject.m_embedStreamLarge,
				oObject.m_embedChat,
				oObject.m_archive,
				oObject.m_activelink,
				oObject.m_activeflag
			);			
		count++;
	}
	areStreamsLoaded = true;
}

function LoadAllStreams()
{
	DAO( DAOAPI_GETALLSTREAMS, "OnLoadedStreams",null);
}

function showStream( streamId, gpsId )
{
	oStream = findStreamById( streamId );
	if ( oStream == null )
	{
		document.getElementById("videodiv").innerHTML = "";
		//document.getElementById("chatdiv").innerHTML  = "";
		document.getElementById("mapdiv").innerHTML = "";	
		document.getElementById("mapcontroldiv").innerHTML = "";
		selectedGPS = null;			
		return;
	}
	//
	document.getElementById("videodiv").innerHTML = oStream.m_embedStreamLarge;	
	//document.getElementById("chatdiv").innerHTML  = oStream.m_embedChat;
	//
	if ( gpsId != 0 )
	{
		//document.getElementById("mapdiv").innerHTML = '<iframe scrolling="no" border=0 id="mapui" width=320 height=325 src="componentmap.php">';			
		//DAO( DAOAPI_GETGPSARCHIVEDATEBYID + gpsId, "OnGPSArchiveDateLoaded", null );
		selectedGPS = gpsId;
		//centerOnTruck( "truck-"+gpsId );
	}
	else
	{
		//document.getElementById("mapcontroldiv").innerHTML = "";			
		//document.getElementById("mapdiv").innerHTML = '';			
	}
}

