//<!--
//*****************************************************************************************************
// 	VSView1: A library of sample view object for displaying AOL video search results on a web page.
// 	Copyright (c) 2006,  AOL LLC.
// 	All rights reserved.
//*****************************************************************************************************

// Function VideoPanel1() is a view object for displaying a set of video search results in a grid view, list view, detail view or full view.
var VideoPanel1 = function(containerID) {  

	// PRIVATE ATTRIBUTES:
	var view = 2;  			// The integer for the view to draw: 0 == grid, 1 == list, and 2 == detail (default).
	var container = document.getElementById(containerID);
 
	// PUBLIC METHODS:
	// Function getVideoSetGridHTML() takes two arguments, the VideoSet data object returned by the AJAX API, and the name of the AJAX 
	// method most recently invoked by the AOLVideoSearchAPI.  This function returns the HTML table that will display a grid view of each 
	// Video in the VideoSet.
	this.detail_box= function( VideoSet, methodName, previousQuery){
		$('video_detail').style.display='block';		
		var theVideo = VideoSet.Video[0];
		var box_html='<table width="100%"  cellpadding="0"  cellspacing="0" id="detail_table">';
//ads
 box_html +='<tr><td width="10%" id="dtitle">Advertisment:</td></tr><tr><td  class="vd_style"><div align="center"><iframe src="ads_300x250.html" width="300px" height="250px" frameborder="0" marginwidth="0" marginheight="0" scrolling="no"></iframe></div></td></tr>'

//video info
		
	 if ("videoPlayerEmbedTag" in theVideo) { 
        box_html +='<tr><td width="10%" id="dtitle">Share this Video:</td></tr><tr>';
		 
		box_html +='<td id="vd_channel" class="vd_style"><a target="_blank" href="http://del.icio.us/post?url=' + home_url +'index.php?play=id:'+theVideo.id+'&title=' +VSUTIL.escapeHTML(theVideo.title) +'"><img border="0" src="' + home_url  +'images/delicious.png" title="Add ' +VSUTIL.escapeHTML(theVideo.title) +' to del.icio.us" width="18" height="18" hspace="2"></a><a target="_blank" href="http://digg.com/submit?phase=2&url=' + home_url +'index.php?play=id:'+theVideo.id+'&title=' +VSUTIL.escapeHTML(VSUTIL.truncateString(theVideo.title,75)) +'&bodytext='+ VSUTIL.escapeHTML(VSUTIL.truncateString(theVideo.description,250))+'&topic=videos_animation"><img border="0" src="' + home_url  +'images/digg.png" title="Submit ' +VSUTIL.escapeHTML(theVideo.title) +' to Digg" width="18" height="18" hspace="2"></a><a target="_blank" href="http://blinklist.com/index.php?Action=Blink/addblink.php&url=' + home_url +'index.php?play=id:'+theVideo.id+'&Title=' +VSUTIL.escapeHTML(theVideo.title) +'"><img border="0" src="' + home_url +'images/blinklist.png" title="Add ' +VSUTIL.escapeHTML(theVideo.title) +' to Blink" width="18" height="18" hspace="2"></a><a target="_blank" href="http://technorati.com/faves/?add=' + home_url +'index.php?play=id:'+theVideo.id + '"><img border="0" src="' + home_url +'images/technorati.png" title="Add ' +VSUTIL.escapeHTML(theVideo.title) +' to TechnoArti " width="18" height="18" hspace="2"></a><a href="http://furl.net/storeIt.jsp?t=' +VSUTIL.escapeHTML(theVideo.title) +'&u=' + home_url +'index.php?play=id:'+theVideo.id + '"><img border="0" src="' + home_url +'images/furl.png" title="Add to Furl" width="18" height="18" hspace="2"></a><a href="http://reddit.com/submit?url=' + home_url +'index.php?play=id:'+theVideo.id + '&title=' +VSUTIL.escapeHTML(theVideo.title) +'"><img border="0" src="' + home_url +'images/reddit.png" title="Add ' +VSUTIL.escapeHTML(theVideo.title) +' to Reddit" width="18" height="18" hspace="2"></a><a href="http://www.stumbleupon.com/submit?url=' + home_url +'index.php?play=id:'+theVideo.id + '&title=' +VSUTIL.escapeHTML(theVideo.title) +'"><img border="0" src="' + home_url +'images/stumbleupon.png" title="Add ' +VSUTIL.escapeHTML(theVideo.title) +' to Stumble Upon" width="18" height="18" hspace="2"></a><a href="http://www.google.com/bookmarks/mark?op=edit&output=popup&bkmk=' + home_url +'index.php?play=id:'+theVideo.id + '&title=' +VSUTIL.escapeHTML(theVideo.title) +'"><img border="0" src="' + home_url +'images/google.png" title="Add ' +VSUTIL.escapeHTML(theVideo.title) +' to Google Bookmark" width="18" height="18" hspace="2"></a><a href="http://www.facebook.com/share.php?u=' + home_url +'index.php?play=id:'+theVideo.id + '"><img border="0" src="' + home_url +'images/facebook.png" title="Add ' +VSUTIL.escapeHTML(theVideo.title) +' to Facebook" width="18" height="18" hspace="2"></a><a href="http://twitter.com/home?status='+ home_url +'index.php?play=id:'+theVideo.id +' ' +VSUTIL.escapeHTML(theVideo.title) +'"<img border="0" src="' + home_url +'images/twitter.png" title="Add ' +VSUTIL.escapeHTML(theVideo.title) +' to Twitter" width="18" height="18" hspace="2"></a><br/><b>Permalink:</b><br><input onClick="javascript:this.focus();this.select();" name="aplink" type="text" id="embed" size="40" value=\''+ home_url + 'index.php?play=id:'+theVideo.id+'\' /><br/><b>Embede Code:</b><br><textarea onClick="javascript:this.focus();this.select();" name="embed" cols="30" rows="3">'+theVideo.videoPlayerEmbedTag+'</textarea><br/>';	
}

		 box_html +='<tr><td width="10%" id="dtitle">Advertisment:</td></tr><tr><td  class="vd_style"><div align="center"><iframe src="ads_300x250_btm.html" width="300px" height="250px" frameborder="0" marginwidth="0" marginheight="0" scrolling="no"></iframe></div></td></tr>';
		box_html +='</span></td></tr>';

		box_html +='</table>';
		$('video_detail').innerHTML=box_html;
	}
	this.getVideoSetGridHTML = function(VideoSet, methodName) {
		$('result').innerHTML ='';
		show_blocks();
		var minCellWidth = 130;
		var cellsPerRow = Math.floor(container.offsetWidth/minCellWidth);
		var rows = Math.ceil(VideoSet.totalResultsReturned/cellsPerRow);
		var theHTML = '';
		var ran_unrounded=Math.random()*999999999999999;
		var ranNum=Math.round(ran_unrounded); 

theHTML += '<div align="center"><iframe src="ads_468x60.html" width="468px" height="60px" frameborder="0" marginwidth="0" marginheight="0" scrolling="no"></iframe></div>';
		theHTML += '<table style="width: 600px; margin: 0 0 0 0; border: 0px; border-style: none; border-collapse: collapse; vertical-align: top;">';
		for (var j=0; j < rows; j++) {
			theHTML += '<tr>';
			for (var k=0; k < cellsPerRow; k++) {
				var i = (j * cellsPerRow) + k; 
				theHTML += '<td align="left" valign="top" style="padding: 12px 4px 12px 4px;">';
				if (i >= VideoSet.Video.length) { theHTML += '&nbsp;'; }
				else {
					var theVideo = VideoSet.Video[i];
				
				
				if (theVideo) {
						theHTML += '<div style="width: '+minCellWidth+'px;"><div >';
			if ("videoPlayerEmbedTag" in theVideo) {  	
				theHTML += '<a href="javascript:getVideos(\'id:'+theVideo.id+'\'); void(0);"><img src="'+theVideo.thumbnailUrl+'" width="120" height="90"  class="thumbnail" alt="Play '+VSUTIL.escapeHTML(VSUTIL.truncateString(theVideo.title, 40))+'"/></a></div>';
				
				theHTML += '<div class="title2"><a style="text-decoration:none" href="javascript:getVideos(\'id:'+theVideo.id+'\'); void(0);">'+VSUTIL.escapeHTML(VSUTIL.truncateString(theVideo.title, 40))+'</a></div>';
				
				}else{
				theHTML += '<a href="javascript:playVideo(\''+theVideo.videoUrl+'\','+theVideo.id+'); void(0);"><img src="'+theVideo.thumbnailUrl+'" width="120" height="90" class="thumbnail" alt="Play '+VSUTIL.escapeHTML(VSUTIL.truncateString(theVideo.title, 40))+'"/></a></div>';		
				theHTML += '<div class="title2"><a style="text-decoration:none" href="javascript:playVideo(\''+theVideo.videoUrl+'\','+theVideo.id+'); void(0);">'+VSUTIL.escapeHTML(VSUTIL.truncateString(theVideo.title, 40))+'</a></div>';
				}	
						
						if (("editorsPick" in theVideo) && (parseInt(theVideo.editorsPick) == 1)) { theHTML += '<div class="callout">FEATURED</div>'; }
						
						if ("runtime" in theVideo) { theHTML += '<div class="vdesc_g"><nobr>'+VSUTIL.getRuntimeString(theVideo.runtime)+'</nobr></div>'; }
						
						if ("channel" in theVideo) { theHTML += '<div class="vdesc_g"><nobr><span class="label">From:</span> <a href="javascript:getVideos(\'channel:&quot;'+VSUTIL.escapeHTMLString(theVideo.channel)+'&quot;\'); void(0);">'+VSUTIL.escapeHTML(VSUTIL.truncateString(theVideo.channel, 15))+'</a></nobr></div>'; }
						if ("viewCount" in theVideo) { theHTML += '<div class="vdesc_g"><nobr><span class="label">Views:</span> '+theVideo.viewCount+'</nobr></div>'; }
theHTML += '';								
						
						theHTML += '</div>';
					}
				}
				theHTML += '</td>';
			}
			theHTML += '</tr>';
		}
		theHTML += '</table>';
		return(theHTML);
	}

	// Function getVideoSetListHTML() takes two arguments, the VideoSet data object returned by the AJAX API, and the name of the AJAX method 
	// most recently invoked by the AOLVideoSearchAPI.  This funciton returns the HTML table that will display a list view of each Video in 
	// the VideoSet.
	this.getVideoSetListHTML = function(VideoSet, methodName) {
		$('result').innerHTML ='';
		show_blocks();
		
		var theHTML = '';
var ran_unrounded=Math.random()*999999999999999;
		var ranNum=Math.round(ran_unrounded); 
theHTML += '<div align="center"><iframe src="ads_468x60.html" width="468px" height="60px" frameborder="0" marginwidth="0" marginheight="0" scrolling="no"></iframe></div>';
		theHTML += '<table style="width: 600px; margin: 0 0 0 0; border: 0px; border-style: none; border-collapse: collapse; vertical-align: top;" border="0" cellpadding="4">';
		for (var i=0; i < VideoSet.totalResultsReturned; i++) {
			var theVideo = VideoSet.Video[i];
			if (theVideo) {
				theHTML += '<tr class="'+(i%2==1?'evenVideo':'oddVideo')+'" >';
				if ("videoPlayerEmbedTag" in theVideo) {  	
				theHTML += '<td class="title2" width="200"><nobr><a href="javascript:getVideos(\'id:'+theVideo.id+'\'); void(0);">'+VSUTIL.escapeHTML(VSUTIL.truncateString(theVideo.title, 30))+'</a></nobr></td>';
				
				}else{
				
				theHTML += '<td class="title2" width="200"><nobr><a href="javascript:playVideo(\''+theVideo.videoUrl+'\','+theVideo.id+'); void(0);">'+VSUTIL.escapeHTML(VSUTIL.truncateString(theVideo.title, 30))+'</a></nobr></td>';				
				}		

				if (("editorsPick" in theVideo) && (parseInt(theVideo.editorsPick) == 1)) { theHTML += '<td class="callout"><nobr>FEATURED</nobr></td>'; }
				else { theHTML += '<td>&nbsp;</td>'; }
				if ("category" in theVideo) { 
					theHTML += '<td class="title3"><nobr>'+VSUTIL.escapeHTML(theVideo.category)+' ';
					if ("rating" in theVideo) { theHTML += '('+VSUTIL.escapeHTML(theVideo.rating)+')'; }		
					theHTML += '</nobr></td>';
				}
				else { theHTML += '<td>&nbsp;</td>'; }
				if ("runtime" in theVideo) { theHTML += '<td class="title3"><nobr>'+VSUTIL.getRuntimeString(theVideo.runtime)+'</nobr></td>'; }
				else { theHTML += '<td>&nbsp;</td>'; }
				if ("dateFound" in theVideo) {
					// theHTML += '<td class="title3"><nobr>'+theVideo.dateFound+'</nobr></td>'; 
				}
				else { theHTML += '<td>&nbsp;</td>'; }
				if ("buyUrl" in theVideo) { theHTML += '<td class="title3"><nobr><a href="'+VSUTIL.escapeHTMLString(theVideo.buyUrl)+'">buy ('+theVideo.buyPrice+')</a></nobr></td>'; }		
				else if ("rentUrl" in theVideo) { theHTML += '<td class="title3"><nobr><a href="'+VSUTIL.escapeHTMLString(theVideo.rentUrl)+'">rent ('+theVideo.rentPrice+')</a></nobr></td>'; }
				else if ("subscribeUrl" in theVideo) { theHTML += '<td class="title3"><nobr><a href="'+VSUTIL.escapeHTMLString(theVideo.subscribeUrl)+'">subscribe ('+theVideo.subscribePrice+')</a></nobr></td>'; }
				else if ("registerUrl" in theVideo) { theHTML += '<td class="title3"><nobr><a href="'+VSUTIL.escapeHTMLString(theVideo.registerUrl)+'">register</a></nobr></td>'; }
				else if ("hiDefVideoUrl" in theVideo) { theHTML += '<td class="title3"><nobr><a href="'+VSUTIL.escapeHTMLString(theVideo.hiDefVideoUrl)+'">play in hi-def</a></nobr></td>'; }
				else { theHTML += '<td>&nbsp;</td>'; }
				theHTML += '<td><nobr><a href="javascript:getVideos(\'id:'+theVideo.id+'\'); void(0);">Details</a></nobr>';
				theHTML += '';					
				theHTML += '</tr>';
			}
		}
		theHTML += '</table>';
		return(theHTML);			
	}
	
	// Function getVideoSetDetailHTML() detail part takes two arguments, the VideoSet data object returned by the AJAX API, and the name of the AJAX method 
	// most recently invoked by the AOLVideoSearchAPI.  This method returns the HTML table that will display a detail view of each Video in the VideoSet.
	this.getVideoSetDetailHTML = function(VideoSet, methodName) {
	
        show_blocks();		
		var userRatingCountThreshold = 1;
		var theHTML = '';
var ran_unrounded=Math.random()*999999999999999;
		var ranNum=Math.round(ran_unrounded); 
theHTML += '<div align="center"><iframe src="ads_468x60.html" width="468px" height="60px" frameborder="0" marginwidth="0" marginheight="0" scrolling="no"></iframe></div>';
		//theHTML += '<iframe src="google.php" width="468px" height="60px" frameborder="0" marginwidth="0" marginheight="0" scrolling="no"></iframe>';
		theHTML += '<table style="width: 600px; margin: 0 0 0 0; border: 0px; border-style: none; border-collapse: collapse; vertical-align: top;" border="0" cellpadding="4">';
		for (var i=0; i < VideoSet.totalResultsReturned; i++) {
			var theVideo = VideoSet.Video[i]; 
			if (theVideo) {
				if ("videoPlayerEmbedTag" in theVideo) {
					var isembed=1;
				}
				theHTML += '<tr  class="'+(i%2==1?'evenVideo':'oddVideo')+'">';
				
				// backup jigs grid
				theHTML += '<td style="width: 120px; vertical-align: top;"><table id="thumbt" width="120" height="90" cellpadding="0" cellspacing="0"><tr><td id="tmbg" align="center" valign="middle" width="120" height="90"  ><div id="thumbgb" style="	background-repeat:no-repeat; width:120px;height:90px; ">';

				theHTML += '<a href="javascript:playVideo(\''+theVideo.videoUrl+'\','+theVideo.id+',' + isembed +'); void(0);"><img src="'+theVideo.thumbnailUrl+'" class="thumbnail" width="120" height="90"  alt="click to play video"/></a></div></td><td width="10px" bgcolor="#FFFFFF">&nbsp;&nbsp;</td></tr></table>';					


				if (("editorsPick" in theVideo) && (parseInt(theVideo.editorsPick) == 1)) { theHTML += '<div class="callout">FEATURED</div>'; }
				if ("videoPlayerEmbedTag" in theVideo) {  
				theHTML += '<a href="javascript:getVideos(\'id:'+theVideo.id+'\'); void(0);"><img src="' +home_url + 'images/play_now.png" border="0" width="120" height="20" /></a></td>';
				}else{
				theHTML += '<a href="javascript:playVideo(\''+theVideo.videoUrl+'\','+theVideo.id+'); void(0);"><img src="' +home_url + 'images/play_now.png" border="0" width="120" height="20" /></a></td>';
				
				}
				theHTML += '<td style="width: 100%; padding: 0px;" >';
				if ("videoPlayerEmbedTag" in theVideo) {  	

				theHTML += '<div class="titlebig" style="padding-bottom: 2px;"><a href="javascript:getVideos(\'id:'+theVideo.id+'\'); void(0);">'+VSUTIL.escapeHTML(theVideo.title)+'</a></div>';		
				}else{
				theHTML += '<div class="titlebig" style="padding-bottom: 2px;"><a href="javascript:playVideo(\''+theVideo.videoUrl+'\','+theVideo.id+'); void(0);">'+VSUTIL.escapeHTML(theVideo.title)+'</a></div>';		
				}

				theHTML += '<div id="vdetail1" style="padding-bottom: 2px;">';
				theHTML += '<nobr><span class="label">Added:</span> '+(theVideo.dateFound)+'</nobr>&nbsp;&nbsp;';
				if ("runtime" in theVideo) { theHTML += '|&nbsp;&nbsp;<wbr><nobr><span class="label">Runtime:</span> '+VSUTIL.getRuntimeString(theVideo.runtime)+'</nobr>&nbsp;&nbsp;'; }
				if ("quality" in theVideo) { theHTML += '|&nbsp;&nbsp;<wbr><nobr><span class="label">Quality:</span> '+theVideo.quality+'</nobr>'; }
				theHTML += '</div>';
				if ("description" in theVideo) { theHTML += '<div id="vdesc" style="padding-bottom: 2px;">'+VSUTIL.escapeHTML(VSUTIL.truncateString(theVideo.description, 250))+'</div>'; }
				theHTML += '<div id="vdetail1" style="padding-bottom: 2px; padding-top:5px;">';
				if ("category" in theVideo) { theHTML += '<nobr><span class="label">Category:</span> <a href="javascript:getVideos(\'category:&quot;'+VSUTIL.escapeHTMLString(theVideo.category)+'&quot;\'); void(0);">'+VSUTIL.escapeHTML(theVideo.category)+'</a></nobr>&nbsp;&nbsp;<wbr>'; }
				if ("rating" in theVideo) { theHTML += '<nobr>('+VSUTIL.escapeHTML(theVideo.rating)+')</nobr>&nbsp;&nbsp;<wbr>'; }		
				if ("channel" in theVideo) { theHTML += '<nobr><span class="label">Channel:</span> <a href="javascript:getVideos(\'channel:&quot;'+VSUTIL.escapeHTMLString(theVideo.channel)+'&quot;\'); void(0);">'+VSUTIL.escapeHTML(theVideo.channel)+'</a></nobr>&nbsp;&nbsp;<wbr>'; }
				if ("distributor" in theVideo) { theHTML += '<nobr><span class="label">Distributor:</span> <a href="javascript:getVideos(\'distributor:&quot;'+VSUTIL.escapeHTMLString(theVideo.distributor)+'&quot;\'); void(0);">'+VSUTIL.escapeHTML(theVideo.distributor)+'</a></nobr>&nbsp;&nbsp;<wbr>'; }
				if (("showName" in theVideo) && ("showUrl" in theVideo)) { theHTML += '<nobr><span class="label">Show:</span> <a href="javascript:getVideos(\'show:&quot;'+VSUTIL.escapeHTMLString(theVideo.showName)+'&quot;\'); void(0);">'+VSUTIL.escapeHTML(theVideo.showName)+'</a></nobr>&nbsp;&nbsp;<wbr>'; }
				if ("episodeName" in theVideo) { theHTML += '<nobr><span class="label">Episode:</span> <a href="javascript:getVideos(\'&quot;'+VSUTIL.escapeHTMLString(theVideo.episodeName)+'&quot;\'); void(0);">'+VSUTIL.escapeHTML(theVideo.episodeName)+'</a></nobr>&nbsp;&nbsp;<wbr>'; }
				if ("artist" in theVideo) { theHTML += '<nobr><span class="label">Artist:</span> <a href="javascript:getVideos(\'artist:&quot;'+VSUTIL.escapeHTMLString(theVideo.artist)+'&quot;\'); void(0);">'+VSUTIL.escapeHTML(theVideo.artist)+'</a></nobr>&nbsp;&nbsp;<wbr>'; }
				if ("album" in theVideo) { theHTML += '<nobr><span class="label">Album:</span> <a href="javascript:getVideos(\'album:&quot;'+VSUTIL.escapeHTMLString(theVideo.album)+'&quot;\'); void(0);">'+VSUTIL.escapeHTML(theVideo.album)+'</a></nobr>'; }
				theHTML += '</div>';
				if ("tags" in theVideo) { theHTML += '<div id="vdetail1" style="padding-bottom: 2px;"><span><span class="label">Tags:</span> '+VSUTIL.getTagsHTML(theVideo.tags, 10)+'</span></div>'; }
				theHTML += '<div style="padding-bottom: 2px;display:none;">';
				if ("viewCount" in theVideo) { theHTML += '<nobr><span class="label">Views:</span> '+theVideo.viewCount+'</nobr>&nbsp;&nbsp;<wbr>'; }
				if (("userRatingCount" in theVideo) && (parseInt(theVideo.userRatingCount) >= userRatingCountThreshold)) { 
					theHTML += '<nobr><span class="label">Rating:</span> '+theVideo.userRating+' (rated '+theVideo.userRatingCount+' time'+(theVideo.userRatingCount==1?'':'s')+')</nobr>&nbsp;&nbsp;<wbr>';
				}
				theHTML += '<nobr><span class="label">Rate this video:</span>'+VSUTIL.getRatingButtons(theVideo.id)+'</nobr>&nbsp;&nbsp;<wbr>';
				if ("vRank" in theVideo) { theHTML += '<nobr><span class="label">VRank:</span> '+theVideo.vRank+'</nobr>'; }
				theHTML += '</div>';
				theHTML += '<div style="padding-bottom: 2px;">';
				if ("hiDefVideoUrl" in theVideo) { theHTML += '<nobr><a href="'+VSUTIL.escapeHTMLString(theVideo.hiDefVideoUrl)+'" target="_blank">View in high quality</a></nobr>&nbsp;&nbsp;<wbr>'; }
				if ("previewVideoUrl" in theVideo) { theHTML += '<nobr><a href="'+VSUTIL.escapeHTMLString(theVideo.previewVideoUrl)+'" target="_blank">Preview this video</a></nobr>&nbsp;&nbsp;<wbr>'; }
				if ("registerUrl" in theVideo) { theHTML += '<nobr><a href="'+VSUTIL.escapeHTMLString(theVideo.registerUrl)+'">Register to view</a></nobr>&nbsp;&nbsp;<wbr>'; }
				if ("subscribeUrl" in theVideo) { 
					if (theVideo.subscribePrice) { theHTML += '<nobr><a href="'+VSUTIL.escapeHTMLString(theVideo.subscribeUrl)+'">Subscribe to view ('+theVideo.subscribePrice+')</a></nobr>&nbsp;&nbsp;<wbr>'; }
					else { theHTML += '<nobr><a href="'+VSUTIL.escapeHTMLString(theVideo.subscribeUrl)+'">subscribe to view</a></nobr>&nbsp;&nbsp;<wbr>'; }
				}
				if ("rentUrl" in theVideo) { 
					if (theVideo.rentPrice) { theHTML += '<nobr><a href="'+VSUTIL.escapeHTMLString(theVideo.rentUrl)+'">rent this video ('+theVideo.rentPrice+')</a></nobr>&nbsp;&nbsp;<wbr>'; }
					else { theHTML += '<nobr><a href="'+VSUTIL.escapeHTMLString(theVideo.rentUrl)+'">rent this video</a></nobr>&nbsp;&nbsp;<wbr>'; }
				}
				if ("buyUrl" in theVideo) { 
					if (theVideo.buyPrice) { theHTML += '<nobr><a href="'+VSUTIL.escapeHTMLString(theVideo.buyUrl)+'">buy this video ('+theVideo.buyPrice+')</a></nobr>'; }
					else { theHTML += '<nobr><a href="'+VSUTIL.escapeHTMLString(theVideo.buyUrl)+'">buy this video ('+theVideo.buyPrice+')</a></nobr>'; }
				}		
				theHTML += '</div>';		
				theHTML += '<div style="padding-bottom: 2px;">';
				theHTML += '<nobr><b><a href="javascript:getVideos(\'id:'+theVideo.id+'\'); void(0);">Details</a></b></nobr>&nbsp;&nbsp;';
				theHTML += '|&nbsp;&nbsp;<wbr><nobr><b><a href="javascript:getVideos(\'sim:'+theVideo.id+'\'); void(0);">Show related videos</a></b></nobr>&nbsp;&nbsp;';
				theHTML += '';				
				if (methodName.indexOf("getFavoriteVideos") >= 0) {
					theHTML += '|&nbsp;&nbsp;<wbr><nobr><a href="javascript:removeFavorite('+theVideo.id+'); void(0);">remove from favorites</a></nobr>';
				}
				else {
					theHTML += '&nbsp;&nbsp;<wbr><nobr></nobr>';
				}
				theHTML += '</div>';
				theHTML += '</td>';
				theHTML += '</tr>';
				theHTML += '<tr><td height="20px"></td></tr>';				
			}
		}
		theHTML += '</table>';
		return(theHTML);
	}
	
	// Function getVideoFullHTML() takes three arguments, the VideoSet data object returned by the AJAX API, the name of the AJAX method most recently
	// invoked by the AOLVideoSearchAPI, and the previousQuery executed by the API (for the back button).  This function returns the HTML to display 
	// the complete detailed view of all displayable metadata fields in the first video of the VideoSet.
	this.getVideoSetFullHTML = function(VideoSet, methodName, previousQuery) {
    $('result').innerHTML ='';
		this.detail_box(VideoSet, methodName, previousQuery);
		show_blocks(1);
		vdetail=1;
		var theVideo = VideoSet.Video[0];
		var theHTML = '';
		if (!theVideo) { return(theHTML); } 
		digg_url='http://' + home_url +'index.php?play=id:' + theVideo.id;
		


		theHTML += '<table id="getvd_tbl" style="width:600px;border: 0px; border-style: none; border-collapse: collapse; vertical-align: top; overflow:hidden;" cellpadding="4">';
	/*	if ("videoPlayerEmbedTag" in theVideo) {
		theHTML += '<tr><td id="player_box" colspan="2" bgcolor="#FCF8E2" align="center">';
						 theHTML += theVideo.videoPlayerEmbedTag ; 
		theHTML += '</tr></td>';			
		}	*/
		theHTML += '<tr>';
		theHTML += '<td style="width: 120px;" valign="top"><div id="thumblg" >';
			if ("videoPlayerEmbedTag" in theVideo) { 
		theHTML += '<a href="javascript:playVideo(\''+theVideo.videoUrl+'\','+theVideo.id+'); void(0);"><img align="right" src="'+theVideo.thumbnailUrl+'" width="120" class="thumbnail" alt="click to play video"/></a></div>';
			}else{
		theHTML += '<a href="javascript:playVideo(\''+theVideo.videoUrl+'\','+theVideo.id+'); void(0);"><img align="right" src="' +home_url + 'images/thumbbdl_play.png" width="120" height="120" class="thumbnail" alt="click to play video"/></a></div>';				
			}
	if ("videoPlayerEmbedTag" in theVideo) { 
	}else{
		//theHTML +='<a href="javascript:playVideo(\''+theVideo.videoUrl+'\','+theVideo.id+'); void(0);"><img border="0" vspace="3" align="right" src="' +home_url + 'images/launch.png" width="120" height="20"  alt="click to play video"/></a>'	;
	}
	if(!theVideo.description){
	theVideo.description="Watch this video!";	
	}
		theHTML += '</td>';
		theHTML += '<td valign="top">';
		theHTML += '<div class="title">'+VSUTIL.escapeHTML(theVideo.title)+'</div>';
		if ("description" in theVideo) { theHTML += '<div id="getdesc">'+VSUTIL.escapeHTML(theVideo.description)+'</div>'; }
		
		theHTML += '</td>';
		theHTML += '</tr>';
	if ("videoPlayerEmbedTag" in theVideo) {
		theHTML += '<tr><td  colspan="2"  align="center">';	
		theHTML += '<div id="player_box" ><div align="center"><iframe src="ads_468x60.html" width="468px" height="60px" frameborder="0" marginwidth="0" marginheight="0" scrolling="no"></iframe></div></div>';
		theHTML += '<div id="player_box" >';
    	 theHTML += theVideo.videoPlayerEmbedTag ; 
		theHTML += '<br/>This video is provided and hosted from a third party server. Please be aware that this is search functionality helping you discover publicly available websites and their content. We does not host and is not responsible for the content.</div>';	
		
		theHTML += '</td></tr>';	
		}			
		
		theHTML += '<tr><td></td><td>';	
		
		theHTML +='<br><a href="javascript:getVideos(\''+VSUTIL.escapeHTMLString(previousQuery)+'\'); void(0);"><img src="' + home_url + 'images/return.png" border="0" /></a><a href="javascript:getVideos(\'sim:'+theVideo.id+'\'); void(0);"><img src="' + home_url + 'images/show_more.png" border="0" hspace="5" /></a>';
		if (methodName.indexOf("getFavoriteVideos") >= 0) {
	
		}
		else {
			
		}
		theHTML += '</td></tr>';		
		theHTML += '</table>';

		return(theHTML);
	}

	// Function getWatchlistSetHTML() takes one argument, the WatchlistSet data object returned by the AJAX API, and returns
	// the HTML table that will display the items in the WatchlistSet.
	this.getWatchlistSetHTML = function(WatchlistSet) {
		var theHTML = '';
		theHTML += '<table style="width: 100%; margin: 0 0 0 0; border: 0px; border-style: none; border-collapse: collapse; vertical-align: top;" border="0" cellpadding="6">';
		for (var i=0; i < WatchlistSet.totalResultsReturned; i++) {
			var theWatchlist = WatchlistSet.Watchlist[i];
			var theQuery = theWatchlist.query;
			if ("title" in theWatchlist) { var theTitle = theWatchlist.title; }
			else { var theTitle = theQuery; }
			if ("rssUrl" in theWatchlist) { var theRssUrl = theWatchlist.rssUrl; }
			theHTML += '<tr class="'+(i%2==1?'evenVideo':'oddVideo')+'">';
			theHTML += '<td class="title" width="90%"><a href="javascript:getVideos(\''+VSUTIL.escapeHTMLString(theQuery)+'\'); void(0);">'+VSUTIL.escapeHTML(theTitle)+'</a></td>';
			theHTML += '<td><nobr><a href=\''+VSUTIL.escapeHTML(theRssUrl)+'\'>get RSS feed</a></nobr></td>';
			theHTML += '<td><nobr><a href="javascript:removeWatchlist(\''+VSUTIL.escapeHTMLString(theQuery)+'\'); void(0);">delete this watchlist</a></nobr></td>';
			theHTML += '</tr>';
		}
		theHTML += '</table>';
		return(theHTML);			
	}

	// Function displayMessage() will display the provided text message in the view container.
	this.displayMessage = function(message) {
		var theHTML = '';
		theHTML += '<table style="width: 100%; margin: 0 0 0 0; border: 0px; border-style: none; border-collapse: collapse; vertical-align: top;" cellpadding="10">';
		theHTML += '<tr><td style="text-align: center;">';
		theHTML += VSUTIL.escapeHTML(message);
		theHTML += '</td></tr>';		
		theHTML += '</table>';
		container.innerHTML = theHTML;
	}

	// Set the value of the view to draw (e.g. 0 == grid view, 1 == list view, and 2 == detail view) then refresh the display.
	this.setView = function(viewInt) {
		view = viewInt;
	}
	
	// Returns the value of the current view.
	this.getView = function() {
		return(view);
	}

	// Function displayFullView() displays the full view of a single video record.
	this.displayFullView = function(aolvs, previousQuery) {
		if (aolvs.VideoSet) {
			container.innerHTML = this.getVideoSetFullHTML(aolvs.VideoSet, aolvs.method, previousQuery);
		}
	}

	// Function displayWatchlistSet() displays the current WatchlistSet in the video results panel.
	this.displayWatchlists = function(aolvs) {
		if (aolvs.WatchlistSet) {
			if (aolvs.WatchlistSet.totalResultsReturned == 0) { this.displayMessage('There are no watchlists available.'); }
			else { container.innerHTML = this.getWatchlistSetHTML(aolvs.WatchlistSet); }
		}		
	}

	// Function refresh() will draw the HTML for this widget into the container tag.  This function takes one argument, the AOLVideoSearch object
	// that contains all of the data returned by the AJAX API.  If this object contains a valid VideoSet, then all of the videos in the VideoSet
	// will be displayed in either grid, detail or list view.  If there are no videos in the VideoSet, then display a helpful message.  If there 
	// is only one video in the VideoSet, then display the full view of the available video metadata. 
	this.refresh = function(aolvs) {
		if (aolvs.VideoSet) {
			var VideoSet = aolvs.VideoSet;
			if (view == 0) { container.innerHTML = this.getVideoSetGridHTML(VideoSet, aolvs.method, aolvs.results); }
			else if (view == 1) { container.innerHTML = this.getVideoSetListHTML(VideoSet, aolvs.method, aolvs.results); }
			else { container.innerHTML = this.getVideoSetDetailHTML(VideoSet, aolvs.method, aolvs.results); }
		}
	}
}


