var ShowError = function () { var curHeight = $('#pop-error').height(); $('#pop-error').css('height', 'auto'); var autoHeight = $('#pop-error').height(); var autoMargin = parseInt(autoHeight/2); $( "#pop-error" ).show( "slow" ); $("#pop-error").height(0).animate({ "height": autoHeight, "margin-top": autoMargin, opacity: 1 }, "Slow", function() { $("#pop-error").delay(2000).animate({ "height": "0px", opacity: 0 }, "Slow"); $( "#pop-error" ).hide( "slow" ); }); }