$(function() {
	$("a.lightbox").lightBox({
		imageLoading: '/i/lightbox/loading.gif',
		imageBlank: '/i/lightbox/blank.gif',
		imageBtnClose: '/i/lightbox/close.gif',
		imageBtnPrev: '/i/lightbox/prev.gif',
		imageBtnNext: '/i/lightbox/next.gif'
	});
	
	$(".l-content table:not(.form) tr:last").each(function(i, item) { if (!$(item).hasClass("last")) $(item).addClass("last"); })
});

function submitVote(url) {
	$(".b-surveyform form").addClass("ajax");

	$.ajax({
		data: $(".b-surveyform form").serialize(),
		dataType: "json",
		url: "/json" + url,
		type: "POST",
		success: buildVote
	});

	return false;
}

function buildVote(data) {
	$(".b-surveyform form").remove();

	if (data.show_vote.show_results == 1) {
		var maxVote = -1;
		$(data.answers).each(function(i, item) { if (item.percents > maxVote) maxVote = item.percents });
		$(data.answers).each(function(i, item) {
			if (item.enabled) {
				var p = $("<p />").attr({ "class": "b-results" }).appendTo($(".b-surveyform"));
				if (item.percents == maxVote) { p.addClass("high"); maxVote = -1; }
				$("<em />").html(item.answer_text).appendTo(p);
				$("<b />").css({ "width": Math.round(item.percents * 80) + "%" }).html('<i class="b-sur"><i class="b-sur-l"></i><i class="b-sur-r"></i></i>').appendTo(p);
				$("<span />").html(Math.round(item.percents * 10000) / 100 + "%").appendTo(p);
			}
		});
	}
	else {
		$("<p />").html(voteThanks).appendTo($(".b-surveyform"));
	}
}