// Function TitleBar1() is a view object for displaying a title above a set of video search results.  This title bar will 
// display the approriate title text as well as the pagination buttons and a link to an RSS feed.
var TitleBar1 = function(containerID) {
	
	// PRIVATE ATTRIBUTES:
	var container = document.getElementById(containerID);

	// PUBLIC METHODS:		
	// Function getHTML() returns HTML to display a title bar for a set of video search results.  This function takes three arguments, the VideoSet
	// object, the query string for the most recent query, and the method name for the most recent method call.
	this.getHTML = function(VideoSet, query, methodName, results) {
		var theHTML = '';
		theHTML += '<table style="width: 600px; margin: 0 0 0 0; border: 0px; border-style: none; border-collapse: collapse;" cellpadding="0">';
		theHTML += '<tr>';
		theHTML += '<td style="text-align: left;" colspan="3">';
		theHTML += '<span class="header">' + VSUTIL.escapeHTML(VideoSet.title) + '</span>';

		theHTML += '</td>';
	
		theHTML += '</tr>';		
		theHTML += '</table>';
		return(theHTML);
	}
	this.getPagerHTML = function(totalResultsAvailable, firstResultPosition, results) {
			var maxBtns = 8;
			var midpoint = Math.floor(maxBtns/2);
			var currentPage = Math.ceil(firstResultPosition/results);
			if (currentPage <= midpoint) { var firstPage = 0; }
			else { firstPage = currentPage - midpoint; }
			var forwardPages = Math.floor((totalResultsAvailable - (firstResultPosition + 1)) / results);
			if (currentPage >= midpoint) {
				if (forwardPages <= midpoint) { var lastPage = currentPage + forwardPages; }
				else { var lastPage = currentPage + midpoint; }
			}
			else {
				if (forwardPages <= (maxBtns - currentPage)) { var lastPage = currentPage + forwardPages; }
				else { var lastPage = maxBtns; }
			}
			
			//alert('currentPage: '+currentPage+'; forwardPages: '+forwardPages+'; firstPage: '+firstPage+'; lastPage: '+lastPage);
			var theHTML = '';

			if (firstPage < lastPage) {
				for (var page = firstPage; page <= lastPage; page++) {
					
					if (page == currentPage) {
						theHTML += '<td width="18px" class="pagenav" style="'+(theHTML==''?'':'border-left: 1px solid #EFF3FC; ')+'text-align: center; text-decoration: underline;">'+parseInt(page+1)+'</td>';
					}
					else {
						theHTML += '<td width="18px" class="pagenav" style="'+(theHTML==''?'':'border-left: 1px solid #EFF3FC; ')+'text-align: center;"><a href="javascript:goToPage('+parseInt(page+1)+'); void(0);">&nbsp;'+parseInt(page+1)+'&nbsp;</a></td>';
					}
				}
			}

		if (theHTML == '') { return(''); }
		else {
			return('<table align="right" style="padding: 0 0 0 0; margin: 0 0 0 0; border: 0px; border-style: none; border-collapse: collapse;" cellpadding="0"><tr>'+theHTML+'</tr></table>');
		}
}	
	// Function displayTitle() displays the provided message in the title bar.
	this.displayTitle = function(message) {
		var theHTML = '';
		theHTML += '<table style="width: 100%; margin: 0 0 0 0; border: 0px; border-style: none; border-collapse: collapse;" cellpadding="0">';
		theHTML += '<tr><td style="text-align: left;">';
		if (message == '') { theHTML += '<span class="header">&nbsp;</span>'; } else { theHTML += '<span class="header">' + VSUTIL.escapeHTML(message) + '</span>'; }
		theHTML += '</td></tr>';
		theHTML += '<tr><td>&nbsp;</td></tr>';
		theHTML += '</table>';

		container.innerHTML = theHTML;

	}

	// Function refresh() will draw the HTML for this widget into the container tag.  This function takes one mandatory argument, the AOLVideoSearch 
	// object that contains the response data from the AJAX API.  If the AOLVideoSearch object contains a valid VideoSet, then the provided title
	// will be displayed for the given video set.  Otherwise, if the AOLVideoSearch object contains a valid WatchlistSet, then an appropriate title
	// will be displayed for the set of watchlists.
	this.refresh = function(aolvs) {
		if (aolvs.VideoSet) {
			if (aolvs.VideoSet.totalResultsReturned == 0) { this.displayTitle(aolvs.VideoSet.title); }
			else { container.innerHTML = this.getHTML(aolvs.VideoSet, aolvs.query, aolvs.method, aolvs.results); }
		}
	}
	
}

