This is a classic case of dergulation run wild, and some speculators were partly to blame, but have not accounted for the majority of foreclosures.
There was a significant demand for CDOs - The IBs couldn't package them up fast enough. The banks saw a great opportunity to lend and mitigate their risk - but you still need borrowers to take out the loans - and many who had no business having a credit card, let alone a mortgage, were lining up to get a mortgage.
All parties are to blame. Hence the drug dealer / drug addict analogy.