//<!--
//*****************************************************************************************************
// 	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.getVideoSetGridHTML = function(VideoSet, methodName) {
		var minCellWidth = 130;
		var cellsPerRow = Math.floor(container.offsetWidth/minCellWidth);
		var rows = Math.ceil(VideoSet.totalResultsReturned/cellsPerRow);
		var theHTML = '';
		theHTML += '<table style="width: 100%; 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>';
			
			newVideoSet = sortClevver(VideoSet); //new
			for (var k=0; k < cellsPerRow; k++) {
				var i = (j * cellsPerRow) + k; 
				theHTML += '<td align="center" valign="top" style="padding: 12px 4px 12px 4px;">';
				if (i >= VideoSet.Video.length) { theHTML += '&nbsp;'; }
				else {
					var theVideo = newVideoSet[i];
					//var theVideo = VideoSet.Video[i]; //old
					if (theVideo) {
						theHTML += '<div style="width: '+minCellWidth+'px;">';
						theHTML += '<a href="javascript:getChannelUrl(\''+theVideo.channelUrl+'\'); playVideo(\''+theVideo.videoUrl+'\','+theVideo.id+'); void(0);"><img src="'+theVideo.thumbnailUrl+'" class="thumbnail" alt="click to play video"/></a>';
						if (("editorsPick" in theVideo) && (parseInt(theVideo.editorsPick) == 1)) { theHTML += '<div class="callout">FEATURED</div>'; }
						theHTML += '<div><a href="javascript:getChannelUrl(\''+theVideo.channelUrl+'\'); playVideo(\''+theVideo.videoUrl+'\','+theVideo.id+'); void(0);">'+VSUTIL.escapeHTML(VSUTIL.truncateString(theVideo.title, 40))+'</a></div>';
						if ("runtime" in theVideo) { theHTML += '<div><nobr>'+VSUTIL.getRuntimeString(theVideo.runtime)+'</nobr></div>'; }
						theHTML += '<div><nobr><span class="label">Added:</span> '+VSUTIL.getShortDateString(theVideo.dateFound)+'</nobr></div>';
						if ("channel" in theVideo) { theHTML += '<div><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><nobr><span class="label">Views:</span> '+theVideo.viewCount+'</nobr></div>'; }
						theHTML += '<div><a href="javascript:getVideos(\'id:'+theVideo.id+'\'); void(0);">show details</a></div>';
						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) {
		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="4">';
				
		newVideoSet = sortClevver(VideoSet);
		for (var i=0; i < VideoSet.totalResultsReturned; i++) {
				//var theVideo = VideoSet.Video[i];  //old
				var theVideo = newVideoSet[i]; 
			if (theVideo) {
				theHTML += '<tr class="'+(i%2==1?'evenVideo':'oddVideo')+'">';
				theHTML += '<td class="title"><nobr><a href="javascript:getChannelUrl(\''+theVideo.channelUrl+'\'); playVideo(\''+theVideo.videoUrl+'\','+theVideo.id+'); void(0);">'+VSUTIL.escapeHTML(VSUTIL.truncateString(theVideo.title, 40))+'</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><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><nobr>'+VSUTIL.getRuntimeString(theVideo.runtime)+'</nobr></td>'; }
				else { theHTML += '<td>&nbsp;</td>'; }
				if ("dateFound" in theVideo) { theHTML += '<td><nobr>'+VSUTIL.getShortDateString(theVideo.dateFound)+'</nobr></td>'; }
				else { theHTML += '<td>&nbsp;</td>'; }
				if ("buyUrl" in theVideo) { theHTML += '<td><nobr><a href="'+VSUTIL.escapeHTMLString(theVideo.buyUrl)+'">buy ('+theVideo.buyPrice+')</a></nobr></td>'; }		
				else if ("rentUrl" in theVideo) { theHTML += '<td><nobr><a href="'+VSUTIL.escapeHTMLString(theVideo.rentUrl)+'">rent ('+theVideo.rentPrice+')</a></nobr></td>'; }
				else if ("subscribeUrl" in theVideo) { theHTML += '<td><nobr><a href="'+VSUTIL.escapeHTMLString(theVideo.subscribeUrl)+'">subscribe ('+theVideo.subscribePrice+')</a></nobr></td>'; }
				else if ("registerUrl" in theVideo) { theHTML += '<td><nobr><a href="'+VSUTIL.escapeHTMLString(theVideo.registerUrl)+'">register</a></nobr></td>'; }
				else if ("hiDefVideoUrl" in theVideo) { theHTML += '<td><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></td>';
				theHTML += '</tr>';
			}
		}
		theHTML += '</table>';
		return(theHTML);			
	}
	
	// Function getVideoSetDetailHTML() 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) {
		var userRatingCountThreshold = 1;
		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="4">';

			newVideoSet = sortClevver(VideoSet);
		for (var i=0; i < VideoSet.totalResultsReturned; i++) {
				//var theVideo = VideoSet.Video[i];  //old
				var theVideo = newVideoSet[i]; 
			if (theVideo) {
				theHTML += '<tr class="'+(i%2==1?'evenVideo':'oddVideo')+'">';
				theHTML += '<td style="width: 1%; vertical-align: top;">';
				theHTML += '<a href="javascript:getChannelUrl(\''+theVideo.channelUrl+'\'); playVideo(\''+theVideo.videoUrl+'\','+theVideo.id+'); void(0);"><img src="'+theVideo.thumbnailUrl+'" class="thumbnail" alt="click to play video"/></a>';
				if (("editorsPick" in theVideo) && (parseInt(theVideo.editorsPick) == 1)) { theHTML += '<div class="callout">FEATURED</div>'; }
				theHTML += '</td>';
				theHTML += '<td style="width: 100%; padding-left: 0px;">';
				theHTML += '<div class="title" style="padding-bottom: 2px;"><a href="javascript:getChannelUrl(\''+theVideo.channelUrl+'\'); playVideo(\''+theVideo.videoUrl+'\','+theVideo.id+'); void(0);">'+VSUTIL.escapeHTML(theVideo.title)+'</a></div>';
				theHTML += '<div style="padding-bottom: 2px;">';
				theHTML += '<nobr><span class="label">Added:</span> '+VSUTIL.getShortDateString(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 style="padding-bottom: 2px;">'+VSUTIL.escapeHTML(VSUTIL.truncateString(theVideo.description, 250))+'</div>'; }
				theHTML += '<div style="padding-bottom: 2px;">';
				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 style="padding-bottom: 2px;"><span><span class="label">Tags:</span> '+VSUTIL.getTagsHTML(theVideo.tags, 4)+'</span></div>'; }
				theHTML += '<div style="padding-bottom: 2px;">';
				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><a href="javascript:getVideos(\'id:'+theVideo.id+'\'); void(0);">show details</a></nobr>&nbsp;&nbsp;';
				theHTML += '|&nbsp;&nbsp;<wbr><nobr><a href="javascript:getVideos(\'sim:'+theVideo.id+'\'); void(0);">show more like this</a></nobr>&nbsp;&nbsp;';
				
				/*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><a href="javascript:addFavorite('+theVideo.id+'); void(0);">add to favorites</a></nobr>';
				}*/
				theHTML += '</div>';
				theHTML += '</td>';
				theHTML += '</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) {
		var theVideo = VideoSet.Video[0];
		var theHTML = '';
		if (!theVideo) { return(theHTML); } 
		theHTML += '<div style="padding: 10px 10px 10px 10px;">';
		theHTML += '<table style="width:480;border: 0px; border-style: none; border-collapse: collapse; vertical-align: top;" cellpadding="4">';
		
		theHTML += '<tr><td></td><td align=right>';
		theHTML += '<div align=right><a href="javascript:getVideos(\''+VSUTIL.escapeHTMLString(previousQuery)+'\'); void(0);">Back To Search Results</a></div>&nbsp;&nbsp;';		
		theHTML += '</td></tr>';
		
		theHTML += '<tr>';
		theHTML += '<td style="width: 1%;">';
		theHTML += '<a href="javascript:getChannelUrl(\''+theVideo.channelUrl+'\'); playVideo(\''+theVideo.videoUrl+'\','+theVideo.id+'); void(0);"><img align="right" src="'+theVideo.thumbnailUrl+'" class="thumbnail" alt="click to play video"/></a>';
		theHTML += '</td>';
		theHTML += '<td>';
		theHTML += '<div class="title"><a href="javascript:getChannelUrl(\''+theVideo.channelUrl+'\'); playVideo(\''+theVideo.videoUrl+'\','+theVideo.id+'); void(0);">'+VSUTIL.escapeHTML(theVideo.title)+'</a></div>';
		if ("description" in theVideo) { theHTML += '<div>'+VSUTIL.escapeHTML(theVideo.description)+'</div>'; }
		
		if ("referrerPageUrl" in theVideo) { theHTML += '<br>Referrer Page: <a href="'+VSUTIL.escapeHTMLString(theVideo.referrerPageUrl)+'" target=_blank>'+VSUTIL.escapeHTML(VSUTIL.truncateString(theVideo.referrerPageUrl, 100))+'</a> '; }
		
		theHTML += '</td>';
		theHTML += '</tr>';
		if ("thumbnailUrlLarge" in theVideo) { theHTML += '<tr><td class="label"><nobr>Video Screenshot:</nobr></td><td ><a href="javascript:getChannelUrl(\''+theVideo.channelUrl+'\'); playVideo(\''+theVideo.videoUrl+'\','+theVideo.id+'); void(0);"><img align="left" src="'+theVideo.thumbnailUrlLarge+'" class="thumbnailbig" alt="click to play video"/></a></td></tr>'; }
		if ("id" in theVideo) { theHTML += '<tr><td class="label"><nobr>Id:</nobr></td><td>'+theVideo.id+'</td></tr>'; }
		if (("channel" in theVideo) && ("channelUrl" in theVideo)) { theHTML += '<tr><td class="label"><nobr>Channel:</nobr></td><td><a href="'+VSUTIL.escapeHTMLString(theVideo.channelUrl)+'" target=_blank>'+VSUTIL.escapeHTML(theVideo.channel)+'</a></td></tr>'; }
		if ("dateFound" in theVideo) { theHTML += '<tr><td class="label"><nobr>Date Added:</nobr></td><td> '+VSUTIL.getDateString(theVideo.dateFound)+' </td></tr>'; }
		if ("vRank" in theVideo) { theHTML += '<tr><td class="label"><nobr>VRank:</nobr></td><td>'+theVideo.vRank+'</td></tr>'; }
		if ("textRelevancy" in theVideo) { theHTML += '<tr><td class="label"><nobr>Relevance rank:</nobr></td><td>'+theVideo.textRelevancy+'</td></tr>'; }
		
		if ("actor" in theVideo) { theHTML += '<tr><td class="label"><nobr>Starring:</nobr></td><td>'+VSUTIL.escapeHTML(theVideo.actor)+'</td></tr>'; }
		if ("director" in theVideo) { theHTML += '<tr><td class="label"><nobr>Directed By:</nobr></td><td>'+VSUTIL.escapeHTML(theVideo.director)+'</td></tr>'; }
		if ("writer" in theVideo) { theHTML += '<tr><td class="label"><nobr>Written By:</nobr></td><td>'+VSUTIL.escapeHTML(theVideo.writer)+'</td></tr>'; }
		if ("producer" in theVideo) { theHTML += '<tr><td class="label"><nobr>Produced By:</nobr></td><td>'+VSUTIL.escapeHTML(theVideo.producer)+'</td></tr>'; }
		if ("artist" in theVideo) { theHTML += '<tr><td class="label"><nobr>Artist:</nobr></td><td>'+VSUTIL.escapeHTML(theVideo.artist)+'</td></tr>'; }
		if ("album" in theVideo) { theHTML += '<tr><td class="label"><nobr>Album:</nobr></td><td>'+VSUTIL.escapeHTML(theVideo.album)+'</td></tr>'; }
		if ("distributor" in theVideo) { theHTML += '<tr><td class="label"><nobr>Distributed By:</nobr></td><td>'+VSUTIL.escapeHTML(theVideo.distributor)+'</td></tr>'; }
		if ("author" in theVideo) { theHTML += '<tr><td class="label"><nobr>Author:</nobr></td><td>'+VSUTIL.escapeHTML(theVideo.author)+'</td></tr>'; }
		if ("copyright" in theVideo) { theHTML += '<tr><td class="label"><nobr>Copyright:</nobr></td><td>'+VSUTIL.escapeHTML(theVideo.copyright)+'</td></tr>'; }
		if ("rating" in theVideo) { theHTML += '<tr><td class="label"><nobr>Rating:</nobr></td><td>'+VSUTIL.escapeHTML(theVideo.rating)+'</td></tr>'; }
		if ("runtime" in theVideo) { theHTML += '<tr><td class="label"><nobr>Runtime:</nobr></td><td>'+VSUTIL.getRuntimeString(theVideo.runtime)+'</td></tr>'; }
		if ("category" in theVideo) { theHTML += '<tr><td class="label"><nobr>Category:</nobr></td><td>'+VSUTIL.escapeHTML(theVideo.category)+'</td></tr>'; }
		if ("tags" in theVideo) { theHTML += '<tr><td class="label"><nobr>Tags:</nobr></td><td>'+VSUTIL.getTagsHTML(theVideo.tags, 100)+'</td></tr>'; }
		if (("showName" in theVideo) && ("showUrl" in theVideo)) { theHTML += '<tr><td class="label"><nobr>Show:</nobr></td><td><a href="'+VSUTIL.escapeHTMLString(theVideo.showUrl)+'">'+VSUTIL.escapeHTML(theVideo.showName)+'</a></td></tr>'; }
		if ("episodeName" in theVideo) { theHTML += '<tr><td class="label"><nobr>Episode Name:</nobr></td><td>'+VSUTIL.escapeHTML(theVideo.episodeName)+'</td></tr>'; }
		if ("episodeNumber" in theVideo) { theHTML += '<tr><td class="label"><nobr>Episode Number:</nobr></td><td>'+VSUTIL.escapeHTML(theVideo.episodeNumber)+'</td></tr>'; }
		if ("seasonNumber" in theVideo) { theHTML += '<tr><td class="label"><nobr>Season Number:</nobr></td><td>'+VSUTIL.escapeHTML(theVideo.seasonNumber)+'</td></tr>'; }
		if ("country" in theVideo) { theHTML += '<tr><td class="label"><nobr>Country:</nobr></td><td>'+theVideo.country+'</td></tr>'; }
		if ("language" in theVideo) { theHTML += '<tr><td class="label"><nobr>Language:</nobr></td><td>'+theVideo.language+'</td></tr>'; }
		if ("dateProduced" in theVideo) { theHTML += '<tr><td class="label"><nobr>Date Produced:</nobr></td><td>'+VSUTIL.escapeHTML(theVideo.dateProduced)+'</td></tr>'; }
		if ("live" in theVideo) { theHTML += '<tr><td class="label"><nobr>Live Stream:</nobr></td><td>'+(theVideo.live==1?'Yes':'No')+'</td></tr>'; }
		if ("editorsPick" in theVideo) { theHTML += '<tr><td class="label"><nobr>Featured Video:</nobr></td><td>'+(theVideo.editorsPick==1?'Yes':'No')+'</td></tr>'; }
		if ("viewCount" in theVideo) { theHTML += '<tr><td class="label"><nobr>View Count:</nobr></td><td>'+theVideo.viewCount+'</td></tr>'; }
		if ("favoriteCount" in theVideo) { theHTML += '<tr><td class="label"><nobr>Favorite Count:</nobr></td><td>'+theVideo.favoriteCount+'</td></tr>'; }
		if (("userRating" in theVideo) && ("userRatingCount" in theVideo)) { theHTML += '<tr><td class="label"><nobr>User Rating:</nobr></td><td>'+theVideo.userRating+' (rated '+theVideo.userRatingCount+' time'+(theVideo.userRatingCount==1?'':'s')+')</td></tr>'; }
		if ("quality" in theVideo) { theHTML += '<tr><td class="label"><nobr>Quality:</nobr></td><td>'+theVideo.quality+'</td></tr>'; }
		if ("formats" in theVideo) { theHTML += '<tr><td class="label"><nobr>Formats:</nobr></td><td>'+theVideo.formats+'</td></tr>'; }
		if ("bitrate" in theVideo) { theHTML += '<tr><td class="label"><nobr>Bitrate:</nobr></td><td>'+theVideo.bitrate+'</td></tr>'; }
		if ("width" in theVideo) { theHTML += '<tr><td class="label"><nobr>Video Width:</nobr></td><td>'+theVideo.width+' px</td></tr>'; }
		if ("height" in theVideo) { theHTML += '<tr><td class="label"><nobr>Video Height:</nobr></td><td>'+theVideo.height+' px</td></tr>'; }
		if ("fileSize" in theVideo) { theHTML += '<tr><td class="label"><nobr>File Size:</nobr></td><td>'+theVideo.fileSize+'</td></tr>'; }
		if ("frameRate" in theVideo) { theHTML += '<tr><td class="label"><nobr>Frame Rate:</nobr></td><td>'+theVideo.frameRate+'</td></tr>'; }
		if ("codec" in theVideo) { theHTML += '<tr><td class="label"><nobr>Video Codec:</nobr></td><td>'+VSUTIL.escapeHTML(theVideo.codec)+'</td></tr>'; }
		theHTML += '<tr><td></td><td>';
		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 += '</td></tr>';		
		theHTML += '<tr><td></td><td>';
		theHTML += '<nobr><a href="javascript:getVideos(\''+VSUTIL.escapeHTMLString(previousQuery)+'\'); void(0);">Back To Search Results</a></nobr>&nbsp;&nbsp;';
		theHTML += '|&nbsp;&nbsp;<wbr><nobr><a href="javascript:getVideos(\'sim:'+theVideo.id+'\'); void(0);">Show More Like This</a></nobr>&nbsp;&nbsp;';
		/*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><a href="javascript:addFavorite('+theVideo.id+'); void(0);">add to favorites</a></nobr>';
		}*/
		theHTML += '</td></tr>';		
		
		if ("embedTag" in theVideo) { theHTML += '<tr><td class="label"><nobr>Embed Tag:</nobr></td><td>'+theVideo.embedTag+'</td></tr>'; }
		
		theHTML += '</table>';
		theHTML += '</div>';
		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.escapeHTMLString(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); }
			else if (view == 1) { container.innerHTML = this.getVideoSetListHTML(VideoSet, aolvs.method); }
			else { container.innerHTML = this.getVideoSetDetailHTML(VideoSet, aolvs.method); }
		}
	}
}


// 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) {
		var theHTML = '';
		theHTML += '<table style="width: 100%; margin: 0 0 0 0; border: 0px; " cellpadding="0" cellspacing=0>';
		theHTML += '<tr>';
		var tempStr='';
		tempStr=VideoSet.title;
		if(tempStr.indexOf('title:')>=0){
			tempStr=tempStr.substring(0,parseInt(tempStr.indexOf('title:')));
		}
		
		//alert ("hello "+ VideoSet.title);
		//alert ("hi "+ tempStr);
		theHTML += '<td style="text-align: left;height=25; width=475">';
		theHTML += '<span class="header">' + VSUTIL.escapeHTML(tempStr) + '</span>';
		
		theHTML += '</td>';
		theHTML += '<td style="text-align: right; width="20" valign=top>';
		
		if (methodName.indexOf("truveo.videos.getVideos") >= 0) {
			theHTML += '&nbsp;&nbsp;<wbr><nobr>';
			if ("rssUrl" in VideoSet) { theHTML += '<a href=\''+VSUTIL.escapeHTMLString(VideoSet.rssUrl)+'\'><img border=0 src=\'/views/images/rss.gif\'/></a>'; }
			theHTML += '<a href="javascript:addWatchlist(\''+VSUTIL.escapeHTMLString(query)+'\'); void(0);"></a>';
			theHTML += '</nobr>';
		}
		else if (methodName.indexOf("truveo.users.getRecentVideos") >= 0) {
			theHTML += '&nbsp;&nbsp;<wbr><nobr>(';
			theHTML += '<a href="javascript:clearRecentVideos(); void(0);">clear recent videos</a>';
			theHTML += ')</nobr>';
		}
				
		theHTML += '</td>';
		theHTML += '</tr></table>';
		//for 1,2,3,4....paging...
		var totPages=0;
//		alert ("per page :"+parseInt(VideoSet.totalResultsReturned));	
		if(!window.ResultPerPage){window.ResultPerPage=50;}
		
		totPages=Math.ceil(parseInt(VideoSet.totalResultsAvailable)/ window.ResultPerPage);
			//alert(VideoSet.totalResultsAvailable + ">>>>" +totPages);
		var arrPageNos=this.paging(totPages);// get a array of page no to display on top as 1,2,3,4,5,.......
		
		//theHTML += (parseInt(VideoSet.firstResultPosition) + 1) + ' to ' + (parseInt(VideoSet.firstResultPosition) + parseInt(VideoSet.totalResultsReturned)) + ' of ' + VideoSet.totalResultsAvailable;
		theHTML += '<table style="width: 100%; margin: 0 0 0 0; border: 0px; border-style: none; border-collapse: collapse;" cellpadding="0" cellspacing=0>';
			
		theHTML += '<tr>';
		theHTML += '<td style="text-align: left;">';
		//theHTML += (parseInt(VideoSet.firstResultPosition) + 1) + ' to ' + (parseInt(VideoSet.firstResultPosition) + parseInt(VideoSet.totalResultsReturned)) + ' of ' + VideoSet.totalResultsAvailable;
		//theHTML += '<b>Page: '+ window.HitNo +' of '+ totPages +'</b>';
		theHTML += ''+(parseInt(VideoSet.firstResultPosition) + 1) + ' to ' + (parseInt(VideoSet.firstResultPosition) + parseInt(VideoSet.totalResultsReturned)) + ' of ' + VideoSet.totalResultsAvailable;
		theHTML += '</td>';
		theHTML += '<td style="text-align: right;"><span class="pagination">';
		
		
		window.bbb=arrPageNos[1] - 1;
		
		
		if (hasPreviousPage() && window.HitNo-4 >= 7  ) { theHTML += '<a href="javascript:goToPage('+window.bbb+');  void(0);getNumber('+window.bbb+');"> Previous </a> |'; } else { theHTML += '&nbsp;'; }
		//theHTML += '</td>';
		//theHTML += '<td style="text-align: right;">';
	
		var i=1;

		//alert(arrPageNos.length);
		knt=Math.ceil(VideoSet.totalResultsAvailable/50)+1;

		while(i<arrPageNos.length){
		 if ( arrPageNos[i] == window.HitNo)
		 {
	   theHTML += '<span style="width:5px;text-decoration: none; color:red; background-color:#FFFFCC;">'+arrPageNos[i]+'</span>|';			
		}
		else
			{
				theHTML += '<a href="javascript:goToPage('+arrPageNos[i]+'); void(0);getNumber('+arrPageNos[i]+');">'+arrPageNos[i]+'</a>|';		
			}
		i++;
			if(i>=knt) 	break;
	
		}
		window.ii=i-1;
		window.iii=arrPageNos[window.ii] + 1;
		if (hasNextPage() && totPages > 10 ) { theHTML += '&nbsp;<a href="javascript:goToPage('+window.iii+'); void(0);getNumber('+window.iii+');">Next </a> '; } else { theHTML += '&nbsp;'; }
		theHTML += '</span></td>';
		theHTML += '</tr>';		
		theHTML += '</table>';
		return(theHTML);
	}
	//function for paging .......
	this.paging =function(maxPages){
		if(!window.HitNo){window.HitNo=1; }
		
		upLimit=1;
		loLimit=1;
		arrPages=new Array(9); // so this can store 10 elements
		if(window.HitNo<=10 && maxPages>=10){
			loLimit=1;
			upLimit=10;
		}else if(window.HitNo<10 && maxPages<10){
			loLimit=1;
			upLimit=maxPages;			
			arrPages=new Array(maxPages); 
		}else if(window.HitNo>maxPages-10){
			loLimit=maxPages-10;
			upLimit=maxPages;
		}else{
			loLimit=window.HitNo-4;
			upLimit=window.HitNo+5;
		}
		var i;
		var j=1;
		for(i=loLimit; i<=upLimit	; i++){
			arrPages[j]=i;
			j++;
		}
		return arrPages;
	}
	// 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); }
		}
	}
}