// under result title bar
var TitleBar2 = function(containerID) {
	
	// PRIVATE ATTRIBUTES:
	var container = document.getElementById(containerID);

	// PUBLIC METHODS:		
	// Function getHTML() returns HTML to display a title bar for a set of video search results.  This function takes three arguments, the VideoSet
	// object, the query string for the most recent query, and the method name for the most recent method call.
	this.getHTML = function(VideoSet, query, methodName, results) {
		var theHTML = '';
		theHTML += '<div class="pageno"><table border="0" cellpadding="0" cellspacing="0" style="border-collapse: collapse" bordercolor="#111111" align="center">';
		theHTML += '<tr><td width="30" align="left">';
		if (hasPreviousPage()) { theHTML += '<a href="javascript:previousPage(); void(0);"><img src="' +home_url + 'images/back.jpg" width="45" height="26" border="0" align="absmiddle" /></a>'; } else { theHTML += '&nbsp;'; }
		theHTML += '</td><td align="center">';	
				
		theHTML += this.getPagerHTML(parseInt(VideoSet.totalResultsAvailable), parseInt(VideoSet.firstResultPosition), parseInt(results));

		theHTML += '</td><td  width="30" align="right">';	
			if (hasNextPage()) { theHTML += '<a href="javascript:nextPage(); void(0);"><img src="' +home_url + 'images/next.jpg" width="45" height="26" border="0" align="absmiddle" /></a>'; } else { theHTML += '&nbsp;'; }
		theHTML += '</td><tr>';
		theHTML += '<td align="center"  width="30">';
		
		theHTML += '</td>';
		theHTML += '<td align="center"><span style="color: #666666; ">';
		theHTML += (parseInt(VideoSet.firstResultPosition) + 1) + ' to ' + (parseInt(VideoSet.firstResultPosition) + parseInt(VideoSet.totalResultsReturned)) + ' of <b>' + VideoSet.totalResultsAvailable + '</b>';
		theHTML += '</span></td>';		
		theHTML += '<td align="center" width="30">';
	
		theHTML += '</td>';
		theHTML += '</tr>';		
		theHTML += '</table></div><br/><br/>';
		return(theHTML);
	}
	this.getPagerHTML = function(totalResultsAvailable, firstResultPosition, results) {
			var maxBtns = 8;
			var midpoint = Math.floor(maxBtns/2);
			var currentPage = Math.ceil(firstResultPosition/results);
			if (currentPage <= midpoint) { var firstPage = 0; }
			else { firstPage = currentPage - midpoint; }
			var forwardPages = Math.floor((totalResultsAvailable - (firstResultPosition + 1)) / results);
			if (currentPage >= midpoint) {
				if (forwardPages <= midpoint) { var lastPage = currentPage + forwardPages; }
				else { var lastPage = currentPage + midpoint; }
			}
			else {
				if (forwardPages <= (maxBtns - currentPage)) { var lastPage = currentPage + forwardPages; }
				else { var lastPage = maxBtns; }
			}
			
			//alert('currentPage: '+currentPage+'; forwardPages: '+forwardPages+'; firstPage: '+firstPage+'; lastPage: '+lastPage);
			var theHTML = '';

			if (firstPage < lastPage) {
				for (var page = firstPage; page <= lastPage; page++) {
					
					if (page == currentPage) {
						theHTML += '<td width="18px" class="pagenav" style="'+(theHTML==''?'':'border-left: 1px solid #EFF3FC; ')+'text-align: center; text-decoration: underline;">'+parseInt(page+1)+'</td>';
					}
					else {
						theHTML += '<td width="18px" class="pagenav" style="'+(theHTML==''?'':'border-left: 1px solid #EFF3FC; ')+'text-align: center;"><a href="javascript:goToPage('+parseInt(page+1)+'); void(0);">&nbsp;'+parseInt(page+1)+'&nbsp;</a></td>';
					}
				}
			}

		if (theHTML == '') { return(''); }
		else {
			return('<table align="right" style="padding: 0 0 0 0; margin: 0 0 0 0; border: 0px; border-style: none; border-collapse: collapse;" cellpadding="0"><tr>'+theHTML+'</tr></table>');
		}
}		
	// Function displayTitle() displays the provided message in the title bar.
	this.displayTitle = function(message) {
		var theHTML = '';
		theHTML += '<table style="width: 100%; margin: 0 0 0 0; border: 0px; border-style: none; border-collapse: collapse;" cellpadding="0">';
		theHTML += '<tr><td style="text-align: left;">';
		if (message == '') { theHTML += '<span class="header">&nbsp;</span>'; } else { theHTML += '<span class="header">' + VSUTIL.escapeHTML(message) + '</span>'; }
		theHTML += '</td></tr>';
		theHTML += '<tr><td>&nbsp;</td></tr>';
		theHTML += '</table>';
		container.innerHTML = theHTML;
	}

	// Function refresh() will draw the HTML for this widget into the container tag.  This function takes one mandatory argument, the AOLVideoSearch 
	// object that contains the response data from the AJAX API.  If the AOLVideoSearch object contains a valid VideoSet, then the provided title
	// will be displayed for the given video set.  Otherwise, if the AOLVideoSearch object contains a valid WatchlistSet, then an appropriate title
	// will be displayed for the set of watchlists.
	this.refresh = function(aolvs) {
		if (aolvs.VideoSet) {
			if (aolvs.VideoSet.totalResultsReturned == 0) { this.displayTitle(aolvs.VideoSet.title); }
			else { container.innerHTML = this.getHTML(aolvs.VideoSet, aolvs.query, aolvs.method, aolvs.results); }
		}
	}
}



