concerning the second problem I can suggest two ways
If you can use unique names for you LOOPs in a html, then you may use global vars like "SOMENAME_REVERSED" in the begin of html not inside of deep structures
If your LOOPs are not huge then you may provide the both direct and reversed representations of the list for each LOOP. e.g. <TMPL_LOOP NAME='NAME'> and <TMPL_LOOP NAME='NAME_REVERSED'>. So you don't need to detect anything