$("img").index($(this))

cmq dovrebbe funzionare anche come hai fatto tu