// 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;
				if(channelName=="Clevver Music" || channelName=="Clevver Movies"){
					theHTML += '<div class="menuHeader"><nobr><a href="javascript:getVideosByChannel(\''+VSUTIL.escapeHTMLString(channelName)+'\'); void(0);"><u>'+VSUTIL.escapeHTML(VSUTIL.truncateString(channelName, charLimit))+' ('+channelCount+')</u></a></nobr></div>';
				}else{
				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 += '<a href="javascript:logout(); void(0);"></a>'; }
		else { theHTML += '<a href="javascript:login(); void(0);"></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(theTag)+'</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);
	}
}

	getNumber= function(n){
		window.HitNo=n;
	}
	
	//this will sort your result for clevver if there is any clevver's record on result page then clevver record will appear first.
	sortClevver = function(vset){
		var clevverVideo = Object ();
		var otherVideo = Object ();
		var allVideo = Object ();
		var intClevverCounter = 0;
		var intOtherCounter = 0;
		var i=0;
		var j=0;
		for (i=0; i < vset.totalResultsReturned; i++) {
			if((vset.Video[i].channel=='Clevver Movies') ||(vset.Video[i].channel=='Clevver Music')) {
				clevverVideo[intClevverCounter]=vset.Video[i];
				intClevverCounter++;
			}else{
				otherVideo[intOtherCounter]=vset.Video[i];
				intOtherCounter++;
			}
		}
		for(i=0; i<intClevverCounter; i++){
			allVideo[i] = clevverVideo[i];
		}
		for(j=0; j<intOtherCounter; j++){
			allVideo[i] = otherVideo[j];
			i++;
		}
		return allVideo;
	}

