var Episode = function(data, series_data){
  this.id = data.mid
  this.name = data.name.replace('&', '&amp;')
  this.description = data.description
  this.image = data.stills ? data.stills[0].url : data.image
  this.broadcasters = data.broadcasters.join(', ')
  this.genres = data.genres.join(', ')
  this.duration = Math.round(data.duration / 60)
  if(series_data){
    this.series = new Series(series_data)
  }
}

Episode.popular = function(callback) {
  UitzendingGemist.Episode.popular(function(episodes){
    callback(
      episodes.map(function(episode){
        return new Episode(episode, episode.series)
      })
    )
  })
}
Episode.find = function(episode_id, series_id, callback) {
  UitzendingGemist.Series.find(series_id, function(series){
    episode = series.episodes.filter(function(episode){
      return episode.mid == episode_id
    })[0]

    callback(new Episode(episode, series))
  })
}

var Episode = function(data, series_data){
  this.id = data.mid
  this.name = data.name.replace('&', '&amp;')
  this.description = data.description
  this.image = data.stills ? data.stills[0].url : data.image
  this.broadcasters = data.broadcasters.join(', ')
  this.genres = data.genres.join(', ')
  this.duration = Math.round(data.duration / 60)
  if(series_data){
    this.series = new Series(series_data)
  }
}

Episode.popular = function(callback) {
  UitzendingGemist.Episode.popular(function(episodes){
    callback(
      episodes.map(function(episode){
        return new Episode(episode, episode.series)
      })
    )
  })
}

Episode.find = function(episode_id, series_id, callback) {
  UitzendingGemist.Series.find(series_id, function(series){
    episode = series.episodes.filter(function(episode){
      return episode.mid == episode_id
    })[0]

    series.episodes.splice(series.episodes.indexOf(episode), 1)

    callback(new Episode(episode, series))
  })
}

Remove the current episode from the series episodes list
Remove the current episode from the series episodes list

`Episode.find` uses `UitzendingGemist.Series.find` to first get the
`Series`, which holds a list of `Episodes`. The `Episode` returned by
`Episode.find` comes from that list.

The `Episode.series` is the `Series` from
`UitzendingGemist.Series.find`, including the episode list. Now, the
`Episode` is removed from that list before creating the `Series`, so the
`Episode` isn't listed in the shelf on the episode view.
