Oh Dear, This actually is a problem of software driver, if it doesn't happens in Vista. There is no standard way in Windows to solve this problem. I have heard there is a Windows Update that solves this problem so update your system using Windows Update utility, if you have a genuine copy of Windows XP. Also, go to the properties of the HD audio (must be in your system tray, near the clock), go to analouge and in there unselect "automatic headphone detection".
Maybe this image help you to locate it :
If it doesn't work at the first go, try uninstalling the drivers from Add/Remove programs and then reinstall after system restarts. Then try the same thing and I hope it will work out properly.