var errors = {
  /**
   * Builds a list of error messages to display to the user
   * 
   * @param {Array} messages A list of messages to render
   * @return {DOMElement} The generate element
   */
  build: function(messages) {
    var errors = $('<ul />').addClass('errors');
    for (var i = 0; i < messages.length; i++) {
      errors.append($('<li />').text(messages[i]));
    }
    
    return errors;
  }
};

var app = {
  /**
   * Initializes the javascript application, including the Viximo platform
   * 
   * @param {String} user The id of the user on the platform
   * @param {String} session The session key for the user
   * @param {String} callback The callback to invoke when the Viximo platfomr has been initialized
   * @param {String} api_version The version of the viximo API to use
   */
  init: function(user, session, callback, api_version) {
    this.user = user;
    this.session = session;
    var options = {
      publisher: 'giftd',
      version: api_version,
      features: ['giftings', 'storefront', 'purchases'],
      complete: function() {
        viximo.translations.add({
          gifting: {
            received: 'sent'
          },
          autocomplete: {
            intro: 'To (provide an e-mail address)'
          }
        });
        callback();
      }
    };
    if (user) options.user = user;
    if (session) options.session = session;
    
    viximo.init(options);
  },
  
  noticeDialog: function(message) {
    console.log('dialog rendering');
    
    //OK Messagebox
    var $messageUI = $('<div>');
    $messageUI.append(
      $('<span>')
      .text(message), 
      $('<br>'), 
      $('<br>') 
    );
    
    var target = $('<div id="notice-new">');
    $('body').append(target);
    
    //display a dialog with the delete UI
    this.currentDialog = $(target).dialog({
      overlay: function() {
          return {opacity: 0.5, background: 'black'};
        },
      draggable: false,
      title: 'Heads up!',
      modal: true,
      height: 100,
      width: 300,
      resizable: false,
      buttons: {
        OK: function(){
          $('#notice-new').dialog('close');
        }
      }
    }).append($messageUI).show().dialog('open');
    console.log('dialog rendered');
  }
}
