He won the primaries.
There is a major shift that happened during the summer, when he switched campaign advisors..AND when Palin came onboard. I say came onboard, because there is ample evidence she was not his first selection, or even on HIS radar.
One noted thing that happened was that James Dobson (focus on family) had stated he would not endorse McCain (meaning- heavy conservative support). I personally think McCain was told that he HAD to pick someone ultra anti abortion as running mate, in order to pull in money. They also felt the ticket needed a woman, in theory to get the woman voters. There were other qualified women in the GOP... but they were not anti abortion.
Sure enough..after Palin, Dobson endorsed McCain.
I am sure that he realized many things, but was pressured into choosing Palin, which completely backfired.