
class VideoThumb extends mx.core.UIComponent
{
	static var symbolName = "VideoThumb";
	var label : Object;		// the new text label we'll use
	var listOwner : Object; // reference to the tree - supplied by the tree
	var thumb;
	var nc;					// NetConnection
	var ns;					// NetStream
	var streamurl;
	
	function VideoThumb()
	{
		// nothing needed - we're extending v2;
	}

	function init()
	{
		// nothing needed - we don't have any instance variables to initialize
	}

	function createChildren(Void) : Void
	{
		// attachMovie (linkageID, new name, depth)
		var v = this.attachMovie( "VideoHolder", "thumb", 0 );
		v._width = 68;
		v._height = 51;
		v.styleName = listOwner;


		var c = createLabel("label", 1);
		
		c.styleName = listOwner;
		c.selectable = false;
		c.wordWrap = true;
		c.multiline = true;
		//c.border = true;
	
	}

	// pass all sizing from the tree to the cell
	function size(Void) : Void
	{
		label.setSize(this.getPreferredWidth(),label.getPreferredHeight());
		label._x = thumb._width + 10;
		label._y = thumb._height/2 - label._height/2;
	}

	// str is the suggested string to render from the tree (based on the node)
	// node is the entire XMLNode for the row
	// sel is the selected state (not usually used)
	function setValue(str : String, item, sel)
	{
		_visible = item != undefined;
		if ( !_visible )
			return;
		
		label.setValue( item.attributes.name );
		//trace(item.attributes.name);
		// Thumbnail is picked up as the first frame of the playlist
		var url = item.attributes.url;
		var stream = item.attributes.thumb;
		var start = item.attributes.thumbpos;
				
				//grab jpg thumbnail instead of initiating stream as shown commented out above.
		var newClip = this.createEmptyMovieClip("thumbie",this.getNextHighestDepth());
		newClip.loadMovie("thumbs/"+stream);
		
		// If explicit thumb is not specified use the
		// start frame of the first stream
		if ( stream == undefined ) {
			stream = item.childNodes[0].attributes.name;
			start = item.childNodes[0].attributes.start;
		}
		
		// Give up if we still don't have valid thumb info
		if ( stream == undefined )
			return;

		// Render the thumbnail only if necessary
		if ( streamurl == url + "/" + stream )
			return;
		
		streamurl = url + "/" + stream;
		//trace( streamurl );
		trace( stream );
		
		//nc = new NetConnection();
//nc.onStatus = function( info ) { trace( info.code ); }
		//nc.connect( null );
		
		//ns = new NetStream(nc);
		//ns.onStatus = function(info) {
			//if ( info.code == "NetStream.Play.Stop" ) {
				//nc = null;
				//ns = null;
			//}
		//}
		//ns.connect();
		//ns.play( stream, start, 0 );
		//ns.play( streamurl );
		//ns.seek(2);
		//ns.pause();
		

	}

	// ensures the cell is centered vertically properly - luckily, the label also implements this method.
	function getPreferredHeight()
	{
		return 60;
	}

	function getPreferredWidth()
	{
		//return label.getPreferredWidth();
		return 120;
	}
}