/*	DARCY COMMON CONTROLS

	By: Major Rasputin/Ayman Habayeb/Crome Tysnomi since 2011
    Depends on: SimPlaza Common JS Library c.js
    Licensed under SIMPL (http://simplaza.net/hax/SIMPL) 2011
*/

var _controls = [];

var DIALOG_INFO = 0;
var DIALOG_WARNING = 1;
var DIALOG_ERROR = 2;

function control_dialog(title, content, type, buttons) {
    this.id = _controls.length;
    this.title = title;
    this.content = content;
    this.type = type;

    this._window = document.createElement('div');
    this._window.className = 'absolute fill hidden control_dialog';
    this._window.id = 'control' + this.id;
        this._window.innerHTML = '\
            <div class="dialog absolute">\
                <header>'+this.title+'</header>\
                \
                '+this.content+' \
            </div>';

    this._buttons = document.createElement('div');
    this._buttons.className = 'buttons';
    this._window.firstElementChild.appendChild(this._buttons);

    buttons.walk(
        function(button, key, args) {
            args[1]._buttons[key] = document.createElement('a');
            args[1]._buttons[key].innerHTML = button[0] + '<sup>'+button[1]+'</sup>';
            args[1]._buttons[key]._control = args[1];
            args[1]._buttons.appendChild(args[1]._buttons[key]);
        }
    , this);

    this.show = function() {
        delClass(this._window, 'hidden');
    }

    this.hide = function() {
        addClass(this._window, 'hidden');
    }

    document.body.appendChild(this._window);
    _controls[this.id] = this;
}
