function _scrollimage() { this.StartScroll = StartScroll; var scrollamount = 39; var scroll = 1; function StartScroll() { scroll--; $('#imagescroller').css('margin-top', scroll + 'px'); if (scroll > -scrollamount * 8) { if (scroll % scrollamount != 0) setTimeout(StartScroll, 100) else setTimeout(StartScroll, 4000); } else { scroll = 1; setTimeout(StartScroll, 100); } } } scrollimage = new _scrollimage(); StartScroll = scrollimage.StartScroll;