/* ============================================================
profile.js
 javascripts for http://books.livedoor.com/profile/
  created: 2008-09-01
  modified:
  $Date:: 2008-10-20 13:45:54#$
  $Author: nakamurak $
  $Revision: 48861 $
============================================================ */

(function($) {
	//execute right now

	//execute when document's ready
	$(function() {
		//open/close for bookMark
		new cau1Lib.Class.columnOpenClose("div.bookMarks",{
			useHalfOpen: true,
			halfOpenHeight:185
		});

		//open/close for categories
		new cau1Lib.Class.columnOpenClose("div.categories");


		//open/close for reviews
		new cau1Lib.Class.columnOpenClose("div.reviews",{
			showHideArea: ".commentsList",
			useHalfOpen: true,
			halfOpenCount: 5,
			halfOpenDetect: function() {
				this.itemsTotalCount = this.targetObj.find(".itemsCount").text();
				if (this.itemsTotalCount > this.options.halfOpenCount) {
					this.readAll = false;
					return true;
				} else {
					this.readAll = true;
					return false;
				}
			},
			actionOpen:function() {
				var self = this;
				if (!this.readAll) {
					//read all data through ajax
					var ldid = $(".profileImage img:first").attr("alt");
					var apiUrl = "/api/userReview?limit=" + this.itemsTotalCount + "&ldid="  + ldid + " li";
					this.showHideArea.load(apiUrl,function() {
						self.readAll = true;
						//reattach events
						self.showHideArea.find(".itemImage").each(function() {
							new cau1Lib.Class.showItemSummary(this,{appendArea:"div.profileArea"});
						});
						self.showHideArea.find(".truncateText").each(function() {
							new cau1Lib.Class.hideLongText(this);
						});
						self.openHandler;
					});
				} else {
					this.showHideArea.find("li:gt(" + (this.options.halfOpenCount-1) + ")").show().end().slideDown();
				}
			},
			actionHalfOpen: function () {
				this.showHideArea.slideDown().find("li:gt(" + (this.options.halfOpenCount-1) + ")").hide();
			}
		});

		//open/close for topics
		new cau1Lib.Class.columnOpenClose("div.topics",{
			showHideArea: ".commentsList",
			useHalfOpen: true,
			halfOpenCount: 5,
			halfOpenDetect: function() {
				this.itemsTotalCount = this.targetObj.find(".itemsCount").text();
				if (this.itemsTotalCount > this.options.halfOpenCount) {
					this.readAll = false;
					return true;
				} else {
					this.readAll = true;
					return false;
				}
			},
			actionOpen:function() {
				var self = this;
				if (!this.readAll) {
					//read all data through ajax
					var ldid = $(".profileImage img:first").attr("alt");
					var apiUrl = "/api/userTopics?limit=" + this.itemsTotalCount + "&ldid="  + ldid + " li";
					this.showHideArea.load(apiUrl,function() {
						self.readAll = true;
						//reattach events
						self.showHideArea.find(".truncateText").each(function() {
							new cau1Lib.Class.hideLongText(this);
						});
						self.openHandler;
					});
				} else {
					this.showHideArea.find("li:gt(" + (this.options.halfOpenCount-1) + ")").show().end().slideDown();
				}
			},
			actionHalfOpen: function () {
				this.showHideArea.slideDown().find("li:gt(" + (this.options.halfOpenCount-1) + ")").hide();
			}
		});

	});
})(jQuery);
