The cross section for the photoproduction of large-p(T) J/psi mesons a
t DESY HERA is calculated at next-to-leading order. adopting a perturb
ative approach to describe the fragmentation of charm quarks and gluon
s into J/psi mesons. We treat the charm quark according to the massles
s factorization scheme, where it is assumed to be one of the active fl
avors inside the proton and the resolved photon. We present inclusive
distributions in transverse momentum and rapidity, including the contr
ibutions due to direct and resolved photons. The importance of the col
or-octet components of the J/psi wave function, which contribute to th
e fragmentation process, is emphasized. In addition to prompt J/psi pr
oduction, we consider also the production of chi(cJ) states followed b
y radiative decays to J/psi mesons, both in the color-singlet and colo
r-octet channels.