/*
 * copy from http://pinglun.qq.com/js/comment_lib.js
 * modified by hobo at 2007-4-30
 */

var Comment = new Object();

Comment.Configure = {
	version: "1.0",
	newline: "\n",
	index_domain: "http://sum.comment.qq.com/",
	index_domain_ex: "http://sum.comment.qq.com/",
	index_domain_ex2: "http://sum.comment.qq.com/"
};

Comment.ContentFormat = {
	decode: function(content)
	{
		return content.split(Comment.Configure.newline);
	}
};

Comment.UrlFactory = {
	commentUrlFormatStr: Comment.Configure.index_domain + "{0}/normal/{1}/{2}.htm{3}",
	commentUrlExFormatStr: Comment.Configure.index_domain_ex + "{0}/normal/{1}/{2}.htm{3}",
	commentUrlExFormatStr2: Comment.Configure.index_domain_ex2 + "{0}/normal/{1}/{2}.htm{3}",

	getCacheString: function(cache)
	{
		return cache ? "?cache="+Math.random() : "";
	},

	getCommentDir: function(id)
	{
		var path = parseInt(id / 1000000) + '/';
		path += parseInt(id / 1000) + '/';
		path += id / 1;
		return path;
	},

	getCommentSumUrl: function(site, id, nocache)
	{
		if (parseInt(id) > 1189800)
		{
			return String.format(this.commentUrlExFormatStr2,
				site, this.getCommentDir(id), "sum", this.getCacheString(nocache));
		}
		else if (parseInt(id) >= 808728)
		{
			return String.format(this.commentUrlExFormatStr,
				site, this.getCommentDir(id), "sum", this.getCacheString(nocache));
		}
		else
		{
			return String.format(this.commentUrlFormatStr,
				site, this.getCommentDir(id), "sum", this.getCacheString(nocache));
		}
	}
};

Comment.DataObjectFactory = function(content, model)
{
	content = Comment.ContentFormat.decode(content);
	var dataModel = Comment.DataObject[model];
	var dataObject = {};

	for (var i=0; i<dataModel.length; i++)
	{
		dataObject[dataModel[i]] = content[i];
	}

	return dataObject;
};

Comment.DataObject = {
	"sum": [
		"origin_count",
		"total_count",
		"top_count"
	]
};

Comment.Proxy = {
	printCommentSum: function(site, id, container)
	{
		if (parseInt(id)<=0)
		{
			$(container).innerHTML = 0;
			return;
		}

		var commentSumUrl = Comment.UrlFactory.getCommentSumUrl(site, id, true);
		ProxyLoader.load(commentSumUrl, {
			onSuccess: function(xmlHttp)
			{
				try
				{
					$(container).innerHTML = Comment.DataObjectFactory(xmlHttp.responseText, 'sum')['total_count'];
				}
				catch (e)
				{
				}
			},
			onFailure: function()
			{
				try
				{
					$(container).innerHTML = 0;
				}
				catch (e)
				{
				}
			}
		});
	}
};

//评论初始化(站点, 评论id, 评论数, 显示评论总数容器, 评论样式)
Comment.init = function(site, commentId, sum, countId, style)
{
	comment_para_site = site;
	comment_para_id = commentId;
	comment_para_is_group = 0;
	comment_para_sum = sum || 10;
	comment_para_mode = "total";
	comment_para_show = 1;
	comment_para_height = 0;
	comment_para_submit_pos = 1;
	comment_para_count_id = countId || "";
	comment_container = "Comment";
	switch (style)
	{
		case 1:
			comment_para_style = "http://comic.qq.com/doodle/styles/css/pl1.css";
			break;
		case 2:
			comment_para_style = "http://comic.qq.com/doodle/styles/css/pl2.css";
			break;
		case 3:
			comment_para_style = "http://comic.qq.com/doodle/styles/css/pl3.css";
			break;
		default:
			comment_para_style = "http://comic.qq.com/doodle/styles/css/pl1.css";
			break;
	}

	comment_create();
};/*  |xGv00|d6fa24aebc2fb578d271a57e7ca93f66 */