Great post. I agree with you on the different foundations of religion, and also how they have been or how they might be eliminated over time.
I have always thought of religion and science as two sides of the same coin. When humans developed self and environmental awareness, we probably had many questions about the world and how it worked. With our early beginnings, and specifically, the beginnings of civilization, much of humanities time revolved around crop production. It makes sense that many early religions tried to appease the sun, atmosphere, and the seasons.
Religion's function is to help explain the world which we cannot explain, and as a result, offer comfort when there are so many unknowns. It evolved as a tool of comfort, but obviously came with many terrible side effects, the worst being a violent divider of people. Over the past century we have revealed so much about the universe that there are less questions to be answered, and less need to use religion as a guiding post. As a result, we see a trend towards new atheism and a new sense of spirituality, or connectedness with one's self, while religious systems become less able to offer the comfort it once did. Religion will suffer even more when we finally answer the questions of extraterrestrial life and possibly the origins.
However, it seems to me that as long as there are questions that have yet to be solved by science, humanity will find a use for religion. This is why I say "two sides of the same coin." As long as there exists some "unknown" about the Universe, religion will have an applicable place; somewhere to hide where it can't be disproved until science has a look. Similarly, as long as there are unknowns about the Universe, science is the only useful tool to really uncover the mystery. As soon as the entire universe has unfolded before our eyes, and once science has solved everything, religion disappears. But so does the need for science. I don't believe we will ever come to this point because surely the Universe extends beyond what we currently perceive as possible, and its complexities may develop infinity.
I always considered the greatest irony to be if there is a god, that they are a scientist who simply discovered a way to program or create a universe.