A foundation of the theory of trilattices