(function(){
/*
	Class: Comment 
	The base data object for a Comment 
*/
function Comment() { this.item = null; this.p_config = null; this.replies = []; }

Comment.prototype.toString = function() { return "[SB.core.Comment]"; };

//Group: Basic Methods 
/*
	Function: setConfig
	Establishes the basic setup for the Box.
	
	inConfig - A configuration array (key/value)

	Configuration Array Options:
	url - The url of the image for the Comment 
	title - The title for the Comment 
	item_id - The id for the Comment 
*/
Comment.prototype.setConfig = function( inConfig )
{
	this.p_config = inConfig;
	for( key in inConfig ) { this[key] = inConfig[key]; }	

	//mapping
	if( this.comment_id ) this.id = this.comment_id;
};

/*
	Function: getConfig
	Gets the basic setup for the Comment.
*/
Comment.prototype.getConfig = function()
{
	return this.p_config;
};

/*
	Function: setParent
	Points the internal reference to the Item that owns it

	*Should only be called by a Box or from Comment itself*
*/
Comment.prototype.setItem = function( inObj ) {
	inObj.addComment( this );
};

/*
 	Function: postComment
	Sends the comment information to SimplyBox servers
*/
Comment.prototype.postComment = function() 
{
	var sURL = "/comment/add/";
	var pd = "item_id="+this.item.item_id+"&comment="+encodeURIComponent(this.text);
	if( this.replyto ) pd += "&replyto="+this.replyto;
	if( this.captcha_value ) pd += "&sbcaptcha="+this.captcha_value+"&captcha_uid=0";
	if( this.text.length )
	{
		YUIRequest.asyncRequest( "POST", sURL, {success:addCommentCallback, arguments:{obj:this} }, pd );
	}
};

function addCommentCallback( inReq )
{
	var comment_obj = this.arguments.obj;
	var response = YUIJSON.parse(inReq.responseText);

	if( response.id )
		comment_obj.id = comment_obj.comment_id = response.id;
}

/*
	Function: kill 
	Deletes the Comment	
*/
Comment.prototype.kill = function() 
{
	this.item.removeComment( this );	
};

window['SB']['core']['Comment'] = Comment;

})();
