I am trying to mod my iPod 5G with an internal speaker. I have made enough space to fit but now I need to make a switch between headphones and internal speaker. I noticed while playing music if the headphones are unplugged the music is paused so there must be some headphone detection. All I need to do is make it switch to the speaker. How can I do this?

Thanks in advance.