Paragraph of the week already folks........
I'd love to take credit for it, Ian, but the truth is that insight was stolen from my ex-father-in-law who was a botanist, with a speciality in the micro evolution of plants and insects. He used to teach a course on Plants and Man, back in the old days and wrote a nice, short little book on it. He included marijuana, coca, and opium as part of our biological, cultural and social dependence on plants.
Although he didn't investigate the idea that plants might have evolved this dependence on their pharmacological properties, I don't see any reason not to think they might have. If they can evolve nectars to include the particular lipids and proteins that their pollinators require for basic nutrition, I don't see why they wouldn't have found themselves selected by the animal world for their ability to produce various other complex chemical substances as well.
Strictly judging on how stoned my cat used to get, I would assume that a lot of animals were fooling around with drug plants long before we did.