I am planning a trip to the US next year and will be travelling around. My idea was to spend a total of six months in the country. I appreciate that under the VWP I will have 90 days initially.
There is no official answer to your question.
Technically when you leave the US and travel to a country other than Mexico or Canada (or some locations in the Caribbean) your current VWP entry will end, and when you re-enter a period of time later you will be given a new VWP, with another 90 days of validity.
However, as with any time that you are entering a foreign country, it is up to the discretion of the the immigration officers as to whether they will let you into the country, and they can ask you any questions they wish in order to determine your intent.
If, in the opinion of the immigration officers you are either intending to stay over 90 days, and/or if they believe that you have taken a short trip out of the country simply as a "visa run" in order to extend your VWP status within the US, then they will almost certainly deny you entry when you try and re-enter the second time.
Even if they don't see this as a "visa run", I would expect them to question you over what you are doing in the US for 6 months, and how you intend to financially support yourself there without working - which is not allowed on a VWP visa.
The recommended way to say for 6 months would be to apply for a B2 Tourist Visa, which will allow you to stay in the country for up to 6 months.
This answer is pretty much the same as Doc's, but with some official evidence. Read Doc's answer as well for a more complete picture.
If you go to Canada and Mexico or the Caribbean, and while you are there, your initial 90-day period of entry expires, but you need to come back in to the U.S. to fly home, you may encounter a problem. The terms of the VWP are very clear - it is only to be used for occasional, short visits to the U.S. If the CBP Officer thinks you are trying to "reset" the clock by making a short trip out of the U.S. and re-entering for another 90-day period, you can be denied entry. (If that happens, you will have to obtain a visa for any future travel to the U.S.) In order to be re-admitted to the U.S. shortly after a previous admission expired, you will have to convince a CBP Officer that you are not trying to "game" the system.
If you visit other countries such as England or Costa Rica, then return to the U.S., your re-entry will be considered to be a new admission (thereby restarting the 90 day clock), rather than a re-entry from a contiguous country in the course of your initial visit, and the admission inspection may be more strenuous. The Officer inspecting you will want evidence that you intend to go back home to your country of citizenship to live as opposed to returning again and again to the U.S. after visits to other countries.