var AppRouter = Backbone.Router.extend({
    routes: {
        "/notes": "getNotes",
        "/notes/:id": "getNotes",
        "/about": 'about',
        "*actions": "defaultRoute"
    },
    getNotes: function(id){
        if(app.collections.posts.length>0) {
            var view = (id) ? new app.Views.postView(id) : new app.Views.postsView();
        } else {
            // Collection Posts is empty
            $('#content').html('').removeClass().addClass('loading');
            
            // Get blog posts
            $.getJSON(app.config.url, function(datas) {
                _.each(datas.posts, function(data){
                    var post = new Post(data);
                    app.collections.posts.add(post);
                });
                var view = (id) ? new app.Views.postView(id) : new app.Views.postsView();
            });
        }

    },
    about: function(){
        var view = new app.Views.aboutView();
    },
    defaultRoute: function(actions){
        var urs = location.protocol + '//' + location.host + '/';
        if(urs.length >= location.href.length){
            var view = new app.Views.aboutView();
        } else {
            app.router.app_router.navigate(location.href.substring(urs.length-1), true);
        }
    }
});

