	/*
		DaapiDiscoveryWidget by Erik Noble
		version 0.13; Last modified on 02/17/2009
	
		Maybe: Vary output based on input. i.e. Show counts for recommended or most commented, but not for recent.
		Maybe: Template in property bag?
		Maybe: Improve input validation
		Maybe: Check for/handle the server being down?
		Maybe: Check for/handle invalid OutputDiv
		Maybe: Implement CreateAbstract
		Maybe: Implement AbstractSize input option

		Q: Validate Activity/ContentType combinations?
		Q: Placeholder if not GalleryPromo? Pull first image (like Tribal)?
	*/
	function DaapiDiscoveryWidget(serverUrl) {
		this.AbstractSize = 150;
		this.debug = false;
		this.SID = "";
		this.isUrl = function(s) {
			var regexp = /https?:\/\/(\w+:{0,1}\w*@)?(\S+)(:[0-9]+)?(\/|\/([\w#!:.?+=&%@!\-\/]))?/
			return regexp.test(s);
		}
		if (serverUrl != null && serverUrl != "" && this.isUrl(serverUrl)) {
			this.serverUrl = serverUrl;
		} else if (typeof gSiteLife != "undefined") { //Check for the existence of SiteLifeProxy so we can build it ourself.
			this.serverUrl = gSiteLife.__baseUrl + "/Direct/Process";
		} else {
			var siteLifeServer = "sitelife"; //the best we can do is guess now.
			var tld = document.domain.replace(/[^\.]*\.([^\.]+\.[^\.]{2,3})/g,"$1");
			this.serverUrl = "http://" + siteLifeServer + "." + tld + "/" + "ver1.0/Direct/Process";
		}
	}
	
	DaapiDiscoveryWidget.prototype.HandleDiscoveryResponse = function(paramBag, responseBatch) {
		contentType = paramBag.contentType;
		activity =  paramBag.activity;
	
		if (typeof(console) != 'undefined' && navigator.userAgent.indexOf("Safari") < 0 && this.debug) {		//Firebug debug
		    console.group("Response: HandleDiscoveryResponse - " + activity + " " + contentType);
		    console.dir(responseBatch);
		    console.groupEnd();
		}
		if (responseBatch.Responses[0].DiscoverContentAction.DiscoveredContent.length == 0) {
											this.HandleDiscoveryResponse_NoResults			(paramBag, responseBatch);
		} else {
			switch(contentType) {
				case "Article":				this.HandleDiscoveryResponse_Article			(paramBag, responseBatch);		break;
				case "BlogPost":			this.HandleDiscoveryResponse_BlogPost			(paramBag, responseBatch);		break;
				case "CommunityGroup":		this.HandleDiscoveryResponse_CommunityGroup		(paramBag, responseBatch);		break;
				case "Discussion":			this.HandleDiscoveryResponse_Discussion			(paramBag, responseBatch);		break;
				case "GroupBlog":			this.HandleDiscoveryResponse_GroupBlog			(paramBag, responseBatch);		break;
				case "Persona":				this.HandleDiscoveryResponse_Persona			(paramBag, responseBatch);		break;
				case "PublicBlog":			this.HandleDiscoveryResponse_PublicBlog			(paramBag, responseBatch);		break;
				case "PublicPhoto":			this.HandleDiscoveryResponse_PublicPhoto		(paramBag, responseBatch);		break;
				case "PublicPhotoGallery":	this.HandleDiscoveryResponse_PublicPhotoGallery	(paramBag, responseBatch);		break;
				case "PublicVideo":			this.HandleDiscoveryResponse_PublicVideo		(paramBag, responseBatch);		break;
				case "PublicVideoGallery":	this.HandleDiscoveryResponse_PublicVideoGallery	(paramBag, responseBatch);		break;
				case "UserBlog":			this.HandleDiscoveryResponse_UserBlog			(paramBag, responseBatch);		break;
				case "UserPhoto":			this.HandleDiscoveryResponse_UserPhoto			(paramBag, responseBatch);		break;
				case "UserPhotoGallery":	this.HandleDiscoveryResponse_UserPhotoGallery	(paramBag, responseBatch);		break;
				default:					alert("Unknown Content Type.");
			}
		}
	}

	DaapiDiscoveryWidget.prototype.HandleDiscoveryResponse_NoResults = function(paramBag, responseBatch) {
		var outputHTML = "";
		outputHTML += "<ol><li>No " + paramBag.activity + " " + paramBag.contentType + " found.</li></ol>";
		document.getElementById(paramBag.miscParams.outputDiv).innerHTML = outputHTML;
	}
	
	DaapiDiscoveryWidget.prototype.HandleDiscoveryResponse_Article = function(paramBag, responseBatch) {
		/*
			discoveredContent[i].ArticleKey.Key
			discoveredContent[i].Categories[]
			discoveredContent[i].Comments.NumberOfComments
			discoveredContent[i].PageTitle
			discoveredContent[i].PageUrl
			discoveredContent[i].Ratings.AverageRating
			discoveredContent[i].Ratings.CurrentUserRating
			discoveredContent[i].Ratings.NumberOfRatings
			discoveredContent[i].Recommendations.CurrentUserHasRecommended
			discoveredContent[i].Recommendations.NumberOfRecommendations
			discoveredContent[i].Reviews.NumberOfReviews
			discoveredContent[i].Section.Name
		*/
		var outputHTML = "";
		var discoveredContent = responseBatch.Responses[0].DiscoverContentAction.DiscoveredContent;
		outputHTML += "<ol>";
		for (var i=0; i < discoveredContent.length; i++) {
			if (discoveredContent[i].PageTitle.length > 50) { 
				outputHTML += "<li><a href=\"" + discoveredContent[i].PageUrl + "\">" + discoveredContent[i].PageTitle.substr(0,48) + "...</a></li>";// ("+discoveredContent[i].Comments.NumberOfComments+")</li>";
			} else {
				outputHTML += "<li><a href=\"" + discoveredContent[i].PageUrl + "\">" + discoveredContent[i].PageTitle + "</a></li>";// ("+discoveredContent[i].Comments.NumberOfComments+")</li>";
			}
		}
		outputHTML += "</ol>";
		document.getElementById(paramBag.miscParams.outputDiv).innerHTML = outputHTML;
	}
	
	DaapiDiscoveryWidget.prototype.HandleDiscoveryResponse_BlogPost = function(paramBag, responseBatch) {
		/*
			discoveredContent[i].AbuseReportCount
			discoveredContent[i].AssociatedCommunityGroupKey
			discoveredContent[i].BlogKey.Key
			discoveredContent[i].BlogPostKey.Key
			discoveredContent[i].CurrentUserHasRecommended
			discoveredContent[i].CurrentUserHasReportedAbuse
			discoveredContent[i].IsPublished
			discoveredContent[i].NumberOfComments
			discoveredContent[i].NumberOfRecommendations
			discoveredContent[i].PostAuthor.[...] (User Object)
			discoveredContent[i].PostBody
			discoveredContent[i].PostTags
			discoveredContent[i].PostTitle
		*/
		var outputHTML = "";
		var discoveredContent = responseBatch.Responses[0].DiscoverContentAction.DiscoveredContent;
		outputHTML += "<ol>";
		for (var i=0; i < discoveredContent.length; i++) {
			outputHTML += "<li><a href=\"" + discoveredContent[i].Url + "\">" + discoveredContent[i].PostTitle + "</a></li>";
		}
		outputHTML += "</ol>";
		document.getElementById(paramBag.miscParams.outputDiv).innerHTML = outputHTML;
	}
	
	DaapiDiscoveryWidget.prototype.HandleDiscoveryResponse_CommunityGroup = function(paramBag, responseBatch) {
		alert("Template needed for CommunityGroup content type."); return false;
	}
	
	DaapiDiscoveryWidget.prototype.HandleDiscoveryResponse_Discussion = function(paramBag, responseBatch) {
		alert("Template needed for Discussion content type."); return false;
	}
	
	DaapiDiscoveryWidget.prototype.HandleDiscoveryResponse_GroupBlog = function(paramBag, responseBatch) {
		alert("Template needed for GroupBlog content type."); return false;
	}
	
	DaapiDiscoveryWidget.prototype.HandleDiscoveryResponse_Persona = function(paramBag, responseBatch) {
		alert("Template needed for Persona content type."); return false;
	}
	
	DaapiDiscoveryWidget.prototype.HandleDiscoveryResponse_PublicPhoto = function(paramBag, responseBatch) {
		alert("Template needed for PublicPhoto content type."); return false;
	}
	
	DaapiDiscoveryWidget.prototype.HandleDiscoveryResponse_PublicPhoto = function(paramBag, responseBatch) {
		/*
			discoveredContent[i].AbuseReportCount
			discoveredContent[i].AssociatedCommunityGroupKey
			discoveredContent[i].Author.[...] (User Object)
			discoveredContent[i].CreatedOn
			discoveredContent[i].CurrentUserHasRecommended
			discoveredContent[i].CurrentUserHasReportedAbuse
			discoveredContent[i].Description
			discoveredContent[i].GalleryKey.Key
			discoveredContent[i].Image.Full
			discoveredContent[i].Image.Large
			discoveredContent[i].Image.Medium
			discoveredContent[i].Image.RecentSlide
			discoveredContent[i].Image.Small
			discoveredContent[i].Image.Tiny
			discoveredContent[i].IsPendingApproval
			discoveredContent[i].NumberOfComments
			discoveredContent[i].NumberOfRecommendations
			discoveredContent[i].PhotoKey.Key
			discoveredContent[i].PhotoUrl
			discoveredContent[i].Tags
			discoveredContent[i].Title
		*/
		var outputHTML = "";
		var discoveredContent = responseBatch.Responses[0].DiscoverContentAction.DiscoveredContent;
		for (var i=0; i < discoveredContent.length; i++) {
			outputHTML += "<div class=\"tabphotolist\"><a href=\"" + discoveredContent[i].PhotoUrl + "\"><img src=\"" + discoveredContent[i].Image.Small + "\"> " + discoveredContent[i].Title + "</a> by <a href=\"" + discoveredContent[i].Author.PersonaUrl + "\">" + discoveredContent[i].Author.DisplayName + "</a><p>" + discoveredContent[i].Description + "</p><br class=\"clearfloat\"/></div>";
		}
		document.getElementById(paramBag.miscParams.outputDiv).innerHTML = outputHTML;
	}
	
	DaapiDiscoveryWidget.prototype.HandleDiscoveryResponse_PublicPhotoGallery = function(paramBag, responseBatch) {
		/*
			discoveredContent[i].AssociatedCommunityGroupKey
			discoveredContent[i].CreatedOn
			discoveredContent[i].CurrentUserHasRecommended
			discoveredContent[i].Description
			discoveredContent[i].GalleryKey.Key
			discoveredContent[i].GalleryPromo.Body
			discoveredContent[i].GalleryPromo.Image.Full
			discoveredContent[i].GalleryPromo.Image.Large
			discoveredContent[i].GalleryPromo.Image.Medium
			discoveredContent[i].GalleryPromo.Image.RecentSlide
			discoveredContent[i].GalleryPromo.Image.Small
			discoveredContent[i].GalleryPromo.Image.Tiny
			discoveredContent[i].GalleryPromo.PhotoKey
			discoveredContent[i].GalleryPromo.Title
			discoveredContent[i].GalleryType.Name
			discoveredContent[i].GalleryViewStage
			discoveredContent[i].MediaType.Name
			discoveredContent[i].NumberOfRecommendations
			discoveredContent[i].Permalink
			discoveredContent[i].Section
			discoveredContent[i].Tags
			discoveredContent[i].Title
		*/
		var outputHTML = "";
		var discoveredContent = responseBatch.Responses[0].DiscoverContentAction.DiscoveredContent;
		outputHTML += "<ol>";
		for (var i=0; i < discoveredContent.length; i++) {
			outputHTML += "<li><a href=\"" + discoveredContent[i].Permalink + "\">";
			if (discoveredContent[i].GalleryPromo.Image.Small != "" && discoveredContent[i].GalleryPromo.Image.Small != null) {outputHTML += "<img src=\"" + discoveredContent[i].GalleryPromo.Image.Small + "\"> "};
			outputHTML += discoveredContent[i].Title + "</a></li>";
		}
		outputHTML += "</ol>";
		document.getElementById(paramBag.miscParams.outputDiv).innerHTML = outputHTML;
	}
	
	DaapiDiscoveryWidget.prototype.HandleDiscoveryResponse_PublicVideo = function(paramBag, responseBatch) {
		/*
			discoveredContent[i].AbuseReportCount
			discoveredContent[i].AssociatedCommunityGroupKey
			discoveredContent[i].Author.[...] (User Object)
			discoveredContent[i].CreatedOn
			discoveredContent[i].CurrentUserHasRecommended
			discoveredContent[i].CurrentUserHasReportedAbuse
			discoveredContent[i].Description
			discoveredContent[i].GalleryKey.Key
			discoveredContent[i].IsPendingApproval
			discoveredContent[i].MediaID
			discoveredContent[i].NumberOfComments
			discoveredContent[i].NumberOfRecommendations
			discoveredContent[i].Tags
			discoveredContent[i].Title
			discoveredContent[i].VideoKey.Key
			discoveredContent[i].VideoState.Message
			discoveredContent[i].VideoState.State
			discoveredContent[i].VideoThumbnail
			discoveredContent[i].VideoUrl
		*/
		var outputHTML = "";
		var discoveredContent = responseBatch.Responses[0].DiscoverContentAction.DiscoveredContent;
		for (var i=0; i < discoveredContent.length; i++) {
			var videoLink = typeof paramBag.miscParams.videoPath == "undefined" ? discoveredContent[i].VideoUrl : paramBag.miscParams.videoPath.replace("<VideoKey.Key>",discoveredContent[i].VideoKey.Key);
			outputHTML += "<div class=\"tabphotolist\"><a href=\"" + videoLink + "\"><img src=\"" + discoveredContent[i].VideoThumbnail + "\" width=\"60\"> " + discoveredContent[i].Title + "</a> by <a href=\"" + discoveredContent[i].Author.PersonaUrl + "\">" + discoveredContent[i].Author.DisplayName + "</a><p>" + discoveredContent[i].Description + "</p><br class=\"clearfloat\"></div>";
		}
		document.getElementById(paramBag.miscParams.outputDiv).innerHTML = outputHTML;
	}
	
	DaapiDiscoveryWidget.prototype.HandleDiscoveryResponse_PublicVideoGallery = function(paramBag, responseBatch) {
		alert("Template needed for PublicVideoGallery content type."); return false;
	}
	
	DaapiDiscoveryWidget.prototype.HandleDiscoveryResponse_UserBlog = function(paramBag, responseBatch) {
		alert("Template needed for UserBlog content type."); return false;
	}
	
	DaapiDiscoveryWidget.prototype.HandleDiscoveryResponse_UserPhoto = function(paramBag, responseBatch) {
		alert("Template needed for UserPhoto content type."); return false;
	}
	
	DaapiDiscoveryWidget.prototype.HandleDiscoveryResponse_UserPhotoGallery = function(paramBag, responseBatch) {
		alert("Template needed for UserPhotoGallery content type."); return false;
	}
	
	DaapiDiscoveryWidget.prototype.HandleDiscoveryResponse_CreateAbstract = function(inputString, numChars) {
		if (inputString.length > 0) {
			numChars = numChars || inputString.length;
			var cleanString = this.HandleDiscoveryResponse_Clean(inputString);
			var abstractString = "";

			if (numChars >= cleanString.length) {
				abstractString = cleanString;
			} else {
				var testString = cleanString.substr(0,numChars);
				if (testString.lastIndexOf(" ") < 0) { //Whoops! We chopped off too much.
					abstractString = cleanString.substr(0,cleanString.indexOf(" ",numChars)) + "..."; //Go up to the first space
				} else {
					abstractString = testString.substr(0,testString.lastIndexOf(" ")) + "..."; //Stop at the last space
				}
			}
		} else {
			abstractString = inputString;
		}
		return abstractString;
	}
	
	DaapiDiscoveryWidget.prototype.HandleDiscoveryResponse_Clean = function(inputString, stripLtGt) {
		stripLtGt = stripLtGt || true;
		var removeHTMLTags = function(strInputCode,stripLtGt){
			/* This script and many more are available free online at The JavaScript Source!! http://javascript.internet.com
			Created by: Robert Nyman | http://robertnyman.com/ 
			Modifed by: B. Erik Noble */
			if (stripLtGt) {strInputCode = strInputCode.replace(/&(lt|gt);/g, function (strMatch, p1){return (p1 == "lt")? "<" : ">";});} //This line is optional, it replaces escaped brackets with real ones, i.e. &lt; is replaced with < and &gt; is replaced with >
			var strTagStrippedText = strInputCode.replace(/<\/?[^>]+(>|$)/g, " "); //Optional: Change space to empty string but then you might get words crammed together
			return strTagStrippedText;	
		}

		var clean = "";
		if(inputString.length>0){
	 	 	var clean = removeHTMLTags(inputString, stripLtGt);
			//Matt Mitchell's code
			//clean = clean.replace(/</g,"&lt;");
			//clean = clean.replace(/>/g,"&gt;");
			clean = clean.replace(/\u2019/g,"&#8217;");
			clean = clean.replace(/\u201C/g,"&#8220;");
			clean = clean.replace(/\u201D/g,"&#8221;");
			clean = clean.replace(/\r\n/g,"\n");
			clean = clean.replace(/\n/g,"<br />\n");
		}
		return clean;
	}

	DaapiDiscoveryWidget.prototype.Core = function(paramBag) {
		paramBag						= paramBag						|| {};
		paramBag.sections				= paramBag.sections				|| null;
		paramBag.categories				= paramBag.categories			|| null;
		paramBag.contributors			= paramBag.contributors			|| null;
		paramBag.activity				= paramBag.activity				|| "Recent";
		paramBag.contentType			= paramBag.contentType			|| "Article";
		paramBag.age					= paramBag.age					|| 15;
		paramBag.max					= paramBag.max					|| 10;
		paramBag.filterBySID			= paramBag.filterBySID			|| false;
		paramBag.parentKeys				= paramBag.parentKeys			|| null;
		paramBag.miscParams				= paramBag.miscParams			|| {};
		paramBag.miscParams.outputDiv	= paramBag.miscParams.outputDiv	|| "DDW_Output";
		
		if (typeof(console) != 'undefined' && navigator.userAgent.indexOf("Safari") < 0 && this.debug) {		//Firebug debug
			console.group("Debug: Core - " + paramBag.activity + " " + paramBag.contentType);
			console.dir(paramBag);
			console.groupEnd();
		}

		//One for the money
		var requestBatch =  new RequestBatch();
		
		//Two for the show
		var Disco_SearchSections		= (paramBag.sections		== null) ? new Array() : this.Core_BuildArray("sections",		paramBag.sections, 		paramBag.contentType);
		var Disco_SearchCategories		= (paramBag.categories		== null) ? new Array() : this.Core_BuildArray("categories",		paramBag.categories, 	paramBag.contentType);
		var Disco_LimitToContributors	= (paramBag.contributors	== null) ? new Array() : this.Core_BuildArray("contributors",	paramBag.contributors, 	paramBag.contentType);
		var Disco_ParentKeys			= (paramBag.parentKeys		== null) ? new Array() : this.Core_BuildArray("parentKeys",		paramBag.parentKeys, 	paramBag.contentType);
        
		//Three to get ready
		var Disco_Activity = new Activity(paramBag.activity);
        var Disco_ContentType = new ContentType(paramBag.contentType);
		var Disco_Age = paramBag.age;
		var Disco_MaximumNumberOfDiscoveries = paramBag.max;
		var Disco_FilterBySiteOfOrigin = paramBag.filterBySID;
		
		//Now go, cat, go.
        requestBatch.AddToRequest(new DiscoverContentAction(Disco_SearchSections, Disco_SearchCategories, Disco_LimitToContributors, Disco_Activity,  Disco_ContentType, Disco_Age, Disco_MaximumNumberOfDiscoveries, Disco_FilterBySiteOfOrigin, Disco_ParentKeys));
		var ProcessDiscoveryResponse = (function(paramBag, self) { //We make this an embedded function so that we still have the paramBag for reference. Phred is awesome.
			return function(responseBatch) {
				if (responseBatch.Messages[0].Message == "ok") {
					self.HandleDiscoveryResponse(paramBag, responseBatch);
				} else if (responseBatch.Messages[0].Message.indexOf("Parameter name: Age") > -1) { //Check for maxAge - Example: "Value:366 must be <= 365\r\nParameter name: Age"
					var maxAgeStart = responseBatch.Messages[0].Message.indexOf("must be <= ")+11;
					var maxAgeEnd = responseBatch.Messages[0].Message.indexOf("\r\nParameter name: Age");
					var maxAge = responseBatch.Messages[0].Message.substring(maxAgeStart,maxAgeEnd);
					paramBag.age = maxAge;
					if (typeof(console) != 'undefined' && navigator.userAgent.indexOf("Safari") < 0 && this.debug) { //Firebug debug
					    console.group("Error: ProcessDiscoveryResponse - MAXAGE");
					    console.dir(responseBatch);
					    console.groupEnd();
					}
					self.Core(paramBag);
				} else {
					alert("Error: "  + responseBatch.Messages[0].Message);
					if (typeof(console) != 'undefined' && navigator.userAgent.indexOf("Safari") < 0 && this.debug) { //Firebug debug
					    console.group("Error: ProcessDiscoveryResponse - UNKNOWN ERROR");
					    console.dir(responseBatch);
					    console.groupEnd();
					}
				}
			}
		})(paramBag, this);
		serverUrl = this.serverUrl || serverUrl;
		if (this.isUrl(serverUrl)) {
	        requestBatch.BeginRequest(serverUrl, ProcessDiscoveryResponse);
		} else {
			throw("DaapiDiscoveryWidget: Invalid Process URL.");
		}
	}
	
	DaapiDiscoveryWidget.prototype.Core_BuildArray = function(inputType, inputString, contentType) {
		switch (contentType) {
			case "PublicPhoto":
			case "PublicPhotoGallery":
			case "PublicVideo":
			case "UserPhoto":
				var inputArray = inputString.replace(/\s+,\s+/gi,",").split(",");
				break;
			default:
				var inputArray = inputString.replace(/,/gi," ").replace(/\s+/gi," ").split(" ");
		}
		
		var outputArray = new Array();
		
		for (var i=0; i < inputArray.length; i++) {
			switch (inputType) {
				case "sections":
					outputArray[i] = new Section(inputArray[i]);
					break;
				case "categories":
					outputArray[i] = new Category(inputArray[i]);
					break;
				case "contributors":
					outputArray[i] = new UserTier(inputArray[i]);
					break;
				case "parentKeys":
					if (unescape(inputArray[i]).indexOf("Forum:") == -1) { //Cat%3a624A7DAD-4F2A-4cd0-BB6E-DDFC51422846Forum%3aDEF69A7B-652A-4c0f-86E8-7158F0361917
						outputArray[i] = new ForumCategoryKey(inputArray[i]);
					} else {
						outputArray[i] = new ForumKey(inputArray[i]);
					}
					break;
				default:
					//Do nothing
			}
		}
		if (typeof(console) != 'undefined' && navigator.userAgent.indexOf("Safari") < 0 && this.debug) { //Firebug debug
			console.group("Debug: Core_BuildArray - " + inputType + ": " + inputString + " (" + contentType + ")");
			console.dir(outputArray);
			console.groupEnd();
		}
		return outputArray;
	}

	/* Based on SiteLifeProxy code. */
	DaapiDiscoveryWidget.prototype.GenerateDiv = function(cssClass) {
	    var outputDiv = "DDW_Container" + this.SID;
	    (typeof(this.numDDWidgets) != "undefined") ? outputDiv += this.numDDWidgets++ : this.numDDWidgets = 1;
	    var cssClass = cssClass || outputDiv;
	    document.write('<div id="'+outputDiv+'" class="'+cssClass+'"></div>');
		return outputDiv;
	}

	/* Supported Activty/ContentType pairs (according to Jeremy Tyree’s DAAPI Discovery Generator)
		Articles: 			Recent, 	Commented, 		Reviewed, 	Recommended, 	Rated
		BlogPost: 			Recent, 	Commented, 			 	Recommended
		CommunityGroup: 		Recent, 											Most Active
		Discussion:			Recent, 	Commented
		GroupBlog:	 			 		 			 		Recommended, 	Rated, 	Most Active
		Persona: 			Recent							Recommended
		PublicBlog: 				 		 			 		Recommended, 	Rated, 	Most Active
		PublicPhoto:			Recent, 	Commented, 			 	Recommended
		PublicPhotoGallery: 	Recent, 	Commented, 		Reviewed, 	Recommended, 	Rated
		PublicVideo:			Recent, 	Commented, 			 	Recommended
		PublicVideoGallery: 	Recent, 	Commented, 		Reviewed, 	Recommended, 	Rated
		UserBlog: 				 		 			 		Recommended, 	Rated, 	Most Active
		UserPhoto:			Recent, 	Commented, 			 	Recommended
		UserPhotoGallery: 		Recent, 	Commented, 		Reviewed, 	Recommended, 	Rated
	*/
	
	/* GENERIC */
	DaapiDiscoveryWidget.prototype.Discover = function(sections, categories, contributors, activity, contentType, age, max, filterBySID, parentKeys, miscParams) {
		miscParams = miscParams || {};
		miscParams.outputDiv = miscParams.outputDiv || this.GenerateDiv();
		return this.Core({"sections":sections,"categories":categories,"contributors":contributors,"activity":activity,"contentType":contentType,"age":age,"max":max,"filterBySID":filterBySID,"parentKeys":parentKeys,"miscParams":miscParams});
	}

	/* FILTERED */	
	DaapiDiscoveryWidget.prototype.MostCommentedArticlesBySection = function(sectionName, count, age, miscParams) {
		miscParams 				= miscParams || {};
		miscParams.outputDiv 	= miscParams.outputDiv || this.GenerateDiv();
		return this.Core({"sections":sectionName,"activity":"Commented","contentType":"Article","age":age,"max":count,"miscParams":miscParams}); 
	}

	DaapiDiscoveryWidget.prototype.MostRecommendedBlogPostsByTags = function(tagFilter, count, age, miscParams) {
		miscParams 				= miscParams || {};
		miscParams.outputDiv 	= miscParams.outputDiv || this.GenerateDiv();
		return this.Core({"categories":tagFilter,"activity":"Recommended","contentType":"BlogPost","age":age,"max":count,"miscParams":miscParams}); 
	}

	DaapiDiscoveryWidget.prototype.RecentPublicPhotosByTags = function(tagFilter, count, age, miscParams) {
		miscParams 				= miscParams || {};
		miscParams.outputDiv 	= miscParams.outputDiv || this.GenerateDiv();
		if (age == null || age == "") {age = "365";} //Photos and videos default to 365
		return this.Core({"categories":tagFilter,"activity":"Recent","contentType":"PublicPhoto","age":age,"max":count,"miscParams":miscParams});
	}

	DaapiDiscoveryWidget.prototype.RecentPublicPhotoGalleriesByTags = function(tagFilter, count, age, miscParams) {
		miscParams 				= miscParams || {};
		miscParams.outputDiv 	= miscParams.outputDiv || this.GenerateDiv();
		if (age == null || age == "") {age = "365";} //Photos and videos default to 365
		return this.Core({"categories":tagFilter,"activity":"Recent","contentType":"PublicPhotoGallery","age":age,"max":count,"miscParams":miscParams});
	}

	DaapiDiscoveryWidget.prototype.RecentPublicVideosByTags = function(tagFilter, count, age, miscParams) {
		miscParams 				= miscParams || {};
		miscParams.outputDiv 	= miscParams.outputDiv || this.GenerateDiv();
		if (age == null || age == "") {age = "365";} //Default photos and videos to 365
		return this.Core({"categories":tagFilter,"activity":"Recent","contentType":"PublicVideo","age":age,"max":count,"miscParams":miscParams});
	}

	DaapiDiscoveryWidget.prototype.MostRecommendedPublicVideosByTags = function(tagFilter, count, age, miscParams) {
		miscParams 				= miscParams || {};
		miscParams.outputDiv 	= miscParams.outputDiv || this.GenerateDiv();
		if (age == null || age == "") {age = "365";} //Photos and videos default to 365
		return this.Core({"categories":tagFilter,"activity":"Recommended","contentType":"PublicVideo","age":age,"max":count,"miscParams":miscParams}); 
	}

	DaapiDiscoveryWidget.prototype.RecentBlogPostsByTags = function(tagFilter, count, age, miscParams) {
		miscParams 				= miscParams || {};
		miscParams.outputDiv 	= miscParams.outputDiv || this.GenerateDiv();
		return this.Core({"categories":tagFilter,"activity":"Recent","contentType":"BlogPost","age":age,"max":count,"miscParams":miscParams}); 
	}
	
	DaapiDiscoveryWidget.prototype.MostRecommendedPublicPhotosByTags = function(tagFilter, count, age, miscParams) {
		miscParams 				= miscParams || {};
		miscParams.outputDiv 	= miscParams.outputDiv || this.GenerateDiv();
		if (age == null || age == "") {age = "365";} //Photos and videos default to 365
		return this.Core({"categories":tagFilter,"activity":"Recommended","contentType":"PublicPhoto","age":age,"max":count,"miscParams":miscParams});
	}
	
	/* UNFILTERED */
	DaapiDiscoveryWidget.prototype.RecentPublicVideos = function(count, age, miscParams) {
		miscParams 				= miscParams || {};
		miscParams.outputDiv 	= miscParams.outputDiv || this.GenerateDiv();
		if (age == null || age == "") {age = "365";} //Photos and videos default to 365
		return this.Core({"activity":"Recent","contentType":"PublicVideo","age":age,"max":count,"miscParams":miscParams}); 
	}

	/* THE END */

	var plck_DW_DDW = new DaapiDiscoveryWidget(serverUrl);
