var cmt;
var article;

if (SITELIFE_ENABLED) {
	// for comments list & comments entry box
	cmt = new _Comments();
	// for comments entry box
	article = new _Article();
	function acb(x) {article.ProcessResponse(x);}
	// a necessary step because of scope and reference
	article.setCallBack(acb);
}
// for comments list
var uniqueCommentKey = "";//same as CommentKey.Key - need this global variable to process UI updates because
                          //some DAAPI calls do not return a response
var recommendedCount = "";//represents NumberOfRecommendations - need globabl variable to process UI update because 
                          //RecommendAction DAAPI call does not return a response
var ArticleJSON = {}; // need this variables to be gloabal for utils.addListener to work in IE
var EntryBoxPropsJSON = {}; // need this variables to be gloabal for utils.addListener to work in IE
var SLIntegrationReady = false; // will set this to true when SetGlobalsForSLIntegration is called

function SetGlobalsForSLIntegration(thisArticle,thisEntryBoxProps) {
	if ( typeof ArticleJSON  != "undefined") {
		ArticleJSON = thisArticle;
		SLIntegrationReady = true;
	}
	if ( typeof EntryBoxPropsJSON  != "undefined") {
		EntryBoxPropsJSON = thisEntryBoxProps;
	}
}
function SLIntegrationStartUpComments() {
	if (SLIntegrationReady) {
		id = ArticleJSON.id;
		if (SITELIFE_ENABLED) {
			// tools.debug("starting up no really");
			function cb(x) {cmt.PluckReturn(x)}
			cmt.SetCallBack(cb);
			cmt.SetReturnCount(20);
			cmt.SetCommentDisplay(DrawComments);
			cmt.GetComments(id);
			// tools.debug("starting up done");
			DrawAbuseReportDialog(document.getElementById('CommentsReportAbusePopup'));
		}
	}
}
function SLIntegrationStartUpEntry() {
	if (SLIntegrationReady) {
		id = ArticleJSON.id;
		headline = ArticleJSON.headline ;
		path = ArticleJSON.path ;
		section = ArticleJSON.section ;
		redirect_url = ArticleJSON.comments_url ;

		if ( typeof EntryBoxPropsJSON == 'undefined')
			var EntryBoxPropsJSON = {} ;

		if (SITELIFE_ENABLED) {
//			cmt = new _Comments();
			function cmb(x) {cmt.commentSubmitted(x);}
			cmt.SetCmtCallBack(cmb);
			function x(url) {wpPostCommentSuccess(redirect_url);}
			cmt.SetSuccessCallBack(x);
			function xy(msg) {wpPostCommentFailure(msg)};
			cmt.SetFailureCallBack(xy);
			DrawCommentsInput(document.getElementById("commententry"),id,EntryBoxPropsJSON);

			var articleDetails = new UpdateArticleAction(new ArticleKey(id),
									path,
									headline,
									new Section(section),
									new Array());

			article.SetArticleDetails(articleDetails);
			function dcc(articleObject) {slDisplay.DrawHeadlineCommentCount(articleObject)};
			article.SetCommentCountHandler(dcc);
			article.CallServer();
		}
	}
}
function SLIntegrationStartUpBoth() {
	if (SLIntegrationReady) {
		if (SITELIFE_ENABLED) {

			if ( typeof EntryBoxPropsJSON == 'undefined')
				var EntryBoxPropsJSON = {} ;

			id = ArticleJSON.id;
			headline = ArticleJSON.headline ;
			path = ArticleJSON.path ;
			section = ArticleJSON.section ;
			redirect_url = ArticleJSON.comments_url ;

			// tools.debug("starting up no really");
			function cb(x) {cmt.PluckReturn(x);};
			cmt.SetCallBack(cb);
			cmt.SetReturnCount(20);
			cmt.SetCommentDisplay(DrawComments);
			cmt.GetComments(id);
			// tools.debug("starting up done");
			DrawAbuseReportDialog(document.getElementById('CommentsReportAbusePopup'));

			function cmb(x) {cmt.commentSubmitted(x);}
			cmt.SetCmtCallBack(cmb);
			function xz(url) {wpPostCommentSuccess(redirect_url);}
			cmt.SetSuccessCallBack(xz);
			function zz(msg) {wpPostCommentFailure(msg)};
			cmt.SetFailureCallBack(zz);

			var articleDetails = new UpdateArticleAction(new ArticleKey(id),
									path,
									headline,
									new Section(section),
									new Array());

			article.SetArticleDetails(articleDetails);
			function cch(articleObject) {slDisplay.DrawHeadlineCommentCount(articleObject)}
			article.SetCommentCountHandler(cch);
			article.CallServer();
			DrawCommentsInput(document.getElementById("commententry"),id,EntryBoxPropsJSON);
		}
	}
}
