var TkFragmentBreadcrumbs = Class.create();
TkFragmentBreadcrumbs.prototype = {
  initialize: function(assetPath, options) {
    this.node = g_navNode_Root;
    this.path = g_navNode_Path;
    this.options = {
      className: 'tkFragmentBreadcrumbs',
      imageOff: (assetPath + 'image/arrowRight.gif'),
      imageOn: (assetPath + 'image/arrowRightOn.gif'),
      imageAlt: '-----',
      overview: false
    }
    Object.extend(this.options, options || {});
    this.last = false;
  },

  write: function() {
    if (this.path.length > 1) {
      document.write('<div class="' + this.options.className + '"><span>');
      this.writeNode(this.node);
      if (!this.last) {
        this.writeTitle();
      }
      document.write('</span></div>');
    }
  },

  writeNode: function(node) {
    var level = node.m_level;
    if (level < this.path.length && this.path[level] == node.m_id) {
      var html = '<a';
      if ((level == 1 && !this.options.overview) && 0 < node.m_subNodes.length) {
          html += ' class="static';
        if (!(level < this.path.length - 1)) {
          html += ' last';
        }
        html += '"';
        this.last = true;
      } else {
        html += ' href="' + node.m_href + '"';
        if (level == this.path.length - 1) {
          html += ' class="last"';
          this.last = true;
        }
      }
      html += '>' + node.m_label + '</a>';
      if (level < this.path.length - 1) {
        var src = (level == this.path.length - 2) ? this.options.imageOn : this.options.imageOff;
        html += '<image src="' + src + '" alt="' + this.options.imageAlt + '" />';
      }
      document.write(html);
      for (var i = 0; i < node.m_subNodes.length; i++) {
        this.writeNode(node.m_subNodes[i]);
      }
    }
  },

  writeTitle: function(node) {
    var html = '<a href="' + document.location + '" class="last">' + document.title + '</a>';
    document.write(html);
  }
}