// Function CategoryMenu1() is a view object for displaying a menu of categories returned in the CategorySet object.
var CategoryMenu1 = function(containerID) {
	
	// PRIVATE ATTRIBUTES:
	var container = document.getElementById(containerID);
	var showHeader = true;  	// The boolean that determines if a menu header is displayed.
	var showAllBtn = true;		// The boolean that determines if an 'all' category is included in menu.
	var charLimit = 16;			// The maximum number of characters to display in each menu item.

	// PUBLIC METHODS:		
	// Function getHTML() returns HTML to display a menu containing the categories provided in the CategorySet object.
	this.getHTML = function(CategorySet) {
		var theHTML = '';
		if (showHeader) { theHTML += '<div class="menuHeader"><nobr>Refine By Category:</nobr></div>'; }
		if (showAllBtn) { theHTML += '<div><nobr><a href="javascript:getVideosByCategory(\'all\'); void(0);">All Categories</a></nobr></div>'; }
		if (("totalResultsReturned" in CategorySet) && (CategorySet.totalResultsReturned > 0)) {
			for (var i=0; i < CategorySet.totalResultsReturned; i++) {
				var categoryName = CategorySet.Category[i].name;
				var categoryCount = CategorySet.Category[i].count;
				theHTML += '<div><nobr><a href="javascript:getVideosByCategory(\''+VSUTIL.escapeHTMLString(categoryName)+'\'); void(0);">'+VSUTIL.escapeHTML(VSUTIL.truncateString(categoryName, charLimit))+' ('+categoryCount+')</a></nobr></div>';
			}
		}
		else { theHTML += 'no related categories'; }
		return(theHTML);
	}
	
	// Function refresh() will draw the HTML for this widget into the container tag.  This function takes one argument, the CategorySet data 
	// object returned by the AJAX API.
	this.refresh = function(CategorySet) {
		if (CategorySet) { container.innerHTML = this.getHTML(CategorySet); }
	}
	
	// Function clear() will display nothing in this menu.
	this.clear = function() {
		container.innerHTML = '';
	}
}