VSUTIL = new VSUtilities();

//-->

























//<![CDATA[
// Global Variables:
var AOLVS = null;			// The global variable for the AOLVideoSearch object used in this application.
var VIDEO_PANEL = null;		// The global variable for the view object used to display the video search results.
var TITLE_BAR = null; 		// The global variable for the view object used to display a title bar for a set of video search results.
var FOOTER_BAR = null;		// The global variable for the view object used to display a footer bar for a set of video search results.
var CATEGORY_MENU = null; 	// The global variable for the view object used to display a menu of related categories.
var CHANNEL_MENU = null; 	// The global variable for the view object used to display a menu of related channels.
var TAG_MENU = null; 		// The global variable for the view object used to display a menu of related tags.
var USER_MENU = null; 		// The global variable for the view object used to display a menu of related users.
var LOGIN_BUTTON = null;	// The global variable for the stateful login button.

// The following functions are handlers for the buttons and links provided in the application.
// Function getVideos() submits the given query to the AOL video search engine.  The optional argument
// start specifies the position of the first video in the total set of matching videos.




function getVideos(query, start) { 
if (query == " title: ")
		query="";		
	AOLVS.results=50;
	window.HitNo=1;
	VIDEO_PANEL.displayMessage('loading...');
	if (arguments.length < 1) { AOLVS.getVideos(); }
	else if (arguments.length < 2) { AOLVS.getVideos(query); }
	else { AOLVS.getVideos(query, start); }
}
// Function getVideosByCategory() modifies the current query to include the provided category filter and retrieves a new set of videos.
function getVideosByCategory(category) {
	if (category.toLowerCase() == 'all') { 
		var query = AOLVS.query;
		query = query.replace(/\s?category:"[^"]*"/gi, "");
		query = query.replace(/\s?category:\S*/gi, "");
		getVideos(query); 
	}
	else { 
		var query = AOLVS.query;
		var theRegExp = new RegExp('\\s?category:"\\s*'+VSUTIL.escapeRegExp(category)+'\\s*"', "gi");
		query = query.replace(theRegExp, "");
		theRegExp = new RegExp('\\s?category:'+VSUTIL.escapeRegExp(category), "gi");
		query = query.replace(theRegExp, "");
		getVideos(query + ' category:"' + category + '"'); 
	}
}
// Function getVideosByChannel() modifies the current query to include the provided channel filter and retrieves a new set of videos.
function getVideosByChannel(channel) {
	if (channel.toLowerCase() == 'all') { 
		var query = AOLVS.query;
		query = query.replace(/\s?channel:"[^"]*"/gi, "");
		query = query.replace(/\s?channel:\S*/gi, "");
		getVideos(query); 
	}
	else { 
		var query = AOLVS.query;
		var theRegExp = new RegExp('\\s?channel:"\\s*'+VSUTIL.escapeRegExp(channel)+'\\s*"', "gi");
		query = query.replace(theRegExp, "");
		theRegExp = new RegExp('\\s?channel:'+VSUTIL.escapeRegExp(channel), "gi");
		query = query.replace(theRegExp, "");
		getVideos(query + ' channel:"' + channel + '"'); 
	}
}
// Function getVideosByTag() modifies the current query to include the provided tag filter and retrieves a new set of videos.
function getVideosByTag(tag) {
	if (tag.toLowerCase() == 'all') { 
		var query = AOLVS.query;
		query = query.replace(/\s?tag:"[^"]*"/gi, "");
		query = query.replace(/\s?tag:\S*/gi, "");
		getVideos(query); 
	}
	else { 
		var query = AOLVS.query;
		var theRegExp = new RegExp('\\s?tag:"\\s*'+VSUTIL.escapeRegExp(tag)+'\\s*"', "gi");
		query = query.replace(theRegExp, "");
		theRegExp = new RegExp('\\s?tag:'+VSUTIL.escapeRegExp(tag), "gi");
		query = query.replace(theRegExp, "");
		getVideos(query + ' tag:"' + tag + '"'); 
	}
}
// Function getVideosByUser() modifies the current query to include the provided user filter and retrieves a new set of videos.
function getVideosByUser(user) {
	if (user.toLowerCase() == 'all') { 
		var query = AOLVS.query;
		query = query.replace(/\s?user:"[^"]*"/gi, "");
		query = query.replace(/\s?user:\S*/gi, "");
		getVideos(query); 
	}
	else { 
		var query = AOLVS.query;
		var theRegExp = new RegExp('\\s?user:"\\s*'+VSUTIL.escapeRegExp(user)+'\\s*"', "gi");
		query = query.replace(theRegExp, "");
		theRegExp = new RegExp('\\s?user:'+VSUTIL.escapeRegExp(user), "gi");
		query = query.replace(theRegExp, "");
		getVideos(query + ' user:"' + user + '"'); 
	}
}
// Function nextPage() displays the next page of videos in the current VideoSet.
function nextPage() {
	VIDEO_PANEL.displayMessage('loading...');
	AOLVS.nextPage()
}
// Function previousPage() displays the previous page of videos in the current VideoSet.
function previousPage() {
	VIDEO_PANEL.displayMessage('loading...');
	AOLVS.previousPage()
}
// Function goToPage() displays the page of videos, specified by pageNum, in the current VideoSet.
function goToPage(pageNum) {
	VIDEO_PANEL.displayMessage('loading...');
	AOLVS.goToPage(pageNum)
}
// Function hasNextPage() returns true if a next page of video results is available.
function hasNextPage() { return(AOLVS.hasNextPage()); }
// Function hasNextPage() returns true if a previous page of video results is available.
function hasPreviousPage() { return(AOLVS.hasPreviousPage()); }
// Function sortBy() modifies the query string to include the provided sort option and retrieves a new set of videos.
function sortBy(sortOption) { getVideos(AOLVS.query.replace(/\s?sort:\S*/gi, "") + " sort:" + sortOption); }
// Function filterType() modifies the query string to include the provided type filter and retrieves a new set of videos.
function filterType(type) { 
	var query = AOLVS.query.replace(/\s?type:\S*/gi, "");
	if (type == 'all') { getVideos(query); }
	else { getVideos(query + " type:" + type); }
}
// Function filterRuntime() modifies the query string to include the specified runtime filter and retrieves a new set of videos.
function filterRuntime(runtime) { 
	var query = AOLVS.query.replace(/\s?runtime:\S*/gi, "");
	switch(runtime) {
		case 'short': getVideos(query + " runtime:<2"); break;
		case 'medium': getVideos(query + " runtime:>2 AND runtime:<10"); break;
		case 'long': getVideos(query + " runtime:>10"); break;
		default: getVideos(query); break;
	}
}
// Function filterQuality() modifies the query string to include the provided quality filter and retrieves a new set of videos.
function filterQuality(quality) { 
	var query = AOLVS.query.replace(/\s?quality:\S*/gi, "");
	if (quality == 'all') { getVideos(query); }
	else { getVideos(query + " quality:" + quality); }
}
// Function filterFormat() modifies the query string to include the provided format filter and retrieves a new set of videos.
function filterFormat(format) { 
	var query = AOLVS.query.replace(/\s?format:\S*/gi, "");
	if (format == 'all') { getVideos(query); }
	else { getVideos(query + " format:" + format); }
}
// Function setStyle() sets the CSS style to apply to the video results.
function setStyle(styleName) {
	document.getElementById('bodyDiv').className = styleName; 
	setStyleBtn();
}
// Function setView() sets the type of view (e.g. grid, list or detail) of the video results to display.
function setView(value) {
	VIDEO_PANEL.setView(value); 
	setViewBtn();
	VIDEO_PANEL.refresh(AOLVS);
}
// Function setVideosPerPage() sets the number of videos to retrieve in each page of results.
function setVideosPerPage(numVideos) {
	AOLVS.results = numVideos;
	window.ResultPerPage=numVideos; //sanjeev
	//setVideosPerPageBtn();
	getVideos(AOLVS.query, AOLVS.start);
}
// Function setShowAdult() turns on or off the family filter and retrieves a new set of videos.
function setShowAdult(value) { 
	AOLVS.showAdult = value;
	setShowAdultBtn();
	getVideos(AOLVS.query);
}
// Function submitRating() submits the rating integer (1-5) for the video with the specified id value.
function submitRating(videoId, rating) { AOLVS.submitRating(videoId, rating); }
// Function login() signs the user into the AOL video search service.
function login() {
	saveState();
	AOLVS.login(window.location.href);
}
// Function logout() signs the user out of the AOL video search service.
function logout() { 
	saveState();
	AOLVS.logout(window.location.href);
}
// Function getFavoriteVideos() retrieves the user's favorite videos, if any have been saved.
function getFavoriteVideos() { AOLVS.getFavoriteVideos(); }
// Function addFavorite() adds the video with the submitted id to the user's favorites list.
function addFavorite(id) { AOLVS.addFavorite(id); }
// Function removeFavorite() removes the video with the submitted id from your favorites list.
function removeFavorite(id) { AOLVS.removeFavorite(id); }
// Function getRecentVideos() retrieves the user's recently viewed videos.
function getRecentVideos() { AOLVS.getRecentVideos(); }
// Function addRecentVideo() adds the video with the submitted id to your recent videos list.
function addRecentVideo(id) { AOLVS.addRecentVideo(id); }
// Function clearRecentVideos() removes all videos from the recent videos list.
function clearRecentVideos() {
	if (confirm("Click 'OK' to confirm that you would like to delete all of your recent videos.")) {
		AOLVS.clearRecentVideos();
	}
}
// Function getWatchlists() retrieves the user's watchlists, if any have been saved.
function getWatchlists() { AOLVS.getWatchlists(); }
// Function addWatchlist() adds the specified search query to the user's watchlists.
function addWatchlist(query) { AOLVS.addWatchlist(query); }
// Function removeWatchlist() removes the specified query from your watchlists.
function removeWatchlist(query) { AOLVS.removeWatchlist(query); }
// Function playVideo() adds the video with the specified id to the recent videos list (if logged in) and then
// opens a new browser window to load the specified videoUrl.

