Your are right that you need to have a contract drawn up that spells out the rights of each of the parties in this situation.  You should probably meet with an attorney and go through what each party brings to the project and what each party would like to have rights to, and have the attorney draw up the contract.  It will be worth the small fee s/he will charge to have it done right.