// Function ChannelMenu1() is a view object for displaying a menu of channels returned in the ChannelSet object.
var ChannelMenu1 = function(containerID) {
	
	// PRIVATE ATTRIBUTES:
	var container = document.getElementById(containerID);
	var showHeader = true;  	// The boolean that determines if a menu header is displayed.
	var showAllBtn = true;		// The boolean that determines if an 'all' category is included in menu.
	var charLimit = 16;			// The maximum number of characters to display in each menu item.

	// PUBLIC METHODS:		
	// Function getHTML() returns HTML to display a menu containing the channels provided in the ChannelSet object.
	this.getHTML = function(ChannelSet) {
		var theHTML = '';
		if (showHeader) { theHTML += '<div class="menuHeader"><nobr>Refine By Channel:</nobr></div>'; }
		if (showAllBtn) { theHTML += '<div><nobr><a href="javascript:getVideosByChannel(\'all\'); void(0);">All Channels</a></nobr></div>'; }
		if (("totalResultsReturned" in ChannelSet) && (ChannelSet.totalResultsReturned > 0)) {
			for (var i=0; i < ChannelSet.totalResultsReturned; i++) {
				var channelName = ChannelSet.Channel[i].name;
				var channelCount = ChannelSet.Channel[i].count;
				theHTML += '<div><nobr><a href="javascript:getVideosByChannel(\''+VSUTIL.escapeHTMLString(channelName)+'\'); void(0);">'+VSUTIL.escapeHTML(VSUTIL.truncateString(channelName, charLimit))+' ('+channelCount+')</a></nobr></div>';
			}
		}
		else { theHTML += 'no related channels'; }
		return(theHTML);
	}
	
	// Function refresh() will draw the HTML for this widget into the container tag.  This function takes one argument, the ChannelSet data 
	// object returned by the AJAX API.
	this.refresh = function(ChannelSet) {
		if (ChannelSet) { container.innerHTML = this.getHTML(ChannelSet); }
	}
	
	// Function clear() will display nothing in this menu.
	this.clear = function() {
		container.innerHTML = '';
	}
}


