What does Buddhism literature and tradition say about transgender folks? This may seem like a question that is far too modern for an ancient tradition, but when I traveled in Thailand I learned that katoeys (male-to-female) are a legal gender in Thailand.  What does Buddhism say about the folks who experience discomfort or distress because there is a mismatch between their biological sex and gender identity?

As it becomes less dangerous for transgender folks to change, I am finding out that several of my friends are transgender and I would like to know what Buddhism offers them.
The Bodhisattva Avalokitesvara can be seen as having an indeterminate gender. Quoting from this website 


  One interpretation of this development contends that the bodhisattva
  is neither male or female but has transcended sexual distinctions
  [...] the flowing drapery and soft contours of the body seen in
  statues and paintings have been intentionally combined with a visible
  moustache to emphasize the absence of sexual identity.


So the issue of gender can take on a more flexible interpretation with some more Mahayana aspects of Buddhism