(function($, b, $i) {

	$i.Post = $i.Api.Model.extend({});
	
	$i.Posts = $i.Api.Collection.extend({
		model : $i.Post,
		initialize : function(options) {
			this.currentIndex = 0; //the lastest one
		},
		goTo: function(slug) {
			var postToDisplay = null;
			var t = this;
			this.each(function(post,index) {
				if(post.get("slug") == slug) {
					t.currentIndex =  index; 
					postToDisplay = post;
					return;
				} 
			});
			return postToDisplay;
		},		
		next : function(current) {
			//the less the newer
			if (this.currentIndex == 0) return null;
			return this.at(--this.currentIndex);
		},
		previous: function() {
			//the more the older
			if (this.currentIndex +1 >= this.length) return null;
			return this.at(++this.currentIndex);
		},
		nextPost : function(current) {
			//the less the newer
			if (this.currentIndex == 0) return null;
			return this.at(this.currentIndex - 1);
		},
		previousPost: function() {
			//the more the older
			if (this.currentIndex + 1 >= this.length) return null;
			return this.at(this.currentIndex + 1);
		}
	});
})(jQuery, Backbone, Insurge);
