Almost all courts use a standard that gives the "best interests of the child" the highest priority when deciding custody issues. What the best interests of a child are in a given situation depends on many factors, including:
Assuming that none of these factors clearly favors one parent over the other, most courts tend to focus on which parent is likely to provide the children a stable environment, and which parent will better foster the child's relationship with the other parent. With younger children, this may mean awarding custody to the parent who has been the child's primary caregiver. With older children, this may mean giving custody to the parent who is best able to foster continuity in education, neighborhood life, religious institutions, and peer relationships.
For practical and legal advice on creating a fair and reasonable custody agreement, get Building a Parenting Parent Agreement That Works, by Mimi Lyster Zemellman. (Nolo).