Not sure about the intended results, but if you fetch the main_node of the current object you might not be identifying the actual node being viewed - eg. in case the given object is published at two different locations. Why not just use $node.parent_node_id?
Principal Consultant International Business
Member of the Community Project Board