Onclick in a tag can't work with if statement

I don’t understand why the image swapping doesn’t work when I click the 2nd time:

<a href="JavaScript:;" onclick="if(document.getElementById('img-book_1').src!=='images/minimize.jpg'){document.getElementById('img-book_1').src='images/minimize.jpg';}else{document.getElementById('img-book_1').src='images/maximize.jpg';}"><img id="img-book_1" src="images/maximize.jpg" style="float: right;border: none;" /></a>

On the first click it swaps to the 2nd image but on the 2nd click it doesn’t swap back to the first.

src always contains the full URL regardless of what is assigned to it. Try:

<a href="#" onclick = "var img = document.getElementById('img-book_1'); img.src = ( img.src.search('minimize.jpg') > -1 ? 'images/maximize.jpg' : 'images/minimize.jpg' ); return false;">
 <img id="img-book_1" src="images/maximize.jpg" style="float: right;border: none;" />
</a>