// Function TagMenu1() is a view object for displaying a menu of tags returned in the TagSet object.
var TagMenu1 = function(containerID) {
	
	// PRIVATE ATTRIBUTES:
	var container = document.getElementById(containerID);
	var showHeader = true;  	// The boolean that determines if a menu header is displayed.
	var showAllBtn = true;		// The boolean that determines if an 'all' category is included in menu.
	var charLimit = 16;			// The maximum number of characters to display in each menu item.

	// PUBLIC METHODS:		
	// Function getHTML() returns HTML to display a menu containing the tags provided in the TagSet object.
	this.getHTML = function(TagSet) {
		var theHTML = '';
		if (showHeader) { theHTML += '<div class="menuHeader"><nobr>Refine By Tag:</nobr></div>'; }
		if (showAllBtn) { theHTML += '<div><nobr><a href="javascript:getVideosByTag(\'all\'); void(0);">All Tags</a></nobr></div>'; }
		if (("totalResultsReturned" in TagSet) && (TagSet.totalResultsReturned > 0)) {
			for (var i=0; i < TagSet.totalResultsReturned; i++) {
				var tagName = TagSet.Tag[i].name;
				var tagCount = TagSet.Tag[i].count;
				theHTML += '<div><nobr><a href="javascript:getVideosByTag(\''+VSUTIL.escapeHTMLString(tagName)+'\'); void(0);">'+VSUTIL.escapeHTML(VSUTIL.truncateString(tagName, charLimit))+' ('+tagCount+')</a></nobr></div>';
			}
		}
		else { theHTML += 'no related tags'; }
		return(theHTML);
	}
	
	// Function refresh() will draw the HTML for this widget into the container tag.  This function takes one argument, the TagSet data 
	// object returned by the AJAX API.
	this.refresh = function(TagSet) {
		if (TagSet) { container.innerHTML = this.getHTML(TagSet); }
	}
	
	// Function clear() will display nothing in this menu.
	this.clear = function() {
		container.innerHTML = '';
	}
}


