$(document).ready(function() {
  $(".VT_formExpand").css("overflow", "hidden"); // Clip overflowing content for expanding elements.
  
  $(".VT_formExpand").each(function(index, obj) { // Set original variables for expanding elements.
    var el = $(this);
    el.data("VT_shrunkHeight", el.height() + "px"); // Save the original heights.
    el.data("VT_formExpandTouched", false);
    el.data("VT_formExpandExpanded", false);
    el.data("VT_formExpandAnimating", false);
  });
  
  $(".VT_formExpand").hover(
  function() { // Mouse over.
    var el = $(this);
    if (!el.data("VT_formExpandExpanded") && !el.data("VT_formExpandTouched") && !el.data("VT_formExpandAnimating")) { // Element hasn't been touched yet and isn't currently animating.
      el.css("height", ""); // Remove height restriction.
      var newHeight = { height: el.height() + "px" }; // Get new height.
      el.css("height", el.data("VT_shrunkHeight")); // Re-shrink div.
      el.animate(newHeight, "fast", function() { // Call-back function when animation is done.
        el.data("VT_formExpandAnimating", false); // Clear animating flag.
        el.data("VT_formExpandExpanded", true); // Flag as expanded.
      });
    }
  },
  function() { // Mouse out.
    var el = $(this);
    if (!el.data("VT_formExpandTouched") && !el.data("VT_formExpandAnimating")) { // Element hasn't been touched yet and isn't currently animating.
      var newHeight = { height: el.data("VT_shrunkHeight") }; // Get new height from saved value.
      el.data("VT_formExpandAnimating", true); // Flag as animating.
      el.animate(newHeight, "fast", function() { // Call-back function when animation is done.
        el.data("VT_formExpandAnimating", false); // Clear animating flag.
        el.data("VT_formExpandExpanded", false); // Clear expanded flag.
      });
    }
  });
  
  $(".VT_formExpand").click(function() {
    var el = $(this);
    el.data("VT_formExpandTouched", true); // Flag this element as touched so it will stay expanded.
    el.css("height", ""); // Remove height restriction.
  });

  // Load another page's content into div.
  $('#temp_container').load('simple_contact_form form', function() { // Grab form content and dump into temp container.
    var codeTr = $('#temp_container input[name=IIT_key]').closest('tr'); // Get the TR containing the security code.
    $('#simple_contact_form tr.VT_codeRow').html(codeTr.html()); // Dump security code content into custom form.
    $('#temp_container').html('cleared'); // Clear content from temp container.
  });
});

