(function(Application){
	
	// Dependencies
	var Post = App.module('post'),
		Page = App.module('page');

	// Shorthand

	// Model

	// Collection

	// Views
	Application.Views.Main = Backbone.View.extend({
		templates: {},
		initialize: function() {
			this.templates.footer = _.template($('#footer').html());
			this.render();
		},
		render: function() {
			var container = '#main';
			var $container = $(container);
			var el = this.el;
			var $el = $(el);
			var $footer = $(this.templates.footer());

			$container.empty().hide();
			$container.append($el);
			$container.append($footer);
			$container.fadeIn();
		}
	});

	Application.Views.Home = Backbone.View.extend({
		initialize: function() {
			_.bindAll(this, 'render');
			this.collection.bind('change', this.render);

			this.collection.get();
			this.render();
		},
		render: function() {
			content = new Post.Views.Archive({ collection: this.collection }).render().el;
			new Application.Views.Main({
				el: content
			});
		}
	});

	Application.Views.Page = Backbone.View.extend({
		initialize: function(params) {
			_.bindAll(this, 'render');
			this.model.bind('change', this.render );
			if(this.model.id !== params.id) {
				this.render();
			}
		},
		render: function() {
			content = new Page.Views.Single({ model: this.model }).render().el;
			new Application.Views.Main({ el: content });
		}
	});

	// Router
	Application.Router = Backbone.Router.extend({
		post_data: undefined,
		projects_data: undefined,
		contact_data: undefined,

		routes: {
			'': 'index',
			'projects': 'projects',
			'contact': 'contact'
		},

		initialize: function() {
			if(this.post_data === undefined) {
				this.post_data = new Post.Collection();
			}
			if(this.projects_data === undefined) {
				this.projects_data = new Page.Model();
			}
			if(this.contact_data === undefined) {
				this.contact_data = new Page.Model();
			}
		},

		index: function() {
			console.log(this.post_data);
			new Application.Views.Home({ collection: this.post_data });
		},

		projects: function() {
			this.projects_data.get('projects');
			new Application.Views.Page({ model: this.projects_data, id: 'projects' });
		},

		contact: function() {
			this.contact_data.get('contact');
			new Application.Views.Page({ model: this.contact_data, id: 'contact' });
		}
	});


})(App.module('application'));
