function Comments (url, place) {
	this.place = $(place);
	this.url = url;
	this.page = 1;
	
	this.load();
}

Comments.prototype.load = function () {
	var ctrl = this;
	
	$.get(
		this.url,
		{'page' : this.page},
		function (data) {
			ctrl.draw(data)
		}
	)
}

Comments.prototype.draw = function (data) {
	var ctrl = this;
	
	this.place.fadeOut(100, function () {
		ctrl.place.html("");
	
		var ecomments = $("<div>").attr("class", "comments");
		$.each(data.comments, function (k, c) {
			$("<div>")
				.attr("class", "comment")
				.append(
					$("<span>")
						.attr("class", "name")
						.text(c.name)
				)
				.append(" ")
				.append(
					$("<span>")
						.attr("class", "date")
						.text(c.date)
				)
				.append(c.text)
				.appendTo(ecomments)
		});
		ctrl.place.append(ecomments);
		
		var epaginator = $("<div>").attr("class", "pages");
		$.each(data.prange, function (k, p) {
			if (p[1] == data.page) {
				$("<span>").text(p[0]).appendTo(epaginator);
			} else {
				var t = function (p) {
					$("<a>").text(p[0]).appendTo(epaginator).click(function () {
						ctrl.changePage(p[1]);
					});
				}; t(p);
				
			}
		});
		ctrl.place.append(epaginator);
		
		ctrl.place.fadeIn(100);
	})
}

Comments.prototype.changePage = function (page) {
	this.page = page;
	this.load();
}