/** 
 * Creates a new Playlist object
 */
function Playlist( aSeason )
{

	this.mySeason = aSeason;
	this.myVideoItems = new Array ();	
	this.myDate	= null;

}


Playlist.prototype.sort = function ( signumFunction )
{
	this.myVideoItems.sort( signumFunction );
}


Playlist.prototype.add = function ( aVideoItem )
{
	this.myVideoItems.push( aVideoItem );
} // END of add


/*
 * Player control
 */


Playlist.prototype.load = function()
{
	this.myVideoItems[0].load();
}


Playlist.prototype.play = function()
{
	this.myVideoItems[0].play();
}


/*
 * Accessors
 */


Playlist.prototype.getSeasonKey = function()
{
	return this.mySeason.getKey();
}


Playlist.prototype.restOfTagStartingWith = function()
{
	return null;
}

/** 
 * Returns the date of the playlist by finding the newest video. 
 * @return the date of the playlist.
 */
Playlist.prototype.getDate = function ( )
{
	
	var newestDate = 0;
	
	if (!this.myDate)
	{
		for ( var i in this.myVideoItems )
		{						
			if ( this.myVideoItems[i].getDate() > newestDate )
			{
				newestDate = this.myVideoItems[i].getDate();
				this.myDate = newestDate;
			}
				
		}
		
		return newestDate;
		
	} else
	{
		return this.myDate;
	}
	
} // END of getDate


/**
 * Spits back a video row.
 * @param isSpecialPage if true will include show
 */
Playlist.prototype.getHTML = function ( isShowDescriptive )
{
	
	var html = "";
	var showLink;
	var oneVideo;
	
	html += "<div id=\"seasonHeader-" + this.mySeason.getKey() + "\" class=\"menuSeasonHeader\"><div id=\"season-" + this.mySeason.getKey() + "\" class=\"seasonName\">"+this.mySeason.getName()+"</div>"+this.mySeason.getDescription()+"</div>";
	
	for ( var i in this.myVideoItems )
	{

		oneVideo = this.myVideoItems[i];
		
		html += oneVideo.getHTML( isShowDescriptive );
	
	}
	
	html += "</div><div class=\"horizontalLine\"></div>";

	return html;

}
