$('.js-hide-offer-btn[data-oid]').click(function(e) {
	e.preventDefault();

	var thislink = $(this),
      thisoid = thislink.attr('data-oid');
	$.get('/api?method=project_hideoffer&oid=' + thisoid, function(data) {
		if (data){
      data = JSON.parse(data);
      if(data.success) {
        if(data.oview == 2) {
          thislink.html('Показать');
          $('#offer_id' + thisoid).addClass('hidden');
          $('.offer-item-cancel-link').removeClass('hidden');
        } else if(data.oview == 1) {
          thislink.html('Скрыть');
        } else {
          thislink.html('Ошибка');
        }
      }
		}
	});
});

function loadDodjiDetails(target) {
	var $offerBlock = $(target).closest(".js-offer-item");
	var itemId = $offerBlock.data("id") - 0;
	var orderId = $offerBlock.data("order-id") - 0;
	var url = "/api?method=project_getDetails";
	var prdDetailsNode = $offerBlock.find(".prdDetails");
	var description = false;
	prdDetailsNode.find(".preloader--project-container").show();
	var $container = $offerBlock.find(".preloader--project-container");
	prdDetailsNode.find(".js-description-button-show").hide();
	$container.preloader("show");

	if (prdDetailsNode.data("loaded") == 0) {
		$.ajax({
			url: url,
			type: "post",
			dataType: "json",
			data: {"itemId": itemId, "orderId": orderId},
			success: function (response) {
				if (response.status == "success") {
					var description = response.content.prd.gdesc;
					var instructions = response.content.prd.ginst;
					var reviews = response.content.reviews;
					var trackOrder = response.content.track_order;
					var files = response.content.files;
					prdDetailsNode.data("loaded", "1");
					prdDetailsNode.find(".js-description").data("descriptionLess", prdDetailsNode.find(".description").html());
					prdDetailsNode.find(".js-description").data("descriptionMore", description);
					prdDetailsNode.find(".js-description").html(description);
					instructions = "<p>" + instructions + "</p>";
					instructions += "<a class=\"requiredInfo-instruction-link-hide dib link_local\">" + t("Свернуть") + "</a>";
					prdDetailsNode.find(".instructions").html(instructions);
					if (files.length > 0) {
						prdDetailsNode.find(".files").html(files);
						prdDetailsNode.find(".files").prev().show();
					}
					if (response.content.prd.is_package == 1) {
						prdDetailsNode.find(".js-gwork").parent().hide();
					} else {
						prdDetailsNode.find(".js-gwork").text(response.content.prd.gwork);
					}
					if (reviews.html.length == 0) {
						prdDetailsNode.find(".reviews").text("Нет отзывов");
					} else {
						prdDetailsNode.find(".reviews").removeClass("mb10");
						prdDetailsNode.find(".reviews").html(reviews.html);
					}
					prdDetailsNode.find(".track-order").html(trackOrder.html);
					if(itemId > 0) {
            prdDetailsNode.find(".js-reviews").data("params", {
  						id: itemId,
  						onPage: 12,
  						onPageStart: 5,
  						entity: "prd",
  						baseUrl: location.href
  					});
  					//prdDetailsNode.find(".js-reviews").reviewWidget();
          }
					if (!description) {
						prdDetailsNode.find(".description").html(prdDetailsNode.find(".description").data("descriptionMore"));
					}
					$container.html("").hide();
					prdDetailsNode.find(".more").show();
					prdDetailsNode.find(".js-description-button-hide").show();
					prdDetailsNode.addClass("mb20");
					var $infoInstructionShow = $(".requiredInfo-instruction-link-show");
					var $infoInstructionHide = $(".requiredInfo-instruction-link-hide");
					$infoInstructionShow.off("click");
					$infoInstructionHide.off("click");
					//Сворачивание, разворачивание блока инструкций покупателю
					$infoInstructionShow.on("click", function () {
						$(this).closest(".requiredInfo-block").find("img").toggleClass("rotate180");
						$(this).closest(".requiredInfo-block").find(".requiredInfo-text-block").toggleClass("hidden");
					});
					$infoInstructionHide.on("click", function () {
						$(this).closest(".requiredInfo-block").find(".requiredInfo-instruction-link-show").find("img").removeClass("rotate180");
						$(this).closest(".requiredInfo-block").find(".requiredInfo-text-block").addClass("hidden");
					});

				}
			}
		});
	} else {
		if (!description) {
			prdDetailsNode.find(".description").html(prdDetailsNode.find(".description").data("descriptionMore"));
		}
		$container.html("").hide();
		prdDetailsNode.find(".more").show();
		prdDetailsNode.find(".js-description-button-hide").show();
		prdDetailsNode.addClass("mb20");
	}
}
function hideDodjiDetails(target) {
	var prdDetailsNode = $(target).closest(".js-offer-item").find(".prdDetails");
	prdDetailsNode.find(".more").hide();
	prdDetailsNode.find(".description").html(prdDetailsNode.find(".description").data("descriptionLess"));
	prdDetailsNode.find(".js-description-button-hide").hide();
	prdDetailsNode.find(".js-description-button-show").show();
	prdDetailsNode.removeClass("mb20");
	prdDetailsNode.find(".preloader--project-container").hide();
}