//function getChannelUrl() retrive the channelurl of selected video if it is on clevver.com then it will play in same window otherwise it will play another window.

var CHANNEL_URL = null; //global variable to store channnel url that: it is on clevver.com or other
function getChannelUrl(channelUrl){
	channelUrl=channelUrl.toLowerCase();
	CHANNEL_URL=channelUrl;
}


function playVideo(videoUrl, id) {
	addRecentVideo(id);
	if(CHANNEL_URL!=null){
		if(CHANNEL_URL.indexOf("clevver")>0){
			window.location =videoUrl;
		}else{
			window.open(videoUrl, '', 'width=800,height=800,location=no,menubar=no,resizable=yes,scrollbars=yes');
		}
	}else{
		window.open(videoUrl, '', 'width=800,height=800,location=no,menubar=no,resizable=yes,scrollbars=yes');
	}
}

// Function handleUpdate() handles all response messages from the AOLVideoSearchAPI.  Whenever the AOLVideoSearchAPI
// receives a response to an AJAX request, it fires the onupdate event.  This method handles each onupdate event.
function handleUpdate(methodName) {
	if ((methodName == 'getVideos') || (methodName == 'getFavoriteVideos') || (methodName == 'getRecentVideos')) {
		TITLE_BAR.refresh(AOLVS);
		FOOTER_BAR.refresh(AOLVS);
		
		tempStr=AOLVS.query;		                    
	  if(tempStr.indexOf('channel:"clevver')>=0){			
			tempStr=tempStr.substring(0,parseInt(tempStr.indexOf('channel:"clevver')));
		}
		document.getElementById('searchBox').value = tempStr;//AOLVS.query
		//document.getElementById('searchBox').value = AOLVS.query;
		//document.getElementById('searchBox').value = 'clevver';
		
		// If there are not videos in the returned VideoSet, then display a helpful message.
		// Otherwise, if this is a 'show details' query for a single video, then show the full view of the video record.  
		// Otherwise, display the standard grid, list or detail view.
		if ((AOLVS.VideoSet) && (AOLVS.VideoSet.totalResultsReturned == 0) || !(AOLVS.VideoSet.Video) || (AOLVS.VideoSet.Video.length == 0)) {
			VIDEO_PANEL.displayMessage('There are no videos available.');
			CATEGORY_MENU.clear();
			CHANNEL_MENU.clear();
			TAG_MENU.clear();
			USER_MENU.clear();
		}
		else if ((AOLVS.VideoSet) && (AOLVS.VideoSet.totalResultsAvailable == 1) && (AOLVS.query) && (AOLVS.query.indexOf("id:") >= 0)) {
			VIDEO_PANEL.displayFullView(AOLVS, AOLVS.previousQuery);
			CATEGORY_MENU.clear();
			CHANNEL_MENU.clear();
			TAG_MENU.clear();
			USER_MENU.clear();
		}
		else {
			VIDEO_PANEL.refresh(AOLVS);
			if ((methodName == 'getFavoriteVideos') || (methodName == 'getRecentVideos')) {
				CATEGORY_MENU.clear();
				CHANNEL_MENU.clear();
				TAG_MENU.clear();
				USER_MENU.clear();
			}
			else {
				CATEGORY_MENU.refresh(AOLVS.CategorySet);
				CHANNEL_MENU.refresh(AOLVS.ChannelSet);
				TAG_MENU.refresh(AOLVS.TagSet);
				USER_MENU.refresh(AOLVS.UserSet);
			}
		}
	}
	else if (methodName == 'submitRating') {
		alert(AOLVS.Result.message + " (User rating: " + AOLVS.Result.userRating + ", User rating count: " + AOLVS.Result.userRatingCount +")");
	}
	else if (methodName == 'addFavorite') {
		alert(AOLVS.Result.message);
	}
	else if (methodName == 'removeFavorite') {
		getFavoriteVideos();
	}
	else if (methodName == 'clearRecentVideos') {
		getRecentVideos();
	}
	else if (methodName == 'getWatchlists') {
		TITLE_BAR.displayTitle('My Watchlists');
		FOOTER_BAR.displayTitle('My Watchlists');
		VIDEO_PANEL.displayWatchlists(AOLVS);
		CATEGORY_MENU.clear();
		CHANNEL_MENU.clear();
		TAG_MENU.clear();
		USER_MENU.clear();
	}
	else if (methodName == 'addWatchlist') {
		alert(AOLVS.Result.message);
	}
	else if (methodName == 'removeWatchlist') {
		getWatchlists();
	}
	LOGIN_BUTTON.refresh(AOLVS.isLoggedIn());
}
// Function handleLoad() handles the onload event, which is fired when the loading of the AOLVideoSearch object is complete.
// This function has one argument, reloadStateFlag, which is set to true if the API state has been reloaded.  This occurs
// following a login, logout or a cancelled login attempt.
//function handleLoad(reloadStateFlag) {
//	if (reloadStateFlag) { 
//		loadState();
//		getVideos(AOLVS.query, AOLVS.start);
//	}
//	else { 
//		
//+++GETVIDCALL+++
//		getVideos();
//		
//		 }
//}

