// Javsacript helper functions for RapidBlog

// javscript to list comments out to make it mo-faster
function listComments(root) {
	var feed = root.feed;
	
	var entries = feed.entry || [];
	var html = [];
	
	
	if (!feed.entry)
		return;
	//$t = "tag:blogger.com,1999:blog-4270442078467138119.post2447883094318407169..comments"
	
	var re=/post([0-9]+)/i
		var joe=re.exec(feed.id.$t);
	var myId=joe[1];
	
	//2007-01-01T22:58:00.000-08:00
	dateRe=/(\d{4})-(\d{2})-(\d{2})T(\d{2}):(\d{2}):\d{2}.\d{3}/;
	
	//	var dateArray=re.exec("2007-01-01T22:58:00.000-08:00");
	//	var thisDate=new Date(dateArray[1],dateArray[2],dateArray[3],dateArray[4],dateArray[5])
	//	document.write(new Date('3/4/006'))
	
	if (feed.entry.length==0) {
		//html.push('comments');
	} else if (showNumberOfComments){	
		html.push('(',feed.entry.length,')<br /> '); /* This actually pushes the (3) type string to the end of the commetents */
	}


if (showComments==1) {
	
	/* Moo Foo 
	html.push('<a href="#" onclick="javascript:expand(',myId,')>Expand Comments</a>');
*/
	html.push('<div class="blog-entry-comments-body">');
	for (var i = 0; i < feed.entry.length; ++i) {
		if ((i%2)==0)
			html.push('<br /><br /> <div class="blog-entry-comments-body-even">');
		else
			html.push('<br /><br /> <div class="blog-entry-comments-body-odd">');
		
		var entry = feed.entry[i];
		var title = entry.title.$t;
		var published=entry.published.$t;
		var dateArray=dateRe.exec(published);
		var thisDate=new Date(dateArray[1],dateArray[2]-1,dateArray[3],dateArray[4],dateArray[5],0)
			// var start = entry['gd$when'][0].startTime;
			var content = entry.content.$t;
		
		// Figure out the author & a web page if given one
		var URI=null;
		var author=null;
		
		author = entry.author[0].name.$t;
		
		if (entry.author[0].uri)
			var URI= entry.author[0].uri.$t;
		if (URI!=null)  {
			var httpRe=/http:\/\//;
			if (!httpRe.exec(URI)) { // if they didn't give a leading HTTP then we need to add one.
				URI="http://"+URI;
			}
			author="<a href='"+URI+"'>"+author+"</a>";
		}
		html.push(author, ' said .... <br />', '<div>', content, ' </div> ',thisDate.toLocaleString(),'</div> </div>');

	}

}



document.getElementById(myId).innerHTML += html.join("");
//$(myId).style.height=0; // moo foo 
}


//function expand(element) { // Cool moo-open/close functions
//	
//	var myFx=new Fx.Style(element,'height','unit','%');
//	var myVal=parseInt($(element).style.height);
//	if (myVal==0)
//		myFx.custom(0,100);
//	else myFx.custom(100,0);
//	
//}
//

