//Set up the list box, call function VideoThumb to create the actual thumbnails

list.rowHeight = 70;
list.cellRenderer = "VideoThumb";
list.selectable = true;

//create new empty listener object
listListener = {};

//Function to handle what happens when an item in the list is selected
/*
listListener.change = function( evtobj ) {
	var nav = list.dataProvider[list.selectedIndex];
	nc = new NetConnection(); 			//create a connection
	nc.connect( null );					//null connection for progressive download
	ns = new NetStream(nc); 			//create a stream
	video.attachVideo(ns); 				//pipe stream to this video object
	// walk through the chosen item, build and play it	
	var reset = true;
	for ( var i = 0; i < nav.childNodes.length; i++ ) {
		var stream = nav.childNodes[i];
		if ( stream.nodeName == "stream" ) {
			// build path to flv, and play it
			myStreamPath = nav.attributes.url + "/" + stream.attributes.name;
			ns.setBufferTime(10);
			ns.play( myStreamPath);
			reset = false;
		}
	}
}
*/

//Function to handle what happens when an item in the list is selected
listListener.change = function( evtobj ) {
	var nav = list.dataProvider[list.selectedIndex];
	var reset = true;
	for ( var i = 0; i < nav.childNodes.length; i++ ) {
		var stream = nav.childNodes[i];
		if ( stream.nodeName == "stream" ) {
			attachMovie("FLVPlayback", "my_FLVPlybk", 10, {width:320, height:240, x:18, y:49});
			
			//center the FLVPlayback component when FLV is ready to play
			var listenerObject:Object = new Object();
			listenerObject.resize = function(eventObject:Object):Void {
				//center video in playback area
				newx = (460 - my_FLVPlybk.preferredWidth)/2;
				newy = (470 - my_FLVPlybk.preferredHeight)/2;
				my_FLVPlybk._x = newx;
				my_FLVPlybk._y = newy;
			};
			//my_FLVPlybk.addEventListener("resize", listenerObject);    
			listenerObject.ready = function(eventObject:Object):Void {
        		my_FLVPlybk.setSize(250, 350);
			};

			my_FLVPlybk.skin = "SteelExternalAll.swf";
			my_FLVPlybk.clear();
			my_FLVPlybk.contentPath = stream.attributes.url + "/" + stream.attributes.name+".flv";
			//my_FLVPlybk.autoSize = true;
			//trace(my_FLVPlybk.contentPath);
			reset = false;
		}
	}
}

//Add an event listener on the list, when it triggers, run the listListener function to repopulate the list
list.addEventListener("change", listListener);


//Function that loads the XML file, parses it, and builds the list of available video clips
	var xmllist = new XML();  		//setup a variable to hold the XML
	xmllist.ignoreWhite = true;
	xmllist.load( "playlist.xml" ); 	//load the XML file
	//The following gets called when the XML has been loaded
	xmllist.onLoad = function( status )  {
		if ( !status )
			trace( status );
		var entries = this.childNodes[0];
		var playlists = {};
		var nav = [];
		for ( var i = 0; i < entries.childNodes.length; i++ ) {
			var entry = entries.childNodes[i];
			if ( entry.nodeName == "listitem" )
				//builds array of video clip names
				playlists[entry.attributes.name] = entry;
			else if ( entry.nodeName == "menu" ) {
				//builds array of available videos
				for ( var j = 0; j < entry.childNodes.length; j++ )
				nav[j] = playlists[entry.childNodes[j].attributes.name];
			} //end else if
		} //end if

		//sends the array of videos to the listbox UI
		list.dataProvider = nav;
	} //end xmllist.onload


//resizes the video object to the width and height of the clip 
function onVideoResize() {
	if ( video.width != video._width || video.height != video._height ) {
		video._width = video.width;
		video._height = video.height;
		//center video in playback area
		newx = (460 - video._width)/2;
		newy = (470 - video._height)/2;
		video._x = newx;
		video._y = newy;
	}
}
setInterval( onVideoResize, 200 ); //keeps checking video size