Cor, I said the just the minimum which demonstrates your problem. Oh well, I got nothing better to do right now, I'll have a look.
ADDITION: This is just an early guess since I haven't really sifted through all your code, but it looks like you are calling EraseLevelGraphics (and thus, FreeImage) after changing the screen mode. Changing the screen mode will clear all the graphics out of your scene, so calling FreeImage on an image which is already gone will result in an error. Try removing EraseLevelGraphics after the screen change.
ADDITION: This is just an early guess since I haven't really sifted through all your code, but it looks like you are calling EraseLevelGraphics (and thus, FreeImage) after changing the screen mode. Changing the screen mode will clear all the graphics out of your scene, so calling FreeImage on an image which is already gone will result in an error. Try removing EraseLevelGraphics after the screen change.