It's simple. When you buy a stock, you are buying a piece of a company. If the company does well, so will your stock (over time). There is all kinds of irrational behavior over the short term, so price at any given moment may not be an indicator of the business' intrinsic value.
So, to take casebro's objection. If stock prices are currently high compared to the business' intrinsic worth, certainly prices will fall if retirement money falls off. But then prices will fall, prices will become attractive, and that will attract foreign investment.
If you are buying either to try to ride a short term gain, or because you think you can predict the stock market (no one has ever shown any evidence of being able to do either), then you are gambling. If you are buying high quality companies at a fair price with the intention of owning them for years to decades, then it is not a gamble. The latter is called Value investing - look in to Graham and Dodd, Warren Buffett, Searle, etc.
Are prices high or low right now? I won't tell you, but I suggest looking at the P/E ratio of the stock market (use a broad index, not DJIA) and dividends, and decide whether you would buy a single company with those numbers, assuming it is fundamentally sound. If your answer is yes, go ahead and put your money in some index funds. If your answer is no, look to other methods to invest than index funds.
ETA: my post implies I am unfamiliar with Efficient Market Theory and/or Malkiel's random walk theory. I am familiar with both, I just don't buy them. If you are seriously interested in this topic, you owe it to yourself to study both and come to your own conclusions.