/*  VCO.TimelineConfig
    separate the configuration from the display (VCO.Timeline)
    to make testing easier
================================================== */
VCO.TimelineConfig = VCO.Class.extend({
    VALID_PROPERTIES: ['scale', 'slides'], // we'll only pull things in from this

    initialize: function (data, callback) {
    // Initialize the data
        if (typeof data === 'string') {
            var self = this;
            
            VCO.ajax({
                type: 'GET',
                url: data,
                dataType: 'json', //json data type
                success: function(d){
                    if (d && d.timeline) {
                        self._importProperties(d.timeline);
                    } else {
                        throw("data must have a timeline property")
                    }
                    self._cleanData();
                    if (callback) {
                        callback(self);
                    }
                },
                error:function(xhr, type){
                    trace(xhr);
                    trace(type);
                    throw("Configuration could not be loaded: " + type);
                }
            });
        } else if (typeof data === 'object') {
            if (data.timeline) {
                this._importProperties(data.timeline);
                this._cleanData();
            } else {
                throw("data must have a timeline property")
            }
            if (callback) {
                callback(this);
            }
        } else {
            throw("Invalid Argument");
        }
    },

    _cleanData: function() {
        this._makeUniqueIdentifiers(this.slides); 
        this._processDates(this.slides);          
        VCO.DateUtil.sortByDate(this.slides);
    },

    _importProperties: function(d) {
        for (var i = 0; i < this.VALID_PROPERTIES.length; i++) {
            k = this.VALID_PROPERTIES[i];
            this[k] = d[k];
        }
    },

    _makeUniqueIdentifiers: function(array) {
        var used = []
        for (var i = 0; i < array.length; i++) {
            if (array[i].uniqueid && array[i].uniqueid.replace(/\s+/,'').length > 0) {
                array[i].uniqueid = VCO.Util.slugify(array[i].uniqueid); // enforce valid
                if (used.indexOf(array[i].uniqueid) != -1) {
                    array[i].uniqueid = '';
                } else {
                    used.push(array[i].uniqueid);
                }
            }
        };
        if (used.length != array.length) {
            for (var i = 0; i < array.length; i++) {
                if (!array[i].uniqueid) {
                    var slug = (array[i].text) ? VCO.Util.slugify(array[i].text.headline) : null;
                    if (!slug) {
                        slug = VCO.Util.unique_ID(6);
                    }
                    if (used.indexOf(slug) != -1) {
                        slug = slug + '-' + i;
                    }
                    used.push(slug);
                    array[i].uniqueid = slug;
                }
            }
        }
    },

    _processDates: function(array) {
        var dateCls = null;
        
        if(this.scale == 'javascript') {
            dateCls = VCO.Date;
            trace('using VCO.Date');
        } else if(this.scale == 'cosmological') {
            dateCls = VCO.BigDate;
            trace('using VCO.BigDate');
        } else {
            throw ("Don't know how to process dates on scale "+this.scale);
        }
            
        for (var i = 0; i < array.length; i++) {
            if (typeof(array[i].start_date) == 'undefined') {
                throw("item " + i + " is missing a start_date");
            }
            
            array[i].start_date = new dateCls(array[i].start_date);
            if (typeof(array[i].end_date) != 'undefined') {
                array[i].end_date = new dateCls(array[i].end_date);
            }
        }
    }
});

@@ -3096,24 +3096,28 @@
    %7D%0A    %7D,%0A
+    
 %0A    _proces
@@ -3171,32 +3171,717 @@
  null;%0A        %0A
+        if(!this.scale) %7B%0A            trace(%22Determining scale dynamically%22);%0A            %0A            this.scale = %22javascript%22; // default%0A            %0A            for (var i = 0; i %3C array.length; i++) %7B%0A                if (typeof(array%5Bi%5D.start_date) == 'undefined') %7B%0A                    throw(%22item %22 + i + %22 is missing a start_date%22);%0A                %7D%0A                %0A                var d = new VCO.BigDate(array%5Bi%5D.start_date);%0A                var year = d.data.date_obj.year;               %0A                if(year %3C -271820 %7C%7C year %3E  275759) %7B%0A                    this.scale = %22cosmological%22;%0A                    break;%0A                %7D%0A            %7D%0A        %7D%0A        %0A
         if(this.

Determine scale dynamically if not set in JSON.