// Function handleError() handles all errors thrown by the AOLVideoSearch API.  It displays an alert box with the
// error code and error message.
function handleError(errorCode, errorMessage) {
	alert("ERROR: Code " + errorCode + "; " + errorMessage);
}

// Function VSLoad() is called when the containing web page has completed loading.  This function instantiates a single AOLVideoSearch
// object, sets the state of the object, attaches the appropriate event handlers to this object, and then initializes the object. 
// This function also instantiates any view objects that are used to display search results and other UI features.
function VSLoad() {
	VIDEO_PANEL = new VideoPanel1("VideoPanelViewDiv");
	TITLE_BAR = new TitleBar1("TitleBarDiv");
	FOOTER_BAR = new TitleBar1("FooterBarDiv");
	CATEGORY_MENU = new CategoryMenu1("CategoryMenuDiv");
	CHANNEL_MENU = new ChannelMenu1("ChannelMenuDiv");
	TAG_MENU = new TagMenu1("TagMenuDiv");
	USER_MENU = new UserMenu1("UserMenuDiv");
	LOGIN_BUTTON = new LoginButton1("LoginButton");
	AOLVS = new AOLVideoSearch('2k3unnv8fpq429cvb');
	AOLVS.showRelatedItems = 1;
	AOLVS.attachEvent('onerror', 'handleError(errorCode, errorMessage);');
	AOLVS.attachEvent('onupdate', 'handleUpdate(methodName);');
	AOLVS.attachEvent('onload', 'handleLoad(reloadStateFlag);');
	AOLVS.initialize();
}

