(function($){

var ns = "Post";

window[ns] = function ( options ) {
  this.options = options;
  
  this.root = $('#wall-list');
  this.form = $(options.form);
  this.url = AJAX_BASE + 'post/?ajax';
  
  this.init();
  this.observe();
}

window[ns].prototype = {
  
  init: function () {
    if ( this.form.hasClass('post-wall') ) {
      
      this.radio = this.form.find('.wallstyle-field input[type=radio]');
      this.radio.click( $.proxy( this.wallradioclick, this ) );

      this.fileupload = this.form.find('.fileupload-field');
      this.videoinput = this.form.find('.videoinput-field');
      this.fileupload.hide();
      this.videoinput.hide();
    }
    
  },
  
  wallradioclick: function ( event ) {
    var element = event.currentTarget;
    var value = element.value;
    
    if ( value == 0 ) {
      this.fileupload.hide();
      this.videoinput.hide();
      this.form.find('textarea').focus();
      
    } else if ( value == 1 ) {
      this.fileupload.show();
      this.videoinput.hide();
      
    } else if ( value == 2 ) {
      this.fileupload.hide();
      this.videoinput.show();
      this.videoinput.find('input.text').focus();
    }    
  },
  
  observe: function () {
    this.form.submit( $.proxy( this.submit, this ) );
  },
  
  submit: function ( event ) {
    if ( this.submiting ) {
      event.preventDefault();
      return false;
    }
    var form = $(event.currentTarget);
    
    if ( form.hasClass('post-note') ) {
      var title = form.find('input#title');
      // if title empty
      if ( "" == $.trim(title.val()) ) {
        title.focus();
        event.preventDefault();
        return false;
      }
    } else {
      var content = form.find('textarea');
    
      // if content empty
      if ( "" == $.trim(content.val()) ) {
        content.focus();
        event.preventDefault();
        return false;
      }
    }
    
    this.submiting = true;
    form.addClass('loading');
    
    form.find('.submit').blur().attr('disabled', 'disabled');

/*
    event.preventDefault();
    if ( form.hasClass('comment') ) return false;
    if ( form.hasClass('loading') ) return false;
    
    // start
    form.addClass('loading');
    
    form.find('.submit').blur();
    var $this = this;
    
    $.post( this.url, form.serialize(), function ( data ) {
      var block = $(data).prependTo($this.root).hide().fadeIn();
      
      Activate( block );
      
      form.removeClass('loading');
      form.get(0).reset();
    } );
*/
    
  }
  
};

})(jQuery);
