
var Post_controller = Class.create();
	
Post_controller.prototype = {
	
  len: { 'comment': 1024 },	
	
  // Initialize vote.
  //
  initialize: function() {
  },
	
  hideAllDetails: function() {
    ['more', 'related', 'share', 'clicked', 'comment', 'comments'].each(function(e) {
      Element.hideIf(e);
    });
  },
	
  showDetail: function(id, li) {
    // show block
    this.hideAllDetails();
    Element.showIf(id);
	
    // tabs
    ['more', 'related', 'share', 'clicked', 'comment'].each(function(e) {
      $(e+'-tab').removeClassName('current');
    });
    li.addClassName('current');
  },
	
  // Refresh counter
  //
  refresh_cnt: function(name, len) {
    $('cnt_'+name).innerHTML = eval('this.len.'+name) - len;
  }	

};
	
var Post = new Post_controller();

var details_rules = ['more', 'related', 'share', 'clicked', 'comment'].fold({}, function(result, value) {
  result['#'+value+'-tab'] = function() {
    $(value+'-tab').onclick = function() {
      Post.showDetail(value, $(value+'-tab'));
      if (value == 'comment') Element.showIf('comments');
      return false;
    };
    $(value+'-tab').onmousedown = prevent_focus;
  };
  return result;
});
	
Behaviour.register(details_rules);
	
var comment_rules = {

  '#content #left #comment textarea': function(e) {
    e.onkeyup = function() {
      Post.refresh_cnt(e.getAttribute('cnt'), e.value.length);
    };
  },
	
	'#from_msg': function(e) {
		e.onclick = function() {
		  e.hide();
		  return false;
		};
	}
	
}
	
Behaviour.register(comment_rules);	
