$(document).ready(function() {
  //$(".answer_container").hide();
  //$(".test-builder-success").hide();
  //$(".question-edit-container").hide();
  
  $(".skills-app-form").each(function () { 
    var thisQu = $(this),
        questionOf = thisQu.find(".question-block").text();
    
    
    thisQu.find(".testbuilderquestion").val(questionOf);
    
    thisQu.find(".answer_type").change(function(){
      if ( $(this).val() == "1" ) { 
        thisQu.find(".answer_container").hide();
        thisQu.find(".answer_container.answer_text").show();
      }
      if ( $(this).val() == "2" ) {  
        thisQu.find(".answer_container").hide();
        thisQu.find(".answer_container.answer_multiple").show();
      }
      if ( $(this).val() == "3" ) {  
        thisQu.find(".answer_container").hide();
        thisQu.find(".answer_container.answer_multiple").show();
      }
    });
    thisQu.find(".test-builder-edit").click(function(){
      thisQu.find(".question-display").slideUp().fadeOut();
      thisQu.find(".question-edit-container").slideDown().fadeIn();
    });
    thisQu.find(".btn-saveedit").click(function(){
      if(thisQu.valid()) {
        thisQu.find(".question-display").slideDown().fadeIn();
        thisQu.find(".question-edit-container").slideUp().fadeOut();
        thisQu.find(".test-builder-success").slideDown().fadeIn();
        thisQu.find(".test-builder-success").delay(3000).slideUp().fadeOut();
      }
    });
    thisQu.find(".btn-cancel-edit").click(function(){
      thisQu.find(".question-display").slideDown().fadeIn();
      thisQu.find(".question-edit-container").slideUp().fadeOut();
    });
    thisQu.find(".btn-cancel").click(function(){
      thisQu.find(".answer_container").hide();
    });
    thisQu.find(".skills-app-form").submit(function() {
      return false;
    });
    thisQu.find(".test-builder-save").click(function(){
      if(thisQu.valid()) {
        thisQu.find(".answer_container").hide();
        thisQu.find(".test-builder-success").slideDown();
        thisQu.find(".test-builder-success").delay(3000).slideUp();
      }
      else {
        thisQu.find(".form-validation-script:invalid").css("border-color", "red");
      }
    });
    thisQu.find( ".btn-save" ).click(function() {
      if(thisQu.valid()) {
        window.location.href = "test-builder-success.html";
      }
    });
  });
  
});