1 define(function () {
  2 
  3     var Playlist = Class.extend({
  4         
  5         init: function () {
  6 
  7             this.reset();
  8         },
  9         _extract: function(tracks, cursor) {
 10             var track;
 11             if (this.cursor < tracks.length) {
 12                 track = tracks[this.cursor];
 13                 this.exhausted = false;
 14             } else {
 15                 track = false;
 16                 this.exhausted = true;
 17             }
 18             return track;
 19         },
 20         current: function () {
 21             return this.exhausted ? false : this.tracks[this.cursor];
 22         },
 23         append: function (tracks) {
 24             this.tracks = this.tracks.concat(tracks || []);
 25             this.length = this.tracks.length;
 26         },
 27         getTracks: function () {
 28             return this.tracks;
 29         },
 30         reset: function () {
 31 
 32             this.cursor = 0;
 33             this.exhausted = true;
 34             // TODO reset shouldn't create a new object for tracks
 35             this.tracks = [];
 36             this.length = 0;
 37         },
 38         next: function () {
 39             var track;
 40             if (this.exhausted) {
 41                 track = this._extract(this.tracks, this.cursor);
 42             } else {
 43                 this.cursor++;
 44                 track = this._extract(this.tracks, this.cursor);
 45             }
 46             return track;
 47         }
 48     });
 49 
 50     return Playlist;
 51 });
 52