Given a function $f\!: x\mapsto f(x)$ on some interval $I$ of length $L>0$ one obtains its Fourier expansion by extending $f$ to all of ${\mathbb R}$ periodically using the given $L$ as period length. The coefficients of the Fourier series should then be computed using the standard formulae for period length $L$ and integrating over the interval $I$ where the function $f$ was given in the first place.
In the case at hand we have $I=[0,\pi]$ and $L=\pi$, and the standard formulae give
$$a_k={2\over\pi}\int_0^\pi \sin x \cos(2 k x)\ dx,\qquad
b_k={2\over\pi}\int_0^\pi \sin x \sin(2 k x)\ dx.$$
Now there is the extra condition that we want only $\cos$-terms. In order to enforce this we must make sure that the periodically extended function is even. But here we are lucky: As $\sin(\pi -x)\equiv \sin x$ the extended function is even automatically. This means that in the above formulae the $b_k$ are all zero, and there remains nothing to be done apart from calculating the integrals for $a_k$.
It would be another matter if the given function would not have this symmetry with respect to $x\mapsto \pi -x$, as in the case of $g(x):=\sin{x\over 2}$ $(0 < x <\pi)$. In this case it would be necessary to extend $g$ first to an even function on the interval $[-\pi,\pi]$, whereupon the standard formulae for period length $2\pi$ can be applied to compute the $a_k$.
Development in cosine series means your function has to be even, so you define $f(x)=\sin(a|x|)$ on $[-\pi,\pi]$, and complete on $\Bbb R$ by periodicity. Then, your function is $2\pi$-periodic, continuous an piecewise $C^1$, hence the Dirichlet conditions apply.
Compute the Fourier coefficients:
$$a_n=\frac{1}{\pi}\int_{-\pi}^\pi \sin(a|x|)\cos(nx) \mathrm dx=\frac{2}{\pi}\int_{0}^\pi \sin(ax)\cos(nx) \mathrm dx$$
You have the identity $\sin(ax)\cos(nx)=\frac12[\sin(a+n)x+\sin(a-n)x]$, thus
$$a_n=\frac{1}{\pi}\int_{0}^\pi (\sin(a+n)x+\sin(a-n)x) \mathrm dx
\\=\frac1\pi\left(\frac{1-\cos(a+n)\pi}{a+n}+\frac{1-\cos(a-n)\pi}{a-n}\right)
\\=\frac{2a}{\pi(a^2-n^2)}\left[1-(-1)^n\cos(a\pi)\right]$$
For the last simplification, notice that $\cos(a+n)\pi=\cos(a-n)\pi=(-1)^n\cos(a\pi)$.
Then, for $x\in[0,\pi]$,
$$\sin (ax)=\frac{a_0}{2}+\sum_{n=1}^\infty a_n\cos (nx)=\frac{1-\cos(a\pi)}{a\pi}+\frac{2a}{\pi}\sum_{n=1}^\infty \frac{1-(-1)^n\cos(a\pi)}{a^2-n^2}\cos (nx)$$
Apart from the constant term, it's the same as your book's answer, in a slightly different form. Either you mistyped the answer, either there is a typo in your book.
Best Answer
First $b_n = 0$ means the sine coefficients must be 0, and that is because the function is even ( all sines are odd ). The rest is just applying the addition formula for sines and integrate. The red box is using $\cos(v+\pi) = -\cos(v)$ which you will realize if you take a look on the unit circle. Both x and y switch sign if you perform a half revolution.