[eluser]wiredesignz[/eluser]
So you really want to reverse the $segments array first pull off the $page_name and add a check for $cat == NULL and assign the $sub_cat value to $cat.
Also in your example a $segments array with 4 elements or more will assign the first value to $page_name.