var SlideshowPaint = new Class({ initialize: function(containerId, myImages) { // global vars this.container = $(containerId); this.myImages = myImages; this.currenBgIndex = 0; this.frameDelay = 5000; // set intial bg this.setBg(); //start slideshow this.setBg.periodical(this.frameDelay, this); }, setBg: function(curImage) { curImage = this.myImages[this.currenBgIndex] this.container.setStyle('backgroundImage', 'url(' + curImage + ')'); if(this.currenBgIndex == (this.myImages.length-2)){ this.currenBgIndex = 0; } else { this.currenBgIndex++; } } });