$(document).ready(function(){

    $(".nieuwsbericht").hide();
   
    $(".nieuwslink").click(function(){
        $(".nieuwsbericht").slideUp();
        var test = $(this).parent().children(".nieuwsbericht");
        if(test.is(":hidden"))
        {
            test.slideDown();
        }
        else
        {
            test.slideUp();
        }
        return false;
    });

    $(function() {
	$('a[rel=lightbox]').lightBox(); // Select all links that contains lightbox in the attribute rel
    });
	
	$(function() {
	$('.gallery').lightBox(); // Select all links that contains lightbox in the attribute rel
    });

    $("#vvs2").click(function(){
        $height = $('.vvs2').outerHeight();
        $('.competitiewrapper').animate({left: -350}, 500);
        $('.competities').animate({height: $height+20}, 500);
        return false;
    });

    $height = $('.vvs1').outerHeight();
    $('.competities').animate({height: $height+20}, 500);


    $("#vvs1").click(function(){
        $height = $('.vvs1').outerHeight();
        $('.competitiewrapper').animate({left: 0}, 500);
        $('.competities').animate({height: $height+20}, 500);
        return false;
    });

    $("#vvs3").click(function(){
        $height = $('.vvs3').outerHeight();
        $('.competitiewrapper').animate({left: -700}, 500);
        $('.competities').animate({height: $height+20}, 500);
        return false;
    });
	
	$height = $('.poll1').outerHeight();
    $('.polls').animate({height: $height+20}, 500);

    $('#resultaten').click(function(){
		$.ajax({
            type : 'GET',
            url : '/stem/resultaten/',
			data : null,
            success: function(data){
                $('.poll2').html(data);
                $height = $('.poll2').outerHeight();
                $('.pollswrapper').animate({left:-350}, 500);
                $('.polls').animate({height: $height+20}, 500);
            }
        });
        return false;
    });

    $('#submit').click(function(event){
            event.preventDefault();
            var $form = $('#poll'),
            $inputs = $form.find("input");

            serializedData = $form.serialize();

            $.post('/stem/',serializedData, function(response){
                if(response=="antwoord_error")
                { 
                    $('#result').html('Antwoord is niet ingevuld');
                    $('#result').addClass("error");
                }
                else if(response=="ip_error")
                {
                    $('#result').html('Er is al gestemd van dit IP adres');
                    $('#result').addClass("error");
                }
                else
                {
                    $('#result').removeClass("error");
                    $('#result').html('Bedankt voor jouw stem. Klik op Resultaten om deze te tonen');
                    $('.radio_antwoord').hide();
                    $('#submit').hide();
                }
            });

            
        return false;
    });
});




