
var ScriptyPrompt = Class.create({
  initialize: function(message, callback, options) {
    this.callback = callback;

    this.options = Object.extend({
      effectIn: Effect.Appear,
      effectOut: Effect.Fade
    }, options || {});
   
    this.root = new Element('div', {'class': 'dialogParent', 'style': 'position:fixed;left:0;right:0;'});
    this.box = new Element('div', {'class': 'dialog', 'style': 'min-height:80px;width:350px;display:none;'});
    this.box.addClassName('dialogDefault');
    this.root.update(this.box);

    this.box.insert({top: new Element('h2').update('Prompt')});

    this.form = new Element('form');
    this.box.insert({bottom: this.form});

    this.fieldset = new Element('fieldset');
    this.form.insert({bottom: this.fieldset});

    this.label = new Element('label', {'for': 'promptField'}).update(message);
    this.fieldset.insert({bottom: this.label});

    this.fieldset.insert({bottom: new Element('br')}) 

    this.field = new Element('input', {'id': "promptField"});
    this.fieldset.insert({bottom: this.field});

    this.buttons = new Element('fieldset', {'class': 'buttons'})
    this.form.insert({bottom: this.buttons});

    this.submit = new Element('input', {'class': 'button', 'type':'submit', 'style':'display:block;', 'value':'OK'});
    this.submit.addClassName('submit');
    this.buttons.insert({bottom: this.submit});

    $(document.body).insert({bottom: this.root});
    new this.options.effectIn(this.box);

    Event.observe(this.form, 'submit', this.retAndClose.bindAsEventListener(this));
  },
  retAndClose: function(event) {
    Event.stop(event);
    this.options.effectOut(this.box, { afterFinish: this.destroy.bind(this) });
    value = this.field.value;
    this.callback(value);
  },
  destroy: function() {
    this.root.remove();
  }
});
