function showVoting(sh)
{
	$.post('/voting/votethis.php', {action:'show', sh:sh}, function(data){
		if(data.error == null) 
		{
			$('#voting_block').fadeIn(200).html(data.out);
			$('.changeButton').bind('mouseover mouseout', function(){changeButton(this);});
			aniVoteImg();
		}
	}, 'json');
}

function voteFor()
{
	if($('input[name="vote2"]:checked').length < 1) 
	{
		alert('Выберите ответ');
		return;
	}
	
	shadow();
	$('#voting_block').fadeOut(200);
	$.post('/voting/votethis.php', $('#voteForm').serialize(), function(data){
		$('#loader').remove();							 
		if(data.error == null && data.ret > 0)
		{
			showVoting(data.ret);
		}
	}, 'json');
}

function aniVoteImg()
{
	$('.voteimg2').each(function(){$('#' + this.id).animate({width:$('#' + this.id).attr('percent') * 3.5 + 'px'}, 1500);});
}


function addAnswer()
{
	if(typeof aCount == 'undefined') aCount = 3;
	else
	{
		var temp = $('#insTable tr[id^="tr"]').length;
		if(temp > 0) aCount = temp + 3;
		else aCount = 3;
	}
	
	if(aCount > 10) 
	{
		alert('Наверно, хватит... :)');
		return;
	}
	
	$('<tr id="tr-' + aCount + '"><td id="td-' + aCount + '">' + aCount + '.</td><td><table width="100" border="0" cellspacing="0" cellpadding="0">' + 
	  '<tr style="height:20px"><td><img src="/img/input_l.png" class="im2"></td><td class="input_td"><input name="answer[]" type="text" maxlength="255" class="text_new" style="width:430px"></td>' + 
	  '<td><img src="/img/input_r.png" class="im2"></td></tr></table></td>' +
	  '<td align="right"><img src="/img/action_delete.png" class="im2" onClick="deletingVoteTr(' + aCount + ');" style="cursor:pointer"></td></tr>').css('display', 'none').appendTo($('#insTable')).fadeIn(500);

	aCount++;
}





function deletingVoteTr(id)
{
	var temp = 0;
	$('#tr-' + id).fadeOut(300, function()
	{
		$(this).remove();

		$('#insTable tr[id^="tr"]').each(function(index)
		{
			temp = index + 3;
			var temp2 = $(this).attr('id');
			$('#' + temp2 + ' td:first').html(temp + '.');
		});		
	});
}


function addVotingNow()
{
	shadow();
	$.post('/other/voting_add.php', $('#addForm').serialize(), function(data)
	{
		$('#loader').remove();
		if(data.error == '')
		{
			$('#votingDiv').fadeOut(500, function()
			{
				$(this).html('Поздравляем! Ваш опрос успешно добавлен в базу.<br> Он будет опубликован сразу же после модерирования.<br><a href="/voting/add.php" style="font-weight:bold">Добавить еще</a>').fadeIn(500);
			});
		}
		else alert(data.error);
	}, 'json');	
}