// Function UserMenu1() is a view object for displaying a menu of users returned in the UserSet object.
var UserMenu1 = function(containerID) {
	
	// PRIVATE ATTRIBUTES:
	var container = document.getElementById(containerID);
	var showHeader = true;  	// The boolean that determines if a menu header is displayed.
	var showAllBtn = true;		// The boolean that determines if an 'all' category is included in menu.
	var charLimit = 16;			// The maximum number of characters to display in each menu item.

	// PUBLIC METHODS:		
	// Function getHTML() returns HTML to display a menu containing the users provided in the UserSet object.
	this.getHTML = function(UserSet) {
		var theHTML = '';
		if (showHeader) { theHTML += '<div class="menuHeader"><nobr>Refine By User:</nobr></div>'; }
		if (showAllBtn) { theHTML += '<div><nobr><a href="javascript:getVideosByUser(\'all\'); void(0);">All Users</a></nobr></div>'; }
		if (("totalResultsReturned" in UserSet) && (UserSet.totalResultsReturned > 0)) {
			for (var i=0; i < UserSet.totalResultsReturned; i++) {
				var userName = UserSet.User[i].name;
				var userCount = UserSet.User[i].count;
				theHTML += '<div><nobr><a href="javascript:getVideosByUser(\''+VSUTIL.escapeHTMLString(userName)+'\'); void(0);">'+VSUTIL.escapeHTML(VSUTIL.truncateString(userName, charLimit))+' ('+userCount+')</a></nobr></div>';
			}
		}
		else { theHTML += 'no related users'; }
		return(theHTML);
	}
	
	// Function refresh() will draw the HTML for this widget into the container tag.  This function takes one argument, the UserSet data 
	// object returned by the AJAX API.
	this.refresh = function(UserSet) {
		if (UserSet) { container.innerHTML = this.getHTML(UserSet); }
	}

	// Function clear() will display nothing in this menu.
	this.clear = function() {
		container.innerHTML = '';
	}
}


