$(document).ready(function() {
  /* variables */
  var preview = $('img');
  var statusausgabe = $('.status');
  var progress_bar = $('.progress-bar');

  /* only for image preview */
  $("#image").change(function(){
    preview.fadeOut();

    /* html FileRender Api */
    var oFReader = new FileReader();
    oFReader.readAsDataURL(document.getElementById("image").files[0]);

    oFReader.onload = function (oFREvent) {
      preview.attr('src', oFREvent.target.result).fadeIn();
    };
  });

  /* submit form with ajax request */
  $('form').ajaxForm({

    /* set data type json */
    dataType:  'json',

    /* reset before submitting */
    beforeSend: function() {
      statusausgabe.fadeOut();
      progress_bar.width('0%');
      progress_bar.html('0%');
    },

    /* progress bar call back*/
    uploadProgress: function(event, position, total, percentComplete) {
      var pVel = percentComplete + '%';
      progress_bar.width(pVel);
      progress_bar.html(pVel);
    },

    complete: function(data) {
	  /* var statusausgabe = $('.status'); */
      preview.fadeOut(800);
     /* statusausgabe.html(data.responseJSON.statusausgabe).fadeIn(); */
    }

  });
});