You want the best lens but you don't want to spend over 1k?
Questionable.
The 24-105 f/4 is pretty good, but is really more of a full-frame lens. It's not nearly as versatile on a 40D...
I've heard enough good about the 17-55 to believe that it can hold its own with L glass optically. The lack of the L classification is more because it's an APS-C only and the lack of weather sealing.
If you have the cash, but are merely 'not too interested in spending over $1k for a lens', get over it and spend the cash. You will find it very, very hard to get around the old adage that you 'get what you pay for'. If that lens will be on your camera 80-90% of the time, then go for it.
My recommendation: Canon 17-55 f/2.8 IS.
Additionally, if you are looking for a really good portrait lens, I *strongly* recommend the 50mm f/1.4 USM. Vastly superior to the f/1.8 and does very well when compared to the f/1.2. Yes, it's better in low light, but it's really all about the control over the bokeh with that lens. Plus it's sharp enough to shave with in light levels that are well below what any zoom can handle.
The 50mm prime is the one that is going to make all the best portraits when you are planning a shot. The 17-55 is your walk-around, indoor-outdoor.
ADDED:
24-70 f/2.8 is great for the 5D. Not so great with the 40D. I use the wide end of my Tammy 17-50 a lot. I have used quite a number of lenses on quite a number of cameras and find the wide end of the 17-50 type lens to be much more important than the long end of the 24-70.
If you are shooting kids, you will definitely want that wide end. it's great for exaggerating perspective.
If you don't have the 10-22mm Canon lens, it's highly unlikely that you will want to be restricted by 24mm on the wide end.
If you have a kit lens or something kicking about, try it at 24mm and walk around a bit. Then zip it over to 18mm and see how things look through that. Totally different ball of wax. I think about 70% of all my pics with the 17-50 occur between 17mm and 24mm. Maybe 60%. For those shots, I'd probably be cursing my 24-XXmm for not being wide enough.
Personally, I'd take the Canon 24-70L over the 24-105L, but that's just because I'm prejudiced against anything over f/2.8 and I'm not so afraid of camera shake with a mid-range zoom lens. IS is most useful on long lenses.
That doesn't mean that I wouldn't go for the Canon 17-55 IS because I think it's a heck of a combination. If you can afford it, go for it.
You could go for a 10-22mm and a 50mm f/1.4 if you wanted as well, but you would need to be really good with a flash to make that work right and that can be a bit cumbersome when chasing kids and trying to catch just the right moment.