Some PHP code to extend AD-Gallery (http://coffeescripter.com/code/ad-gallery/)