Endogenous Parties: Cooperative and Non-cooperative Analysis