var unique_id = "";

$(function() {
	$("form.add").each(function() {
		var $form = $(this);

		$form.find("select[name=type]").change(function() {
			$form.find("div[data-type]").hide();
			
			var val = $(this).val();
			if (val == 1) {
				$form.find("div[data-type=1]").show();
			}
			if (val == 2) {
				$form.find("div[data-type=2]").show();
			}
			if (val !== "") {
				$form.find("div[data-type='all']").show();
			}
		}).trigger("change");
	});
	
	// Голосование
	if (typeof evercookie != "undefined") {
		var ec = new evercookie();
		ec.get("unique_id", function(value) {
			$(".hobby .vote").show();

			if (typeof value == "undefined" || !value) {
				unique_id = default_unique_id;
				ec.set("unique_id", unique_id);
				return;
			}
			unique_id = value;
		});
		
		$(".hobby .vote li").click(function() {
			$.post("/ajax/hobby-vote.php", {
				work_id: $(this).closest(".work").attr("work-id"),
				unique_id: unique_id,
				value: $(this).text()
			}, function() {
			});

			$(this).closest(".vote").hide().next().show();
		});
	}
});

