var wu_shoutbox = new Class({
 messagesaved: function(text) {
  switch (text) {
   case 'spam': wumessage.show(this.m_spam); break;
   case 'short': wumessage.show(this.m_short); break;
  };
  this.refresh();
 },
 sendmessage: function(e) {
  this.showloading();
  new Ajax('sites/tagmasterz/shoutbox/shoutbox.php?action=message', {method: 'post', data: this.form.toQueryString(), onComplete: this.messagesaved.bind(this)}).request();
  return wu.stop(e);
 },
 createli: function(name, date, message) {
  return new Element('li')
   .adopt(new Element('span').appendText(message + ' '))
   .adopt(new Element('strong').appendText(name + ' ').adopt(new Element('em').appendText(date)))
  ;
 },
 showlist: function(text) {
  this.list.innerHTML = '';
  var resp = Json.evaluate(text);
  try {
   var len = resp.rows.length;
  } catch(e) {
   this.showstable();
   return;
  }
  for (var n = 0; n < len; n++) {
   var row = resp.rows[n];
   var li = this.createli(row.name, row.date, row.message);
   if ((this.list.getElementsByTagName('li').length % 2) == 0) li.addClass('even');
   this.list.adopt(li);
  }
  this.showstable();
 },
 refresh: function() {
  this.showloading();
  new Ajax('sites/tagmasterz/shoutbox/shoutbox.php?action=list', {method: 'get', onComplete: this.showlist.bind(this)}).request();
 },
 showloading: function() {
  this.indicator.setStyle('display', 'block');
  this.list.setStyle('display', 'none');
  this.form.setStyle('display', 'none');
 },
 showstable: function() {
  this.indicator.setStyle('display', 'none');
  this.list.setStyle('display', 'block');
  this.form.setStyle('display', 'block');
 },
 initialize: function(id, adopter, name, message, submit, m_spam, m_short, csrf) {
  this.div = new Element('div').setProperty('id', id);
  this.list = new Element('ul');
  this.m_spam = m_spam;
  this.m_short = m_short;
  this.indicator = new Element('p').adopt(new Element('img').setProperty('src', 'sites/tagmasterz/shoutbox/loading.gif'));
  var html = '\
<div class="wu_field"><span class="wu_label"><label>' + name + ' <' + '/label><' + '/span><span class="wu_input"><input type="text" name="name" maxlength="254" value="" /><' + '/span><' + '/div>\
<div class="wu_field"><span class="wu_label"><label>' + message + ' <' + '/label><' + '/span><span class="wu_input"><input type="text" name="message" maxlength="254" value="" /><' + '/span><' + '/div>\
<div class="wu_field"><input type="hidden" name="wu_csrf" value="' + csrf + '" /><input type="hidden" name="action" value="message" /><input type="submit" class="wu_submit" value="' + submit + '" /><' + '/div>\
';
  this.form = new Element('form').setProperties({'action': 'sites/tagmasterz/shoutbox/shoutbox.php', 'method': 'post'}).setHTML(html).addEvent('submit', this.sendmessage.bind(this));
  this.div.adopt(this.list).adopt(this.form).adopt(this.indicator);
  this.showloading();
  adopter.adopt(this.div);
  this.refresh();
 }
})