//	______________________________________________________________________ VideoStream
function VideoStream( title, caption, url, image ) {
	this.title		= title;
	this.caption	= caption;
	this.url		= url;
	this.image		= image;
}

//	______________________________________________________________________ VideoStreamList
function VideoStreamList( name ) {
	this.name = ( VideoStreamList.arguments.length > 0 ) ? name : ""
	this.array			= new Array();
	this.selectedStream	= -1;
	this.streamType		= "ns";
	this.streamSize		= "28";
	
	this.add			= add;
	this.forward		= forward;
	this.backward		= backward;
	this.changeChannel	= changeChannel;
	this.selectChannel	= selectChannel;
	this.populateList	= populateList;
	this.cacheImages	= cacheImages;
	this.displayInformation = displayInformation;
}

//	______________________________________________________________________ add
function add( stream ) {
	var videoStream;
	
	if ( typeof add.arguments[0] == "string" ) {
	//	if passed stream information in string form (title, caption, url, image)
		var title	= ( add.arguments[0] ) ? add.arguments[0] : "";
		var caption	= ( add.arguments[1] ) ? add.arguments[1] : "";
		var url		= ( add.arguments[2] ) ? add.arguments[2] : "";
		var image	= ( add.arguments[3] ) ? add.arguments[3] : "";
		videoStream = new VideoStream( title, caption, url, image );
	} else {
	//	if passed a VideoStream object
		videoStream = add.arguments[0];
	}
	
	this.array[this.array.length] = videoStream;
	//	add videoStream to end of the list
}

//	______________________________________________________________________ forward
function forward() {
	this.selectedStream++;									//	increment
	if ( this.selectedStream > this.array.length - 1 ) {	//	check for overflow
		this.selectedStream = 0;							//		if true, start at beginning
	}
	
	this.changeChannel();									//	present stream
}

//	______________________________________________________________________ backward
function backward() {
	this.selectedStream--;									//	decrement
	if ( this.selectedStream < 0 ) {						//	check for underflow
		this.selectedStream = this.array.length - 1;		//		if true, start at end
	}
	
	this.changeChannel();									//	present stream
}

//	______________________________________________________________________ changeChannel
function changeChannel( stream ) {
//	parameter is needed for use by the list, not necessarily by the buttons
	this.selectedStream = stream ? parseInt( stream ) : this.selectedStream;
	
	var videoStream = this.array[this.selectedStream];
	
	if ( videoStream.caption ) {						//	if caption isn't blank...
		document.forms[( this.name + 'VideoForm' )].caption.value = videoStream.caption;
	}
	
	if ( videoStream.image ) {							//	if image isn't blank...
		document.images[( this.name + 'VideoImage' )].src = videoStream.image;
	}
}

//	______________________________________________________________________ selectChannel
function selectChannel() {
	var videoStream = this.array[this.selectedStream];
	
	if ( videoStream.url ) {							//	if url isn't blank...
		if ( this.selectedStream != -1 ) {				//	and a stream is selected...
//			alert( videoStream.url + "." + this.streamType + this.streamSize + ".html" );
			vod( videoStream.url + "." + this.streamType + this.streamSize + ".html",
				videoStream.title );
		} else {
			document.forms[( this.name + 'VideoForm' )].caption.value
				= "Please select a stream first";
		}
	}
}

//	______________________________________________________________________ populateList
function populateList() {
	var listMarkup = "\r";
	
	for ( var i = 0; i < this.array.length; i++ ) {
		listMarkup += "<option value=\"" + i + "\">" + this.array[i].title + "</option>\r";
	}
	
	document.writeln( listMarkup );
}

//	______________________________________________________________________ cacheImages
function cacheImages() {
	imageObjects = new Array( this.array.length );
	
	for ( var i = 0; i < this.array.length; i++ ) {
		imageObjects[i]		= new Image( 120, 90 );
		imageObjects[i].src	= this.array[i].image;
	}
}

//	______________________________________________________________________ displayInformation
function displayInformation() {
	document.writeln( "<h3>" + this.name + "</h3>\r<table border=\"0\" cellspacing=\"0\">\r" );
	document.writeln( "\t<tr><th>Field</th><th>Value</th></tr>\r" );
	for ( var i = 0; i < this.array.length; i++ ) {
		var object = this.array[i];
		var bgcolor = ( i % 2 ) ? "#99CCCC" : "#CCCC99";
		document.writeln( "<tr bgcolor=\"#999999\"><th colspan=\"2\">" + i + "</th></tr>" );
		for ( field in object ) {
			document.writeln( "\t<tr bgcolor=\"" + bgcolor + "\" valign=\"top\">" +
					"<td>" + field + "</td><td>" + object[field] + "</td></tr>\r" );
		}
	}
	document.writeln( "</table>\r" );
}
