var a = $('a[class^=ad-thumb]'), n = a.index($("a.ad-active")), id; n = (n == a.length-1) ? 0 : n+1; id = a[n].id;