var Fixture = require('./lib/Fixture'),
    ElementPool = require('./lib/ElementPool'),
    Fetcher = require('./lib/Fetcher'),
    q = require('q'),
    fs = require('fs'),
    feedsPath = '../iblfetcher/feeds/'

q.longStackSupport = true;

function FixtureCreator(config) {
    that = this;
    that.config = config;
    that.feeds = {};
    that.elementPool = new ElementPool();
    that.fetcher = new Fetcher({
        apiKey: config.apiKey,
        iblUrl: config.iblUrl,
        proxy: config.proxy,
        cacheDir: config.cacheDir,
        cacheExpireTime: config.cacheExpireTime || (new Date().getTime() - (60 * 60 * 1000))
    });

    that.prefetch = that.fetcher.prefetch().then(function (feeds) {
        that.feeds = feeds;
        for (name in feeds) {
            var feed = feeds[name];
            that.elementPool.processFeed(feed);
        }

        if (config.debug) {
            console.log('Processed feeds, found the following elements for use')
            console.log('Episodes:', that.elementPool.pools.Episode.length)
            console.log('Group:',that.elementPool.pools.Group.length)
            console.log('Programmes:',that.elementPool.pools.Programme.length)
        }

    }).fail(function (err) {
        console.log('Error prefetching feeds', err);
        throw err
    });
}

FixtureCreator.prototype.createFixture = function(feedName, params) {
    var defer = q.defer(),
        newFeedDefer = q.defer();
        that = this,
        path = feedName;

    feed = that.feeds[feedName];
    if (feed === undefined) {
        that.fetcher.fetch(feedName, params).done(function (json) {
            that.feeds[feedName] = json;
            newFeedDefer.resolve(json);
        });
    } else {
        newFeedDefer.resolve(feed)
    }

    newFeedDefer.promise.then(function (feed) {
        fixture = new Fixture(feedName, feed, that.elementPool, that.config);

        defer.resolve(fixture);
    }).fail(function (e) {
        defer.reject(e)
    }).done();

    return defer.promise
};

module.exports = FixtureCreator

@@ -205,16 +205,17 @@
 /feeds/'
+;
 %0A%0Aq.long
@@ -1443,17 +1443,17 @@
 .defer()
-;
+,
 %0A       
@@ -1489,16 +1489,35 @@
 feedName
+,%0A        cloneFeed
 ;%0A%0A    f
@@ -1748,16 +1748,70 @@
  else %7B%0A
+        cloneFeed = JSON.parse(JSON.stringify(feed));%0A
         
@@ -1831,17 +1831,22 @@
 resolve(
-f
+cloneF
 eed)%0A   

Stop fixtures overwriting each other if they use the same feed. Adds a 'clone' (JSON dance) before returning a feed from the cache