app.Views.aboutView = Backbone.View.extend({
    el: $("#content"),
    initialize: function(){
        this.render();
    },
    render: function(){
        this.el.removeClass().addClass('aboutme');
        var template = _.template( $("#about").html(), {} );
        this.el.html( template );
    }
});


app.Views.postsView = Backbone.View.extend({
    el: $("#content"),
    initialize: function(){
        this.render();
    },
    render: function(){
        var _this = this;
        this.el.removeClass().addClass('blog short').html('');
        _.each(app.collections.posts.models, function(article){
            _this.addArticleView(article);
        });
    },
    addArticleView: function(article){
        var view = new app.Views.articleShortView({model: article});
        $(this.el).append(view.render());
    }
});

app.Views.postView = Backbone.View.extend({
    el: $("#content"),
    initialize: function(){
        this.render();
    },
    render: function(){
        var _this = this, slug = this.options;

        $('html,body').animate({ scrollTop: $('body').offset().top }, 300);
        this.el.removeClass().addClass('blog').html('');
        
        // From RSS
        if(!_.isNaN(parseInt(slug, 10))) {
            _.find(app.collections.posts.models, function(article){
                if(article.get('id') === _this.options) {
                    slug = article.get('slug');
                    return true;
                }
            });
            app.router.app_router.navigate('/notes/'+slug, true);
        }

        var article = _.find(app.collections.posts.models, function(article){
            return article.attributes['slug'] === slug;
        });

        this.addArticleView(article);
    },
    addArticleView: function(article){
        var view = new app.Views.articleView({model: article, single: true});
        $(this.el).append(view.render());
    }
});


app.Views.articleView = Backbone.View.extend({
    initialize: function(){
        this.render();
    },
    render: function(){
        var data = this.model.toJSON(),
            now = moment(data['date']);
        
        data.regularTitle = data['regular-title'];
        data.date = now.format('MMMM, Do YYYY'); // December, 08 2011
        data.regularBody = data['regular-body'];
        data.single = this.options.single || false;
        data.url = window.location.href;
        
        var template = _.template( $("#article").html(), data );
        return template;
    }
});

app.Views.articleShortView = Backbone.View.extend({
    initialize: function(){
        this.render();
    },
    render: function(){
        var data = this.model.toJSON(),
            now = moment(data['date']);
        
        data.regularTitle = data['regular-title'];
        data.date = now.format('MMMM, Do YYYY'); // December, 08 2011
        var content = data['regular-body'].split('<p><span class="more"></span></p>');
        data.regularBody = content[0];
        data.single = this.options.single || false;
        data.url = window.location.href;

        var template = _.template( $("#article").html(), data );
        return template;
    }
});


