function Test(a, b, c) { this.SetDelay(500); this.SetContainer(a); this.SetImageList(b.reverse()); this.SetString(c); this.Mode = -1; this.Paused = false; this.Image = new Image(); var t = this; $(document).keypress(function() {t.Unpause();}) } Test.prototype = { Start: function() { var t = this; this.Interval = window.setInterval(function(){t.Step();}, this.Delay); }, Stop: function() { this.Mode = -1; this.Paused = false; window.clearInterval(this.Interval); }, Pause: function() { this.Paused = true; window.clearInterval(this.Interval); }, Unpause: function() { if (this.Paused) { this.Paused = false; this.Start(); } }, SetString: function(a) { this.String = a; }, SetImage: function(a) { this.Image.src = a; }, SetImageList: function(a) { var l = []; for (x in a) { l.push(new Image(a[x]); } this.ImageList = l; }, SetContainer: function(a) { this.Container = a; }, SetDelay: function(a) { this.Delay = a; }, Step: function() { /* Modes: S0: Viðbúinn! S1: Stafur S2: Bið S3: Bið S4: Tómt S5: Mynd (halt) */ this.Mode++; if (this.Mode == 6) { this.Mode = 0; } switch(this.Mode) { case 0: this.Container.empty(); this.Container.addClass("ready"); this.Container.text("Viðbúinn!"); break; case 1: this.Container.removeClass("ready"); this.Container.addClass("letter"); this.Container.text(this.String[0]); this.String = this.String.substr(1, this.String.length); break; case 2: case 3: break; case 4: this.Container.text(""); case 5: this.SetImage(this.ImageList.pop()); this.Container.append(this.Image); this.Pause(); } } }