/**
 * @author rrobinson
 */

/**
 * The function builds a playlist entry for each video object
 */
function buildMovieList(id)
{
	var playlist = document.getElementById(id);
	
	var details = "Details! Details! Details! There are always details. It is said that '...the devil is in the details...'. What do you think? You need details on a movies to know if it is of any interest. Can you have too much detail? Sure.";
	fandangoPlaylistCount = com.fandango.playlist.videos.length;
	for(var i=0; i < fandangoPlaylistCount; i++){
		var video = com.fandango.playlist.videos[i];
		var N = i + 1;
		
		// -------------------------------------------------------------
		// create header for play list item
		// -------------------------------------------------------------
		/*
		 * <div class="header rel=N>
		 * 		<h4>video title</h4>
		 * 		<div class="subheader">
		 * 			<a href="javascript:playVideo();">Trailer (00:00)</a>
		 * 			- Now Playing
		 * 		</div>
		 * </div>
		 */
		var div = document.createElement('div');
		div.setAttribute('class', 'header');
		div.setAttribute('rel', N);
		
		var h4 = document.createElement('h4');
		var textnode = document.createTextNode(video.title);
		h4.appendChild(textnode);
		div.appendChild(h4);
		
		// create subheader
		var subdiv = document.createElement('div');
		subdiv.setAttribute('class', 'subheader');

		var anchor = document.createElement('a');
		anchor.setAttribute('href', "javascript:playVideo(" + i + ");");
		textnode = document.createTextNode(video.contenttype + " (" + video.runtime + ")");
		anchor.appendChild(textnode);
		subdiv.appendChild(anchor);
		
		textnode = document.createTextNode(" - Now Playing");
		subdiv.appendChild(textnode);
		
		div.appendChild(subdiv);

		// add to playlist
		playlist.appendChild(div);

		// create actions
		div = document.createElement('div');
		div.setAttribute('class', "list_item");
		div.setAttribute('id', N);
		
		subdiv = document.createElement('div');
		subdiv.setAttribute('class', "actions");
		
		anchor = document.createElement('a');
		anchor.setAttribute('href', "javascript:void(0);");
		anchor.setAttribute('class', "action");
		textnode = document.createTextNode("Photos");
		anchor.appendChild(textnode);
		subdiv.appendChild(anchor);
		
		anchor = document.createElement('a');
		anchor.setAttribute('href', "#");
		anchor.setAttribute('class', "add");
		textnode = document.createTextNode("Video Details");
		anchor.appendChild(textnode);
		subdiv.appendChild(anchor);
		
		div.appendChild(subdiv);

		// details
		subdiv = document.createElement('div');
		subdiv.setAttribute('class', "details");
		//subdiv.setAttribute('style', "display: none;");
		subdiv.style.display = "none";
		
		var paragraph = document.createElement('p');
		paragraph.appendChild(document.createTextNode(details));
		subdiv.appendChild(paragraph);
		
		div.appendChild(subdiv);
		
		// rating
		/*
			<div class="rating">
				<h5>Rate This Video</h5> 
				<div class="temp"></div>
			</div>
		*/
		subdiv = document.createElement('div');
		subdiv.setAttribute('class', "rating");
		var h5 = document.createElement('h5');
		textnode = document.createTextNode('Rate This Video');
		h5.appendChild(textnode);
		subdiv.appendChild(h5);
		
		var subsubdiv = document.createElement('div');
		subsubdiv.setAttribute('class', "temp");
		subdiv.appendChild(subsubdiv);
		
		div.appendChild(subdiv);
		
		// add to playlist
		playlist.appendChild(div);
	}
	
	var footer = document.createElement('div');
	footer.setAttribute('id', "playlist_footer");
	var footertext = document.createTextNode("There are no more videos in your playlist. Select channels below for more content.");
	footer.appendChild(footertext);
	playlist.appendChild(footer);
}