sendback = function(obj) {
  var y = $(obj).css("top");
  var x = $(obj).css("left");
  var z = $(obj).css("z-index");

  var active = $(".active").get(0);

  $(active).css("z-index", z);
  $(".midback", active).removeClass("autoheight");
  $(active).animate({top: y}, "normal").animate({left: x}, "normal");
  $(".box").removeClass("active").addClass("inactive");
}

bringtofront = function(obj) {
  
  $(obj).css("z-index", "7");
  $(obj).removeClass("inactive").addClass("active");
  $(obj).animate({top: 230, left: 350}, 1200, "easeOutBounce");
  $(".midback", obj).addClass("autoheight");
}

init = function() {
  $(".box").click(function() {
    if (!$(this).is(".active")) {
      sendback(this);
      bringtofront(this);
    }
  });
}
$(document).ready(init);

