	if (!window.tpatpc) {
		window.tpatpc = {};
	}
	with(tpatpc) {
	
		tpatpc.FFUserLoader = function(nick,start,dim) {
			if (!nick) {
				throw("No nick");
			}
			this.nick = nick;
			this.start = isNaN(start) ? 0 : start;
			this.dim = isNaN(dim) ? 20 : dim;
		};
		
		FFUserLoader.prototype.getUrl = function(callbackString) {
				return "http://friendfeed.com/api/feed/user/"+this.nick+"?format=json&callback="+callbackString+"&num="+this.dim+"&start="+this.start;
		};
		
		tpatpc.FFPostLoader = function(post,start,dim) {
			if (!post) {
				throw("no post");
			}
			this.post = post;
			this.start = isNaN(start) ? 0 : start;
			this.dim = isNaN(dim) ? 20 : dim;
		}
		
		FFPostLoader.prototype.getUrl = function (callbackString) {
				return "http://friendfeed.com/api/feed/url?url="+this.post+"&format=json&callback="+callbackString+"&num="+this.dim+"&start="+this.start;
		};
		
		tpatpc.BloggerCommentsLoader = function(idPost,start,dim) {
			if (!idPost) {
				throw("no post");
			}
			this.idPost = idPost;
			this.start = isNaN(start) ? 0 : start;
			this.dim = isNaN(dim) ? 20 : dim;
		};
		
		BloggerCommentsLoader.prototype.getUrl = function(callbackString) {
				//this.dim??
				//this.start??
				return "http://tpatpc.blogspot.com/feeds/"+this.idPost+"/comments/default?alt=json-in-script&callback="+callbackString;
		};
	}	
	
	
	
	
/////////////////////////////////////////////////
	
	var jLoader = new tpatpc.JsonLoader();
	var ffCommentTemplate = new Patroon.Template('ffCommentTemplate');
	var ffUserTemplate = new Patroon.Template('ffUserTemplate');
			
	var ffComments = {};
			
	function loadFFPostComments(url,id,isMore) {
		if (ffComments[id] && !isMore) {
			return;
		}
		
		if (!ffComments[id]) {
			ffComments[id] = {};
		}
		
		//prepare to load the 20 items
		var start =ffComments[id].ffObj ? ffComments[id].ffObj.start+20 : 0;
		ffComments[id].ffObj = new tpatpc.FFPostLoader(url,start,20);
		//keep track about the number of pending requests
		ffComments[id].loadCounter = ffComments[id].loadCounter ? ffComments[id].loadCounter+1 : 1;
			
		var loader = show("ff_loader_"+id);
		
		var commentContainer = document.getElementById("comment_container_"+id);
		var container = document.createElement("div");
		commentContainer.insertBefore(container,loader);
		
		var pData = ffComments[id];
	
		ffComments[id].ffObj.callback = function(data) {
			pData.loadCounter--;
			if (pData.loadCounter <= 0) {
				hide("ff_loader_"+id);
			}
			
			
			if (data.entries.length > 0) {
				var h2 = show("comment_count_container_"+id);
				
				var span = h2.getElementsByTagName("span")[0];
				if (span) {
					var newEntries = data.entries.length;
					var oldEntries = trim(span.innerHTML);
					if (!isNaN(oldEntries)) {
						span.innerHTML = new Number(oldEntries) + newEntries;
					} else {
						span.innerHTML = newEntries;
					}
				} 
				
				var expnd = ffCommentTemplate.expand(data);
				container.appendChild(expnd);
			}
		}
		jLoader.load(ffComments[id].ffObj);
	}
			
	function loadFFUserFeed(id, isMore) {
		if (!bloggers[id]) {
			//no blogger, no load ;)
			return;
		}
		
		if (bloggers[id].friendfeed) {
			//the blogger must have a friendfeed so that it can be loaded 

			if (bloggers[id].ffObj && !isMore) {
				//friendfeed for this user was already loaded, 
				//unless we want more entries, exit
				return;
			}
			
			//prepare to load the 20 items
			var start = bloggers[id].ffObj ? bloggers[id].ffObj.start+20 : 0;
			bloggers[id].ffObj = new tpatpc.FFUserLoader(bloggers[id].friendfeed,start,20);
			//keep track about the number of pending requests
			bloggers[id].loadCounter = bloggers[id].loadCounter ? bloggers[id].loadCounter+1 : 1;
			
			//show the loader icon
			var loader = show(id+"_loader");
			
			//get the container
			var p = document.getElementById(id+"_container");
			
			//create the container and place it on the DOM, this way newest entries will
			//always be on top
			var container = document.createElement("div");
			p.insertBefore(container,loader);

			//add the callback to the loader
			bloggers[id].ffObj.callback = function(data) {
				//reduce the count of pending requests
				bloggers[id].loadCounter--;
				if (bloggers[id].loadCounter <= 0) {
					//if this is the last one, hide the loader
					hide(id+"_loader");
				}
				
				//expand the received data on the template
				var result = ffUserTemplate.expand(data);
				
				//append the results
				container.appendChild(result);
				
			}
			
			//let's load!
			jLoader.load(bloggers[id].ffObj);
			
		}
	}
	