EnergyLabel = function(container) {
  this.container = container;
  this.uid = EnergyLabel.nextId++;
};

// Global constant to prevent namespace collision between 2 chart
EnergyLabel.nextId = 0;

EnergyLabel.IMGPATH = 'http://www.heluz.cz/img/';

EnergyLabel.prototype.escapeHtml = function(text) {
  if (text == null) {
    return '';
  }
  return text.replace(/&/g, '&amp;').
      replace(/</g, '&lt;').
      replace(/>/g, '&gt;').
      replace(/"/g, '&quot;');
};

EnergyLabel.prototype.draw = function(options) {
  var html = [];
  var width = options['width'];
  html.push('<table border="0" cellpadding="3" cellspacing="0" class="energylabel-grid1" width="', width, '">');
  var header = options['title'];
  if (header) {
    html.push('<caption class="energylabel-title">', this.escapeHtml(header), '</caption>');
  }

  var rows = 7;
  var current = options['current'];
  var sublevel = options['sublevel'];
  var arrowHeight = 33;
  for (var i = 0; i < rows; i++) {
    width = 125 + i * 15;
    html.push('<tr height="', arrowHeight, '"><td align="left"><img src="', EnergyLabel.IMGPATH, i + '_arrow.gif', '" width="', width, '" height="', arrowHeight, '" /></td><td align="left" width="67">');
    if (i == current) {
      html.push('<img src="', EnergyLabel.IMGPATH, i + sublevel + '_selected.gif', '" width="67" height="', arrowHeight, '" />');
    } else {
      html.push('&nbsp;');
    }
    html.push('</td></tr>');
  }
  html.push('</table>');
  this.container.innerHTML = html.join('');
};
