The standard (Apple-endorsed) way to do this is to install Snow Leopard from an official Mac OS X installation disc. Once Snow Leopard is installed, you can use the Mac App Store app to download and install the latest supported version of OS X for your Mac model.
You can buy the Snow Leopard installation disc here
http://www.apple.com/shop/product/MC573Z/A/mac-os-x-106-snow-leopard
If Mountain Lion is the latest version of OS X for your Mac model, you can order it here
http://www.apple.com/shop/product/D6377Z/A/os-x-mountain-lion
Your iMac is "mid 2007" or newer, and it has sufficient RAM, it can run the current version of OS X (El Capitan), which is a no cost upgrade from Snow Leopard.
https://www.apple.com/osx/how-to-upgrade/
EDIT: Second link was wrong. I corrected it.