Thanks for your questions.
You are suffering from gender identity disorder
where a male/female thinks his/her mind as opposite sex and they attract with person of same sex.But actually why it happens no body knows and we dont have any preventive measure for that neither we have any drug to control them.
The best therapy is psychoeducation
or psychological counselling
and that help a lot to cope up with the problem so please visit a psychiatrist
and tell your problem in detail,he will surely help you.