Blahger.Post = ActiveElement.Base.spawn('post', {

  afterInitialize: function(){
    this.commentForm = this.findCommentForm();
    this.comments = this.findComments();
  },

  getTitleElement: function(){
    return this.element.down('.title a');
  },

  getLinkElement: function(){
    return this.element.down('.title a');
  },

  getLinkValue: function(){
    return this.getLinkElement().readAttribute('href');
  },

  setLinkValue: function(href){
    this.getLinkElement().writeAttribute('href', href);
  },

  findComments: function(){
    var comments = this.element.down('.comments');
    return comments && new Blahger.Comments(comments);
  },

  findCommentForm: function(){
    var form = this.element.down('#new_comment') || this.element.down('#edit_comment');
    return form && new Blahger.CommentForm(form);
  }

});

Blahger.Posts = ActiveElement.Collection.spawn('post', {

  extend: {
    findInDocument: function(){
      return new this($$('.posts').first());
    },
    attach: function(posts){
      Blahger.posts = posts;
    }
  },
  
  afterInitialize: function(){
    this.addClassNames();
  },

  addClassNames: function(){
    var classNames = $w('koda basanda bosoya tikki ottobo boshatta umahasha heeta');
    this.each(function(post, index){
      post.element.addClassName(classNames[index % classNames.length]);
    });
  }

});
