/**
 * Created by JetBrains PhpStorm.
 * User: Slash
 * Date: 06/10/11
 * Time: 09:53
 * To change this template use File | Settings | File Templates.
 */

$(document).ready(function(){


    var voormiddag1 = $('#1voormiddag input[type=checkbox]');
     voormiddag1.click(function() {
        if($(voormiddag1).filter(":checked").length >= 1) {
            $(voormiddag1).not(':checked').attr("disabled", "disabled");
        } else {
            voormiddag1.attr("disabled", "");
        }
    });

    var namiddag1 = $('#1namiddag input[type=checkbox]');
    namiddag1.click(function() {
            if($(namiddag1).filter(":checked").length >= 1) {
                $(namiddag1).not(':checked').attr("disabled", "disabled");
            } else {
                namiddag1.attr("disabled", "");
            }
        });

    var voormiddag2 = $('#2voormiddag input[type=checkbox]');
    voormiddag2.click(function() {
        if($(voormiddag2).filter(":checked").length >= 1) {
            $(voormiddag2).not(':checked').attr("disabled", "disabled");
        } else {
            voormiddag2.attr("disabled", "");
        }
    });

    var namiddag2 = $('#2namiddag input[type=checkbox]');
    namiddag2.click(function() {
            if($(namiddag2).filter(":checked").length >= 1) {
                $(namiddag2).not(':checked').attr("disabled", "disabled");
            } else {
                namiddag2.attr("disabled", "");
            }
        });

    var voormiddag3 = $('#3voormiddag input[type=checkbox]');
    voormiddag3.click(function() {
        if($(voormiddag3).filter(":checked").length >= 1) {
            $(voormiddag3).not(':checked').attr("disabled", "disabled");
        } else {
            voormiddag3.attr("disabled", "");
        }
    });

    var namiddag3 = $('#3namiddag input[type=checkbox]');
    namiddag3.click(function() {
            if($(namiddag3).filter(":checked").length >= 1) {
                $(namiddag3).not(':checked').attr("disabled", "disabled");
            } else {
                namiddag3.attr("disabled", "");
            }
        });

    var voormiddag4 = $('#4voormiddag input[type=checkbox]');
    voormiddag4.click(function() {
        if($(voormiddag4).filter(":checked").length >= 1) {
            $(voormiddag4).not(':checked').attr("disabled", "disabled");
        } else {
            voormiddag4.attr("disabled", "");
        }
    });

    var namiddag4 = $('#4namiddag input[type=checkbox]');
    namiddag4.click(function() {
            if($(namiddag4).filter(":checked").length >= 1) {
                $(namiddag4).not(':checked').attr("disabled", "disabled");
            } else {
                namiddag4.attr("disabled", "");
            }
        });


   // This is a functions that scrolls to #{blah}link
  function goToByScroll(id){
        // Remove "link" from the ID
      id = id.replace("link", "");
        // Scroll
      $('html,body').animate({
          scrollTop: $("#"+id).offset().top},
          'slow');
  }

  $("#stages .zomerstageLink a").click(function(e) {
        // Prevent a page reload when a link is pressed
      e.preventDefault();
        // Call the scroll function
      goToByScroll($(this).attr("id"));
  });






   //$('#zomerstages').hide();

    $('#stages .top').click(function(){
       document.scrollTop();
    });

   /* $('#stages .zomerstageLink').click(function(){
       // $('#zomerstages').slideDown();

       // $(this).hide();

    });*/

   $('#content').fadeIn(200);

   /* $('#periode1').hide();
    $('#periode2').hide();
    $('#periode3').hide();
    $('#periode4').hide();

    $('#p1').click(function(){
        $('#periode2').slideUp();
        $('#periode3').slideUp();
        $('#periode4').slideUp();
        $('#periode1').fadeIn();

    });

     $('#p2').click(function(){
        $('#periode1').slideUp();
        $('#periode3').slideUp();
        $('#periode4').slideUp();
        $('#periode2').fadeIn();

    });

     $('#p3').click(function(){
          $('#periode2').slideUp();
        $('#periode1').slideUp();
        $('#periode4').slideUp();
        $('#periode3').fadeIn();

    });

     $('#p4').click(function(){
          $('#periode2').slideUp();
        $('#periode3').slideUp();
        $('#periode1').slideUp();
        $('#periode4').fadeIn();

    });

*/
    /*$('#inhoud2').hide();*/

    $('#stages .underline').click(function(){
        $('#inhoud').fadeOut();
        $('#inhoud2').fadeIn();



        $('#stages .goud').hover(function(){
                $(this).css("cursor", "pointer");
                $(this).css("text-decoration", "underline");
                }   ,function(){
                    $(this).css("text-decoration", "none");

            });

    });



    $('#stages .goud').click(function(){
        $('#inhoud2').fadeOut();
        $('#inhoud').fadeIn();
    });

    $('#stagePeriodes').hide();
    $('#stap2').click(function(){

        if ($('#samenvatting ul li').length == 0){
           // alert ('test stap 2');

        }

    });
    
    //variablen
    var content = $("#content");
    var sections = $("menuStages li");

    sections.click(function(){
        switch(this.id){
            case "info":
                content.fadeOut();
                content.load("#inhoud");
                content.fadeIn;
                break;
            case "inschrijven":
                content.fadeOut();
                content.load("#inhoud2");
                content.fadeIn;
                break;
        }
    })



});


$(init);
function init(){

   /* $('.topnav li a').click(getPage);*/
    $(pika);

    $.ajaxSetup({
        error:function(XMLHttpRequest, textStatus, errorThrown){
            alert('Error: [' + textStatus + ']' + XMLHttpRequest.statusText + ' ' + errorThrown);
        },
        timeout:5000

    });



    $(sidebarScrollAanbod);


}


function pika(){
    $("#pikame").PikaChoose({autoPlay:true, transition:[5], animationSpeed:1000});

}


function getPage(e){
    e.preventDefault();

    $.ajax(
        {
            type: 'POST',
            url: $(this).attr('href'),
            succes:function(data){
                console.log(data);
                $('#inhoud').empty();
                $('#inhoud').append(data);
            }
        }
    )
}


function sidebarScrollAanbod(){
    var offset = $("#aanbodmenu").offset();
               var topPadding = 15;
                var marginX = 0;
               $(window).scroll(function() {
                   if ($(window).scrollTop()  > offset.top + marginX) {
                       $("#aanbodmenu").stop().animate({
                           marginTop: $(window).scrollTop() - offset.top + topPadding - marginX
                       });
                   } else {
                       $("#aanbodmenu").stop().animate({
                           marginTop: 0
                       });
                   };
               });

}





