var Comment = null;

Comment = Class.create();
Comment.prototype = {
	initialize : function(prefix, work_id, min_num, max_num) {
		this.prefix = prefix;
		this.id = work_id;
		this.min_num = min_num;
		this.max_num = max_num;
		this.list = [];
		this.order = "asc";
		/*this.setAll();*/
	},
/*	setAll : function () {
		var min_num = this.min_num;
		var max_num = this.max_num;
		var com_id_base = 'comment' + '_' + this.prefix + this.id + '_';
		this.list = list;
	},
	*/
	sortAsc : function() {
		this.order = "asc";
		this.list.reverse();
	},
	sortDesc : function() {
		this.order = "desc";
		this.list.reverse();
	},
	setSwitcher : function() {
		var csw = $('com_order');
		if (csw) csw.remove();
		var tmenu = $('top-menu-list');

		if (this.order == "asc") {
			order_label = "昇順";
		} else {
			order_label = "降順";
		}
		var order_label;
		var str = '<p id="com_order" style="display:inline">現在のコメント順:<strong>' + order_label + '</strong>&nbsp;<a href="#" onclick="comment.refresh();return false;">切替</a></p>';
		if (tmenu) tmenu.insert({after : str});
//		var bmenu = $('bottom-menu-list');
//		if (bmenu) bmenu.insert({after : str});
	},
	refresh : function() {
		var com_list_base = 'comment' + '_' + this.prefix + this.id;
		var clist = $(com_list_base);
		//if (clist) clist.remove();

		if (this.order == "asc") {
			this.sortDesc();
		} else {
			this.sortAsc();
		}
		this.setSwitcher();

		var cl = clist.childElements();
		//cl.reverse();

		cl.reverse().each(function(cl, index) {
			if (index > 0)
				clist.insertBefore(cl, cl[index - 1]);
		}.bind(this));
/*
		title = $('work-title');
		var str = '<ol class="thread hfeed hslice" id="' + com_list_base +'">';
		var list = this.list;
		var len = list.length;
		var tmp;
		for (var i = 0; i < len; i++) {
			tmp = list[i];

//			str += list[i];
		}
		str += '</ol>';
		title.insert({after : str});
	*/

	}
}