// Function setStyleBtn() sets the state of the style toggle button.
function setStyleBtn() {
	var styleName = document.getElementById('bodyDiv').className;
	switch(styleName) {
		case 'style1':
			document.getElementById('style1Btn').style.textDecoration = "underline"; 
			document.getElementById('style2Btn').style.textDecoration = "none"; 
			document.getElementById('style3Btn').style.textDecoration = "none"; 
			break;
		case 'style2': 
			document.getElementById('style1Btn').style.textDecoration = "none"; 
			document.getElementById('style2Btn').style.textDecoration = "underline"; 
			document.getElementById('style3Btn').style.textDecoration = "none"; 
			break;
		case 'style3': 
			document.getElementById('style1Btn').style.textDecoration = "none"; 
			document.getElementById('style2Btn').style.textDecoration = "none"; 
			document.getElementById('style3Btn').style.textDecoration = "underline"; 
			break;	
	}
}

// Function setViewBtn() sets the state of the view toggle button.
function setViewBtn() {
	switch(parseInt(VIDEO_PANEL.getView())) {
		case 0: 
			document.getElementById('gridBtn').style.textDecoration = "underline"; 
			document.getElementById('listBtn').style.textDecoration = "none"; 
			document.getElementById('detailBtn').style.textDecoration = "none"; 
			break;
		case 1: 
			document.getElementById('gridBtn').style.textDecoration = "none"; 
			document.getElementById('listBtn').style.textDecoration = "underline"; 
			document.getElementById('detailBtn').style.textDecoration = "none"; 
			break;
		case 2: 
			document.getElementById('gridBtn').style.textDecoration = "none"; 
			document.getElementById('listBtn').style.textDecoration = "none"; 
			document.getElementById('detailBtn').style.textDecoration = "underline"; 
			break;
	}
}

