Strange order behavior

Strange order behavior

Hey all,

I have a good lot of experience with javascript and jQuery but I am seeing something very strange today and I can't figure out what's going on. I've stripped down my code to the point where there's basically nothing going except for this weirdness. Here's my code:

function sortBy(column, direction) {
    $("#search_result_container #scrim_loader").show();
    for (var i = 0; i < 999999999; i++) {
        var y = i;
    }
    //$("#search_result_container #scrim_loader").hide();
}

notice that the last line is commented for now.

What I see is a delay of a couple seconds (presumably the for loop running) then the #scrim_loader is shown. Not before, but after the delay.

What I am trying to do is:
1) show loader
2) sort stuff (using for loop in place in this example)
3) hide loader


FWIW, I also did it in non-jQuery style:

document.getElementById('scrim_loader').style.display = "inline";

Any ideas what's happening here?

Thanks,
Dan