// Function LoginButton1() is a view object to display a stateful login button.  If the user is not logged in, the 
// button displays 'login', if the user is logged in, the button displays 'logout'.
var LoginButton1 = function(containerID) {

	// PRIVATE ATTRIBUTES:
	var container = document.getElementById(containerID);

	// PUBLIC METHODS:		
	this.refresh = function(isLoggedIn) {
		var theHTML = '';
		if (isLoggedIn) { theHTML += 'You are logged in: <a href="javascript:logout(); void(0);">logout</a>'; }
		else { theHTML += 'You are not logged in: <a href="javascript:login(); void(0);">login</a>'; }
		container.innerHTML = theHTML;
	}
}


// Function VSUtilities() is an object that contains a variety of utility methods for processing video search results metadata.
// These methods are available in the global VSUTIL object.
var VSUtilities = function() {
	
	// PUBLIC METHODS:
	// Function getDateString() takes the dateFound string, in RFC 2822 format (see http://www.faqs.org/rfcs/rfc2822),
	// and returns a long-format string suitable for display in a web page.  For example "Thursday, March 09, 2006 12:53:14 PM".
	this.getDateString = function(dateFound) {
		var theDate = new Date(dateFound);
		return(theDate.toLocaleString());
	}
	
	// Function getShortDateString() takes the dateFound srting, in RFC 2822 format (see http://www.faqs.org/rfcs/rfc2822),
	// and returns a short-format string representing the elapsed time.  For example, "1 minute ago", "3 days ago", "2 years ago", etc..
	this.getShortDateString = function(dateFound) {
		var theDate = new Date(dateFound);
		var now = new Date();
		var elapsedTime = now.getTime() - theDate.getTime();
		var seconds = Math.round(elapsedTime/1000);
		if (seconds < 60) { return(seconds+" second"+(seconds==1?'':'s')+" ago"); }
		var minutes = Math.round(elapsedTime/(1000*60));
		if (minutes < 60) { return(minutes+" minute"+(minutes==1?'':'s')+" ago"); }	
		var hours = Math.round(elapsedTime/(1000*60*60));	
		if (hours < 24) { return(hours+" hour"+(hours==1?'':'s')+" ago"); }
		var days = Math.round(elapsedTime/(1000*60*60*24));
		if (days < 30) { return(days+" day"+(days==1?'':'s')+" ago"); }	
		var months = Math.round(elapsedTime/(1000*60*60*24*30));
		if (months < 12) { return(months+" month"+(months==1?'':'s')+" ago"); }	
		var years = Math.round(elapsedTime/(1000*60*60*24*30*12));
		return(years+" year"+(years==1?'':'s')+" ago");
	}
	
	// Function getRuntimeString() takes the runtime string, which represents the duration of the video in seconds, 
	// and returns an appropriate human-readable string.
	this.getRuntimeString = function(runtime) {
		var totalSeconds = parseInt(runtime);
		var minutes = Math.floor(totalSeconds/60);
		var seconds = totalSeconds - (minutes * 60);
		return(minutes+"min "+seconds+"sec");
	}

	// Function getTagsHTML() takes two arguments, the string containing the comma-delimited list of tag names and the 
	// the maximum number of tags to return in the response.  This function returns an HTML string where each tag is
	// a clickable link.
	this.getTagsHTML = function(tags, maxTags) {
		var tagArray = tags.split(",", maxTags);
		var theHTML = '';
		var theTag = '';
		for (var i=0; i < tagArray.length; i++) {
			theTag = VSUTIL.trim(tagArray[i]);
			theHTML += '<nobr><a href="javascript:getVideos(\'tag:&quot;'+this.escapeHTMLString(theTag)+'&quot;\'); void(0);">'+this.escapeHTML(VSUTIL.truncateString(theTag,30))+'</a></nobr>&nbsp;&nbsp;<wbr>';
		}
		return(theHTML);
	}
	
	// Function getRatingButtons() returns the HTML that will draw a simple set of buttons to allow the user to rate a video
	// by 1, 2, 3, 4 or 5.
	this.getRatingButtons = function(id) {
		var theHTML = '&nbsp;';
		for (var i=1; i <= 5; i++) {
			theHTML += '<a href="javascript:submitRating('+id+','+parseInt(i)+'); void(0);">'+i+'</a>&nbsp;';
		}
		return(theHTML);
	}
	
	// Function truncateString() takes two arguments, the original string and the maximum number of characters to return
	// in the new string.  This function returns a truncated version of the string, appended with an ellipsis, if the 
	// original string is longer than maxChar characters.  Note that the use of HTML entities in the string may cause 
	// the length of the truncated string to vary.  A check is provided in this method to avoid truncating html entities.
	this.truncateString = function(string, maxChar) {
		if (string && (string.length > maxChar)) {
			var index = string.indexOf(";", maxChar);
			if ((index >= 0) && ((index - maxChar) < 10)) { maxChar = index+1; }
			return(string.substr(0, maxChar)+'...');
		}
		else { return(string); }
	}
	
	// Function escapeHTML() takes a string as an argument and returns a new string where the following characters are replaced
	// by their HTML entity equivalents: &, <, >, ", '.
	this.escapeHTML = function(string) {
		var newstr = string.replace(/&/g,"&amp;");
		newstr = newstr.replace(/</g,"&lt;");
		newstr = newstr.replace(/>/g,"&gt;");
		newstr = newstr.replace(/'/g,"&#039;");
		newstr = newstr.replace(/"/g,"&quot;");
		return(newstr);
	}
	
	// Function escapeString() takes a string as an argument and returns a new string where all single and double quotes in the original
	// string have been escaped.
	this.escapeString = function(string) {
		var newstr = string.replace(/'/g,"\'");
		return(newstr.replace(/"/g,'\"'));
	}
	
	// Function escapeHTMLString takes a string as an argument and returns a new string where the following characters are replaced
	// by their HTML entity equivalents: &, <, >, ", '.  Additionally, single and double quotes are double escaped.
	this.escapeHTMLString = function(string) {
		var newstr = string.replace(/&/g,"&amp;");
		newstr = newstr.replace(/</g,"&lt;");
		newstr = newstr.replace(/>/g,"&gt;");
		newstr = newstr.replace(/'/g,"\\&#039;");
		newstr = newstr.replace(/"/g,"\\&quot;");
		return(newstr);		
	}

	// Function escapeRegExp takes a string as an argument and returns a new string where the following regular expression special
	// characters are preceded by a backslash: ^ $ . * + ? = ! : | \ / ( ) [ ] { }
	this.escapeRegExp = function(string) {
		var newstr = string.replace(/\^/g,"\^");
		newstr = newstr.replace(/\$/g,"\$");
		newstr = newstr.replace(/\./g,"\.");
		newstr = newstr.replace(/\*/g,"\*");
		newstr = newstr.replace(/\+/g,"\+");
		newstr = newstr.replace(/\?/g,"\?");
		newstr = newstr.replace(/\=/g,"\=");
		newstr = newstr.replace(/\!/g,"\!");
		newstr = newstr.replace(/\:/g,"\:");
		newstr = newstr.replace(/\|/g,"\|");
		newstr = newstr.replace(/\\/g,"\\");
		newstr = newstr.replace(/\//g,"\/");
		newstr = newstr.replace(/\(/g,"\(");
		newstr = newstr.replace(/\)/g,"\)");
		newstr = newstr.replace(/\[/g,"\[");
		newstr = newstr.replace(/\]/g,"\]");
		newstr = newstr.replace(/\{/g,"\{");
		newstr = newstr.replace(/\}/g,"\}");
		return(newstr);		
	}
	
	// Function trim() removes any leading or trailing spaces from the specified string.
	this.trim = function(string) {
		while(''+string.charAt(0) == ' ') string = string.substring(1, string.length);
		while(''+string.charAt(string.length-1)==' ') string = string.substring(0, string.length-1);
		return(string);
	}
}
VSUTIL = new VSUtilities();

//-->