// Function setVideosPerPageBtn() sets the state of the videos per page toggle button.
function setVideosPerPageBtn() {
	switch(parseInt(AOLVS.results)) {
		case 10: 
			document.getElementById('10Btn').style.textDecoration = "underline"; 
			document.getElementById('20Btn').style.textDecoration = "none"; 
			document.getElementById('50Btn').style.textDecoration = "none"; 
			break;
		case 20: 
			document.getElementById('10Btn').style.textDecoration = "none"; 
			document.getElementById('20Btn').style.textDecoration = "underline"; 
			document.getElementById('50Btn').style.textDecoration = "none"; 
			break;
		case 50: 
			document.getElementById('10Btn').style.textDecoration = "none"; 
			document.getElementById('20Btn').style.textDecoration = "none"; 
			document.getElementById('50Btn').style.textDecoration = "underline"; 
			break;
	}
}

// Function setShowAdultBtn() sets the state of the family filter toggle button.
function setShowAdultBtn() {
	if (AOLVS.showAdult == 1) {
		document.getElementById('familyFilterOffBtn').style.textDecoration = "underline";
		document.getElementById('familyFilterOnBtn').style.textDecoration = "none";
	}
	else {
		document.getElementById('familyFilterOffBtn').style.textDecoration = "none";
		document.getElementById('familyFilterOnBtn').style.textDecoration = "underline";
	}
}

// Function saveState() saves application state to a cookie, so that it can be reloaded later if the user returns to this page.
function saveState() {
	var stateCookie = new Cookie(document, "app1_state");
	stateCookie.style = document.getElementById('bodyDiv').className;
	stateCookie.view = VIDEO_PANEL.getView();
	stateCookie.store();
}

// Function loadState() restores the application state from the stateCookie.
function loadState() {

	// Load the state from the cookie and update the application state based on the cookie values.
	var stateCookie = new Cookie(document, "app1_state");
	if (stateCookie.load()) {
		document.getElementById('bodyDiv').className = stateCookie.style; 
		VIDEO_PANEL.setView(stateCookie.view); 
		stateCookie.remove();
	}

	// Update the display of the stateful toggle buttons.
	setStyleBtn();
	setViewBtn();
	//setVideosPerPageBtn();
	setShowAdultBtn();
}


function process_qry(ss) {
 	  getVideos(ss);	
}