function newtheorem(img) {
    jQuery.ajax({
	url: "/misc/theorem/gen.pl",
	dataType: "text",
	success: function(txt) {
	    jQuery(img).attr('src', txt);
	}
    });
}

// when the DOM is ready
jQuery(document).ready(function($){
    var img = new Image();
    $(img).load(function () {
	$(this).hide();
	$("#loader")
	    .removeClass('loading')
	    .append(img);
	h = $(this).height();
	if($('#loader').height() == h) {
	    $(this).fadeIn();
	} else {
	    $('#loader').animate({height: h}, 500);
	    $(this).animate({opacity: 1}, 500).fadeIn();
	}
    });
    $("#generate").click(function () { newtheorem(img); });

    newtheorem(img);
});

