document.observe("dom:loaded", function() {
  new Comments();
});


var Comments = Class.create({
	
	defaultOptions : {
  	},
  
  	initialize: function(options) 
  	{
  		this.options = Object.extend(Object.extend({ }, this.defaultOptions), options || { });
  		
  		comments = this;
  		$$('.action_add_comment_form').each(function(element) {
  			element.observe('click', comments.toggle_add_form.bindAsEventListener(comments));
  		});
  		
  		$$('.action_submit_to_moderate').each(function(element) {
  			element.observe('click', comments.submit_to_moderate.bindAsEventListener(comments));
  		});
    
  	},
  	
  	toggle_add_form: function(event)
  	{
  		event.stop();
  		add_form = event.element().up('.comments_header').next();
  		if(add_form.visible()) {
  			add_form.slideUp({ duration: 0.4 });
  		}
  		else {
  			add_form.slideDown({ duration: 0.4 });
  		}
  	},
  	
  	submit_to_moderate: function(event)
  	{
  		event.stop();
  		action = event.findElement('a');
  		
  		dialogbox = new Api_simple_confirmationbox(
  			'Zgłoszenie naruszenia zasad',
  			'Jesteś pewien, że chcesz zgłosić ten komentarz do moderacji?',
  			action.readAttribute('href'),
  			{ show_success_message: true }
  		); 
  		dialogbox.show();  		
  	}
  	
});

