I wound say it fainted, but was probably knocked out, then regained consiousness, then it saw you and probably thought you were a threat and tried to fly away. He probably hit the window with suck force becuase being as he could see inside, he probably thought he could get inside aswell...
Well...