  function nextStep() 
    {
      nextstep = "#step" + (approved+1);
      setTimeout("$(nextstep).click()", 200);
      loadDynamicParts();
  }

  /* goedgekeurde stappen */
  approved = 0;
  function approve(i) {
    $('#checkout> .header').slice(0,i).removeClass('current-step').addClass('approved');
    $('.editlink').slice(0,i).show();
    if (i > approved) {approved = i;}
    
    //geef huidige stap class current-step
    $('#checkout> .header').eq(approved).addClass('current-step');
  }

  function loadDynamicParts()
    {
      //stap 3 dynamisch
      $('#step3').next('.step').load(
        'step3.php', 
        {limit: 25},
        function() {
         $("#confirmform").validate({ 
              errorClass: "invalid", 
              errorLabelContainer: $(".errorBox2"), 
              wrapper: "span", 
              event: "blur",
              submitHandler: function(form) {
                $("#register").ajaxSubmit({
                  beforeSubmit: function() { $.blockUI(); } ,
                  success: function() { 
                    $.unblockUI();
                    approve(3);
                    nextStep();
                  }
                });
              }
            });
        }


      );
 


      //stap 4 dynamisch
      $('#step4').next('.step').load(
        'step4.php', 
        {limit: 25},
        function() {
            tb_init('a.thickbox, area.thickbox, input.thickbox');
        }
      );



    }


$(document).ready(function() {
  var checkCreateAccount = function() {
    if ($('#createaccount:checked').length != '0') { 
      $('#accountcreate').slideDown('slow');
    }
    else {
      $('#accountcreate').slideUp('slow');
    }
  }


  /* accordion */
  function isClickable(header) {
    /* vorige stappen goedgekeurd ? */
    var index = ($('#checkout> .header').index(header));
    if (index > approved) {
      return false;
    }

    /* al zichtbaar?  */
    if ($(header).next(':hidden').length) {
      return true;
    }

    
  }

  $('#checkout> .header').click(function() {
    var $showDiv = $(this).next('.step');
    if (isClickable(this)) {
      var $visibleSiblings = $showDiv.siblings('.step:visible');
      if ($visibleSiblings.length) {
        $visibleSiblings.slideUp('normal', function() {
        $showDiv.slideToggle('slow');
        });
      } else {
         $showDiv.slideToggle('slow');
      }
    }
    $('html,body').animate({scrollTop: 1000000}, 1000); 
  });
  /*einde accordion */



  function init() {
    //new checkCreateAccount();
  }





  $("#register").validate({
    errorClass: "invalid", 
    errorLabelContainer: $(".errorBox"), 
    wrapper: "span", 
    event: "blur",
    submitHandler: function(form) {
      $("#register").ajaxSubmit({
        beforeSubmit: function() { $.blockUI(); } ,
        success: function() { 
          $.unblockUI(); 
          approve(1);
          nextStep();
        }
      });
    }
  
  });


  $.blockUI.defaults.pageMessage = "<h2>Een ogenblik geduld alstublieft...</h2>";
  init();
  approve(0);
  $('#createaccount').bind('click', checkCreateAccount);
  $('.step').eq(0).show();



/* code voor pagina 2 */
var checkSpecify = function() {
  if ($('#specify:checked').length != '0') { 
    $('#specific_address').slideDown('slow');
    $(".errorBox2").show();
  }
  else {
    $('#specific_address:visible').slideUp('slow');
    $(".errorBox").hide();
  }
}

    checkSpecify();


    $('#specify').bind('click', function(){
      checkSpecify();
    });


     $("#adresform").validate({ 
        errorClass: "invalid", 
        errorLabelContainer: $(".errorBox2"), 
        wrapper: "span", 
        event: "blur",
        submitHandler: function(form) {
          $("#adresform").ajaxSubmit({
            beforeSubmit: function() { $.blockUI(); } ,
            success: function() { 
              $.unblockUI();
              approve(2);
              nextStep();
            }
          });
        }
      });




	$('.step').hide();
    });

