// votebox
function loadVotebox() {
	$('#votebox').load('/voting/vote_frontend.php?foo='+Math.random(), function() {
			$('#votebox').parent().show();
			setTimeout(mapFormEvent, 500);
		}
	);
}


var updateHtml;
function mapFormEvent() {
	$('#submitBtn').click(function() {
		$('#submitBtn').parent().hide();
		$('#ajaxIndicator').css('display', 'block');
		var postData = $('#submitBtn').parent().find('input').serialize() + '&send=Abstimmen';

		$.post('/voting/vote_frontend.php', postData, function(data, textStatus) {
			if(textStatus == 'success') {
				updateHtml = data;
				setTimeout('showVoteBox()', 1000);
			} else {
				$('#votebox').html('Es gab einen Verbindungsfehler');
			}
		}, 'html');
	});
}

function showVoteBox() {
	$('#votebox').html(updateHtml);
	mapFormEvent();
}

// vote archive
function loadPagination(){
	$('#paginationLinks a').click(pager);
}

var page;
function pager() {
	var element = $(this);
	page = parseInt(element.html()) - 1;
	$('#paginationLinks a').removeClass('selected');
	element.addClass('selected');

	$('#voteArchive').html('');
	$('#ajaxIndicator2').show();
	setTimeout('loadPage()', 1000);
}

function loadPage() {
	$('#voteArchive').load('/voting/vote_frontend.php?pageNo='+page, function() {
		$('#ajaxIndicator2').hide();
	});
}

