I think this is mostly answered, but I'll add some examples.
When a lens is focused at a particular distance, the image will appear sharp from some distance in front of the focus point to some distance behind it. The range from "nearest sharp point" to "most distant sharp point" is called depth of field (DOF).
Here's a Wikipedia example. The focus point is the "depth of field" text, and the DOF extends approximately from the line below to the line above:
DOF depends on three factors. (That is, three factors you can easily change. DOF also depends on the size of the camera sensor, how large you want to print or display the picture, how closely you look and how critical you are, but I'll assume that these are constant.)
The factors you can easily change are
Aperture: Smaller aperture gives more DOF.
Example: (All examples for Nikon D5100 or other APS-C 1.5x crop camera.)
55mm f/5.6, focus at 10 feet: DOF range from 9 to 11 feet (2 feet total)
55mm f/22, focus at 10 feet: DOF range from 7 to 18 feet (11 feet total)
Distance: More distance from camera to focus point gives more DOF.
55mm f/5.6, focus at 10 feet: DOF range 9 - 11 feet (2 feet total)
55mm f/5.6, focus at 20 feet: DOF range 16 - 26 feet (10 feet total)
Focal length: Shorter focal length gives more DOF.
55mm f/5.6, focus at 10 feet: DOF range 9 - 11 feet
18mm f/5.6, focus at 10 feet: DOF range 5 feet to infinity
So to maximize the depth of field, the basics are
- Shortest possible focal length
- Smallest possible aperture (although at very small apertures you run into diffraction blur instead)
- If possible, increase distance between camera and foreground
- Focus slightly behind the foreground subject, to exploit the fact that DOF extends some distance in front of the focus point.
- 18mm f/22, focus at 2 feet: DOF range from 1 to 12 feet
- 18mm f/22, focus at 10 feet: DOF range from 2 feet to infinity
- 18mm f/22, focus at infinity (the mountains): DOF range from ~2.5 feet to infinity.
So you could have everything from 2 feet to infinity in focus, by focusing at 10 feet.
If you want to go advanced, you could improve DOF slightly by focusing at what's called the hyperfocal distance. (Although you would need a table or calculator to look it up.)
Focusing at the hyperfocal distance gives the maximum possible depth of field, in this case that's
- 18mm f/32, focus at 1.7 feet (hyperfocal distance): DOF range from 0.9 feet to infinity
That's the best optics can give you. If you need more than that, you'll have to fake it by taking multiple shots and merging them.
You can find these values from an online DOF calculator like the one ElendilTheTall linked to.
Just select your camera (or another camera with the same size sensor, like D5000 in your case) and fill in focal length, f-stop and focus distance.
Note that these DOF values are only approximate: The DOF range is calculated using a definition of "acceptable sharpness" - subjects at the edges of the DOF range will be slightly out of focus, but we might still call them "acceptably sharp" - and what you consider acceptable will probably differ from the standard definition.
You will have to experiment to find your own limits, but a DOF calculator is a good starting point.