You can use something like this, using the jQuery Deferred Object ( see Docs )
var Shown = false;
function ShowLoadingGif() {
var $promise = $.Deferred();
$("#loading").show("fast", function() {
$promise.resolve("Im done");
});
$promise.done(function(data) {
// data === "Im done"
});
}
I have updated your Fiddle that now alerts when the stuff has finished as you would expect
Fiddle (http://jsfiddle.net/k5Wan/3/)
Also I have updated the code quality
var $promise = $.Deferred();
$promise.done(function() {
alert("Done...");
});
$(function() {
$("button").on("click", function() {
$("#loading").show("slow", function() {
$promise.resolve();
});
});
});