/* Init functionality ***********/

function init()
{
	//Corner and shadow the content
	$("#main-body").corner();
	$("#main-header-text").dropShadow({ "opacity": 0.9, "top": 2, "left": 2, "blur": 0 });
	$(".shadow").dropShadow({ "opacity": 0.9, "top": 2, "left": 2, "blur": 0 });
}


/* Menu functions */

function MenuTab_slideIn(element)
{
	$(element).animate({ "top": "-5px"}, "fast");
}

function MenuTab_slideOut(element)
{
	$(element).animate({ "top": "-15px"}, "fast");
}


function MenuButton_slideIn(element)
{
	$(element).animate({ "paddingTop": "2px", "paddingBottom": "2px"}, "fast");
}

function MenuButton_slideOut(element)
{
	$(element).animate({ "paddingTop": "0px", "paddingBottom": "0px"}, "fast");
}


/* Comment functions ******************** */

//Define comment list function
function listComment(obj, index)
{
	//Set CSS class
	var cssClass = "";
	if (index%2)
		cssClass = " class='even'";

	//Make sure the object has an author name
	if (!obj.authorName())
		obj.setAuthorName("Anonymous");
		
	//Build list item string
	var result = obj.authorName();
	if (obj.authorEmail())
		result = "<a href='mailto:" + obj.authorEmail() + "'>" + result + "</a>";
	if (obj.authorUrl())
		result += ", <a href='" + obj.authorUrl() + "'>[web site]</a>";
	result += ", " + obj.createdDateTime(); 
	result = "<span class='small'>" + result + " wrote:</span><br/>" + obj.text();
	return "<li " + cssClass + ">" + result + "</li>"; 
}

//Comment load function
function loadComments(maxCount, groupName)
{	
	//Create a search filter for the comment list
	var commentSearchFilter = new SearchFilter();
	commentSearchFilter.setPaging(0, maxCount);
	commentSearchFilter.addSortRule("createdDateTime DESC");
	commentSearchFilter.addSearchRule("groupName = '" + groupName + "'");

	//Load all required comments
	var comments = new Comment();
	comments.search(commentSearchFilter.searchFilter(), function(result)
	{
		//Update the control
		Wigbi.getControl("commentList").refresh(result);
		
		//Update total count, if any
		if (result.length > 0)
			$("#spanNumComments").html(" (" + result[0].totalCount() + " comments)");
		else
			$("#spanNumComments").html(" (no comments)");
		
		//Show/hide the load button
		if (result.length == 0 || result.length >= result[0].totalCount())
			$("#loadDiv").hide();
		else
			$("#loadDiv").show();
	});
}

