Previous Version (http://www.sqlservercentral.com/scripts/SQL+Server+2005/61278/)
Iterates through sys.tables; performs an online index rebuild on indexes where the logical fragmentation is greater than or equal to the @LogicalFragmentationPercent parameter. The procedure can perform offline rebuild on indexes containing text, ntext, image, xml, varchar(max), varbinary(max) and nvarchar(max) or an offline rebuild by partition. This procedure is intended to reside in the msdb database and will conditionally create and populate a table called dbo.index_maintenance_history, configured via the @MaintainHistory parameter. This procedure can also produce and HTML report via the @EmailNotification paramter.
To utilize this with RedGate's SQL Script Manager, please save T-SQL above as usp_DBA_index_maintenance_SSC.sql along with the *.rgtool code, preferably in the C:\ProgramData\Red Gate\SQL Scripts Manager directory.
In the past several readers have posted problems w/ downloading the T-SQL from the WYSWYG editor. Should you encounter any of these types of issues, I've made the scripts available via my SkyDrive.