var stream = stream || {};

stream.Tumblr = new Class({

    initialize: function(account, callback, container) {
        this.account   = account;
        this.callback  = callback;
        this.container = container;        
    },
    
    update: function() {
    
        jQuery.ajax({
            'url': 'http://' + this.account + '/api/read/json',
            'success': this.success.bind(this), 
            'dataType': 'jsonp'
        });
    
    },
    
    success: function(data) {
    
        data.posts = data.posts.reverse();
    
        for(var i=0; i < data.posts.length; i++) {
            var post = data.posts[i];
            
            if(typeof this.posts[post.id] == 'undefined') {
                this.posts[post.id] = post;
                this.max_id = post.id;
                
                this.callback.apply(this.callback, [post, this.container]);
            }
            
        }
    
        setTimeout(this.update.bind(this), 60 * 1000);
    },
    
    posts: {}
});

function numberPad(number) {
    return (number < 10) ? '0'+number : number;
}

