/**
 *    Copyright 2006 - 2011 Opera Software ASA
 *
 *    Licensed under the Apache License, Version 2.0 (the "License");
 *    you may not use this file except in compliance with the License.
 *    You may obtain a copy of the License at
 *
 *        http://www.apache.org/licenses/LICENSE-2.0
 *
 *    Unless required by applicable law or agreed to in writing, software
 *    distributed under the License is distributed on an "AS IS" BASIS,
 *    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *    See the License for the specific language governing permissions and
 *    limitations under the License.
 *
 **/


/**
 * @constructor
 */
var ButtonBase = function()
{
  this.type = "button";

  this.init = function(id, class_name, title, handler, attributes)
  {
    this.id = id;
    this.class_name = class_name || '';
    this.title = title || '';
    this.handler = handler || '';
    this.attributes = attributes || {};
  };
};

var Button = function(id, class_name, title, handler, attributes)
{
  /** interface **/

  /**
   * Set the active state of the button.
   *
   * @param {Boolean} active Whether or not the button is active.
   */
  this.set_active = function(active) {};

  /**
   * Get the button template.
   */
  this.get_template = function() {};


  /** implementation **/

  this.set_active = function(active)
  {
    this._element.setAttribute("is-active", !!active);
  };

  this.get_template = function()
  {
    return window.templates[this.type](this.id, this.class_name, this.title, this.handler, this.attributes);
  };

  this.init(id, class_name, title, handler, attributes);
};

Button.prototype = new ButtonBase();

window.templates["button"] = function(id, class_name, title, handler, attributes)
{
  var attrs = [];
  for (var attr in attributes)
  {
    attrs.push(attr, attributes[attr]);
  }

  return [
    "button",
    "",
    "id", id,
    "class", "ui-control " + class_name,
    "title", title,
    "handler", handler || id
  ].concat(attrs);
};

