Not An Easy Decision
Judges must weigh several factors when making a custody determination. Financial responsibility of the parents, moral responsibility, home environment, other relatives that are involved in the children's lives - all of these factors and more are considered and used to help with the determination.
But if you think this makes the decision clear by the end of the custody hearing, think again.
The following case from Independence County, Arkansas illustrates this point.
http://courts.state.ar.us/unpublished/2007a/20070131/ca06-486.pdf