Hamiltonian approach for a layered fluid system with a free surface