Haven't looked at your code since I can't be bothered to try to decipher poorly formatted code right now, but I'd bet the problem is you're trying to use changeimgpart with a width or height of zero. Hide the HP/MP/whatever bars when they're at zero to fix it.
Please format your code prior to posting it. If nothing else, use
this.