Hi Katopunk
Your second itinerary seems much better, it would be crazy to fly to Madrid and go up to the north only to return to Madrid again.. And, I totally agree that you should visit Barcelona, I live there now and it is an amazing city just be warned that it is not cheap to stay here especially since you are travelling in high season (this goes for every place you will be travelling to). When there is no option for couchsurfing check out hostelworld.com and gomio.com, both website have a broad offer of hostels all around the world.
You have a limited amount of time to visit all these places, take 3 days for Barcelona and Madrid if you really want to get a ´feel´ of the city. 2 days would be possible if you are only going to see the highlights, just what you prefer, but I would try to go for three. Be sure to count in the travel time!
http://gospain.about.com/od/gettingaroundspain/qt/how_get_city_to_city.htm Check this link for the travels you have to make, they have a lot of links from city to city by different types of transport so you can calculate the time and price for it. Check if it is possible to take nightbusses/trains for some destinations because you might save on accommodation that way.
Just some tips for Barcelona, since I know most about that city: Check out Parc Guell, Sagrada Familia, Casa Mila & Batllo (if you want to enter one of these, mila is cheaper but batllo has a more impressive interior), walk trough the streets of Ciutat Vella (around the Ramblas to Barceloneta) and Gracia, don´t spend much time on the Ramblas (they are way overrated in my eyes).
If you want to spend time on the beach consider taking the train outside of BCN to Sitges (in the south) or direction of Blanes (North) because it is quieter, cleaner and without people asking you if you want beer/cocos/massage/tattoo every minute.
Keep a close eye on your stuff because there BCN is infamous for pickpockets. To me, never anything happened, just try to look the least touristy as possible and keep your hand on your bag at crowded places. Don´t take out big amounts of money and leave creditcards etc in a save place if possible.
When you feel like sitting down for a drink walk away from the touristy areas into the smaller streets to save money.
Don´t worry too much of getting accommodation in the centre, outside it is prob. cheaper and the public transport is very good and cheap.
Hope this helps you! let me know if you have more questions.
OHannemarie
(Oh-Barcelona)