A good read about preventing of this annoyment can be found here: http://www.decision-web-design.com/security-hacking-articles/prevention
Joomla checklist: https://docs.joomla.org/Security_Checklist/You_have_been_hacked_or_defaced
and here: https://www.stopthehacker.com/2012/06/19/cleaning-up-malware-infected-websites/
Always fully update and patch, monitor, have back-ups ready.

polonus