$(document).ready(function(){
	// カテゴリツリー
	if ($("#treeview").size() > 0) {
		$("#treeview").treeview({
			persist: "location",
			collapsed: true
		});
		// 中カテゴリクリックによる小カテゴリopen
		$('.folder').click(function() {
			$(this).next().show();
			$(this).parent().find('div').removeClass('expandable-hitarea');
			$(this).parent().find('div').addClass('collapsable-hitarea');
		});
		// 中カテゴリクリックによる小カテゴリopen（サーバー応答後）
		var openCategory = $('#open_category').val();
		if (openCategory != '') {
			$("#" + openCategory).show();
			$("#" + openCategory).parent().find('div').removeClass('expandable-hitarea');
			$("#" + openCategory).parent().find('div').addClass('collapsable-hitarea');
		}
	}

	// お気に入りに追加＆解除
	$('img[id^="favoriteButton"]').each(function() {
		var pointID = $(this)[0].id;
		pointID = pointID.replace("favoriteButton", "");
		$(this).bind("click", function(){
			$.get("/ajax/favoritepointid/", {point_id:pointID, mode:'regist'}, function(returnData){
				if (returnData == 'regist') {
					// 追加したので、解除ボタンに切替
					$('#favoriteButton' + pointID).attr('src', "/images/get/btn_favoriteRemove.gif");
				} else if (returnData == 'delete') {
					// 解除したので、追加ボタンに切替
					$('#favoriteButton' + pointID).attr('src', "/images/get/btn_favoriteAppend.gif");
				}
			});
		});
	});

	// マイページお気に入り解除
	$('img[id^="favoriteDelete"]').each(function() {
		var pointID = $(this)[0].id;
		pointID = pointID.replace("favoriteDelete", "");
		$(this).bind("click", function(){
			$.get("/ajax/favoritepointid/", {point_id:pointID, mode:'delete'}, function(returnData){
				if (returnData == 'regist') {
					// 追加はありえないはず
				} else if (returnData == 'delete') {
					// 解除したので、隠す
					$('#favoriteDelete' + pointID).closest("div[class*='favoriteContainer']").hide();
				}
			});
		});
	});

	// 人気情報検索ワードクリック
	$(".noteworthyWord").click(function() {
		$("#query").val($(this).attr('alt'));
		$("#searchForm").submit();
	});

	// プロフィール画像角丸
//	$("img.prof").imgr({size:"1px",color:"#c0d9f1",radius:"10px"});
});

