Add the butter and onions to a large skillet over medium heat and saute until starting to soften, 3 to 4 minutes. Sprinkle the flour over the onions and whisk them together. Continue cooking the onion/flour mixture until golden brown, about 2 minutes. Stir in the half-and-half and milk and whisk around, allowing the mixture to thicken; this will take 3 to 4 minutes. Add some pepper, stir the sauce, reduce the heat and keep warm.
Slice the potatoes really thin using a mandolin or a really sharp knife, the thinner the better. Generously butter a 2-quart baking dish, then add half the sliced potatoes and half the diced ham. Sprinkle on half the cheese then pour on half the sauce from the skillet. Repeat with the rest of the ingredients, ending with a layer of cheese and sauce. Sprinkle extra pepper on top.
Cover the dish with foil and bake it for 40 minutes, then remove the foil and bake until the cheese is golden brown and the sauce is bubbling, an additional 20 to 30 minutes. Sprinkle with chopped parsley if desired and serve it up.