<script>
    
    jQuery(function() {
    
    //-- Backbone Objects --------------------------------------------------//
        
        //-- Models --------------------------------------------------------//
        
            var Article = Backbone.Model;
        
        
        //-- Collections ---------------------------------------------------//
        
            var Articles = Backbone.Collection.extend({ 
                model: Article 
            });
            
            
        //-- Views ---------------------------------------------------------//
            
            var Posts = Backbone.View.extend({
                
                initialize: function() {
                    
                    var post = this;
                    
                    this.collection.bind('add', function(model) {
                        post.render(model);
                    })
                },
                
                render: function(model) {
                    $.get("/template/article", function(data) {
                           $("#content").append(_.template(data, model.toJSON()));
                    });
                }
                
            });
            
        
        //-- Create instances ----------------------------------------------//
        
            articles = new Articles();
            
            var posts = new Posts({
                collection: articles
            });
            
            
        //-- Router --------------------------------------------------------//
        
        var Router = Backbone.Router.extend({
            
            routes: {
                '/:id'                   : 'showArticle',
                '/awesomething/:thinger' : 'showthatawesomething'  
            },
            
            showArticle: function(id) {
                                
                var article = articles.get(id);
                
                $.get("/template/article", function(data) {
                       $("#content").fadeOut(500, function() {
                           $(this).html(_.template(data, article.toJSON())).fadeIn();
                       });
                });
            },
            
            showthatawesomething: function(thinger) {
            
            }
            
        });
        
        var router = new Router();
        Backbone.history.start();
                
      
    //-- Socket.IO ---------------------------------------------------------//
        
        var socket = io.connect('http://localhost');                      
        
        // Receive Article Data
        socket.on('articles', function(data) {
            articles.add(data);
        });

        socket.emit('alert');
        
    });
</script>