This question has been answered by Bruno17. See the first response.
[[*parent:is=`2`:then=`[[$gallerySript]]`]]
[[[[*parent:is=`2`:then=`$gallerySript`:else=``]]]]
Thanks Bruno17
Is there a script where it can detect the ultimate parent of a page?
yes, its name is: UltimateParent
http://modx.com/extras/package/ultimateparent